Skip to content

Test Token Activity coverage through the spend dashboard - #2797

Merged
steipete merged 5 commits into
steipete:mainfrom
Yuxin-Qiao:codex/test-token-activity-dashboard
Aug 10, 2026
Merged

Test Token Activity coverage through the spend dashboard#2797
steipete merged 5 commits into
steipete:mainfrom
Yuxin-Qiao:codex/test-token-activity-dashboard

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a focused backend-only regression test for the shared Codex token activity path
  • exercise CostUsageStore -> cached Codex token activity -> SpendDashboardSource -> ProviderInput -> SpendDashboardModel
  • preserve partial coverage, daily buckets, and empty/unknown/unavailable distinctions

The synthetic shared store covers 2026-04-06 through 2026-04-08 with token totals 18, 0, and 24. The dashboard model must keep only those three established days in its 365-day activity series, leave the day before coverage unavailable, and retain the established zero gap. A second case verifies that an established empty range produces zeros while an unavailable range remains entirely unavailable, and its unavailable-case assertions are non-vacuous: they require a present source input, no failed sources, and the full 365-point activity series before asserting every point is unavailable.

The test now drives the production default activity-loader path: it calls SpendDashboardSource.load(_:cacheRootResolver:codexSnapshotLoader:), which uses the production loadCodexActivity implementation, so SpendDashboardSource itself passes context.cacheRoot and context.account.homePath to CostUsageFetcher(cacheRoot:) -> loadCachedCodexTokenActivity(now:codexHomePath:maximumDays:). The test injects only the narrowest testability seam (a cache-root resolver for filesystem isolation); it no longer injects a full codexActivityLoader or reimplements the production fetcher call.

Production changes are limited to dependency-injection plumbing: the existing load overloads now forward through a private implementation that accepts a CodexCacheRootResolver, and the public entry points keep the same default resolver (codexCacheRoot(for:)), so runtime default behavior is unchanged (+32/-2 in SpendDashboardController.swift).

Duplicate check

  • rebased from latest steipete/CodexBar main at c94fe8d8 (no conflicts; the 7 new upstream commits do not touch this PR's files)
  • inspected open PR Track multi-provider spend and model usage #2759 and the latest main tests; no equivalent shared-store-to-dashboard Token Activity integration coverage was present (store-layer CostUsageFetcherCacheSnapshotTests exists, but nothing exercises the full CostUsageStore -> cached Codex activity -> SpendDashboardSource -> ProviderInput -> SpendDashboardModel path)

Validation

  • swift test --filter SpendDashboardTokenActivityIntegrationTests — 2 tests passed (real output below)
  • swift test --filter SpendDashboard — 128 tests in 12 suites passed, covering the refactored load overload family (SpendDashboardControllerTests, SpendDashboardSourceConcurrencyTests, SpendDashboardForceStateMachineTests, ...)
  • swift test --filter ProviderArchitectureGatekeeperTests — 38 tests passed, including the line-anchored SpendDashboardController provider-construct entries re-anchored after the loader seam
  • SwiftFormat lint on changed files — 0 files require formatting; SwiftLint --strict on changed files — 0 violations
  • git diff --check — clean
  • make check — repo-wide JS/lint tool steps (oxfmt/oxlint/typescript) could not be downloaded inside the local sandbox because its network is unavailable; all portable steps that ran passed (locales, parser hash, provider manifests), and the same checks are green in CI (lint job)
  • make test (Scripts/ci_swift_test_by_suite.py, 835 selections / 70 groups) — all groups pass except the Alibaba token-plan cookie-cache tests, which fail only inside the local Codex sandbox with EPERM ("Operation not permitted") when locking the real user cookie-cache path; reproduced standalone on the pre-change base commit, so it is environmental and unrelated to this change

Real behavior proof

On PR head 52b9b68a (rebased onto latest main c94fe8d8), the focused integration tests actually execute and pass through the production default Codex activity loader:

$ swift test --filter SpendDashboardTokenActivityIntegrationTests
[0/1] Planning build
Building for debugging...
[0/16] Write swift-version--58304C5D6DBC2206.txt
Build complete! (2.34s)
Test Suite 'Selected tests' started at 2026-08-10 12:34:06.368.
Test Suite 'CodexBarPackageTests.xctest' started at 2026-08-10 12:34:06.369.
Test Suite 'CodexBarPackageTests.xctest' passed at 2026-08-10 12:34:06.369.
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
Test Suite 'Selected tests' passed at 2026-08-10 12:34:06.369.
	 Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
◇ Test run started.
↳ Testing Library Version: 1902
↳ Target Platform: arm64e-apple-macos14.0
◇ Suite SpendDashboardTokenActivityIntegrationTests started.
◇ Test "shared Codex activity keeps partial store coverage through source and model" started.
✔ Test "shared Codex activity keeps partial store coverage through source and model" passed after 0.042 seconds.
◇ Test "empty established and unavailable shared activity retain distinct dashboard semantics" started.
✔ Test "empty established and unavailable shared activity retain distinct dashboard semantics" passed after 0.009 seconds.
✔ Suite SpendDashboardTokenActivityIntegrationTests passed after 0.052 seconds.
✔ Test run with 2 tests in 1 suite passed after 0.052 seconds.

PR diff vs main: 3 files changed, 267 insertions(+), 11 deletions(-) — new test file (226 insertions), the minimal DI seam in SpendDashboardController.swift (+32/-2, runtime default behavior unchanged), and the re-anchored provider-architecture gatekeeper entries (9 lines updated) that keep the line-anchored suite valid after the seam moved the anchors.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 1:36 PM ET / 17:36 UTC.

ClawSweeper review

What this changes

Adds cached Codex token-activity regression coverage through the spend dashboard and a narrow cache-root resolver seam so the test uses the production activity loader.

Merge readiness

Ready for maintainer review

Keep open for normal maintainer review. The refreshed branch contains a focused testability seam and regression coverage, prior actionable findings are addressed, and no new correctness defect was found.

Priority: P3
Reviewed head: bab3a2910a5b8531a4de567926b98e2fe3d99e64

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused real test output and a narrow implementation make this a normally mergeable coverage PR.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes a real terminal transcript showing both new integration tests pass through the production default activity-loader path; the later head is a maintainer merge refresh.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes a real terminal transcript showing both new integration tests pass through the production default activity-loader path; the later head is a maintainer merge refresh.
Evidence reviewed 5 items Production loader path: The production source builds the snapshot and activity load contexts from one resolved cache root; the PR routes the new test overload through the existing activity loader rather than injecting a replacement activity loader.
Cache semantics: The existing fetcher returns nil for unavailable cache coverage and derives daily activity only after validating the scoped cache roots and coverage range, matching the distinctions asserted by the new tests.
Focused regression coverage: The new serialized suite covers partial cached coverage, an established empty range, and an unavailable range through the source and dashboard model.
Findings None None.
Security None None.

How this fits together

CodexBar reads cached provider usage data and converts it into dashboard inputs and a dashboard model for the app’s spend UI. The changed path loads Codex token activity from the local cache, preserves coverage information, and supplies it to the model.

flowchart LR
A[Codex activity cache] --> B[Usage fetcher]
B --> C[Spend dashboard source]
C --> D[Provider input]
D --> E[Dashboard model]
E --> F[Spend UI]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Focused surface 3 files affected The patch is limited to one loader seam, its architecture-test anchors, and one regression suite.
Production versus test delta production +32/-2; tests +235/-9 Most of the change is focused coverage; the production delta is limited to forwarding the existing default resolver.

Technical review

Best possible solution:

Merge the focused regression coverage after ordinary review of the exact refreshed head and its running checks.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR adds coverage rather than reporting a separate user bug. The body includes a terminal transcript of the two new integration tests passing through the default activity-loader path.

Is this the best way to solve the issue?

Yes. Injecting only the cache-root resolver retains the production activity loader while isolating test storage, which is narrower than replacing the loader in the test.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4f0ac0680cd2.

Labels

Label justifications:

  • P3: This is targeted regression coverage and a narrow internal testability seam without a demonstrated user-facing incident.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes a real terminal transcript showing both new integration tests pass through the production default activity-loader path; the later head is a maintainer merge refresh.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a real terminal transcript showing both new integration tests pass through the production default activity-loader path; the later head is a maintainer merge refresh.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the central loader and cached activity wiring to the v0.49.1 release commit. (role: introduced current dashboard-loader behavior; confidence: high; commits: ae1111e39912; files: Sources/CodexBar/SpendDashboardController.swift)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-09T14:16:05.323Z sha 17c1235 :: needs real behavior proof before merge. :: [P2] Exercise the default activity loader | [P2] Require the unavailable-case provider input
  • reviewed 2026-08-09T14:32:50.167Z sha d82ccbd :: needs real behavior proof before merge. :: [P2] Exercise the production activity-loader wiring
  • reviewed 2026-08-09T15:57:30.105Z sha d82ccbd :: needs real behavior proof before merge. :: [P2] Exercise the default activity loader
  • reviewed 2026-08-09T18:15:49.150Z sha d82ccbd :: needs real behavior proof before merge. :: [P2] Exercise the default activity loader
  • reviewed 2026-08-09T20:11:49.959Z sha d82ccbd :: needs real behavior proof before merge. :: [P2] Exercise the default activity loader
  • reviewed 2026-08-10T03:58:01.330Z sha 3a159a7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T04:39:20.342Z sha 52b9b68 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T05:02:05.412Z sha 52b9b68 :: needs maintainer review before merge. :: none

@Yuxin-Qiao
Yuxin-Qiao marked this pull request as ready for review August 9, 2026 03:26
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 9, 2026
@Yuxin-Qiao
Yuxin-Qiao force-pushed the codex/test-token-activity-dashboard branch from 2007d2e to 17c1235 Compare August 9, 2026 10:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17c1235260

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +142 to +146
return await CostUsageFetcher.loadCachedCodexTokenActivity(
now: context.now,
codexHomePath: context.account.homePath,
maximumDays: context.historyDays,
scannerOptions: scannerOptions)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise the production activity-loader wiring

If SpendDashboardSource.loadCodexActivity regresses—for example by resolving the wrong cache root or no longer forwarding the account home—these tests still pass because the injected closure bypasses that production method and reads the captured test store directly through scannerOptions. Seed the cache where the source resolves it and invoke the default loader, or expose a cache-root seam, so this actually protects the advertised store-to-source path.

Useful? React with 👍 / 👎.

Comment on lines +113 to +114
#expect(unavailableResult.inputs.first?.tokenActivityCache == nil)
#expect(unavailableModel.tokenActivity.allSatisfy { $0.totalTokens == nil })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require an input before asserting unavailable activity

When the source unexpectedly drops or fails the Codex input, both assertions pass vacuously: inputs.first?.tokenActivityCache is nil, and a model built from no inputs has an empty activity array for which allSatisfy is true. Require the input, verify the source did not fail, and assert the expected 365-point series before checking that every point is unavailable.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 9, 2026
@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the PR body now includes a ## Real behavior proof section with the real focused-test terminal output at head d82ccbd5, and all checks are green.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@Yuxin-Qiao
Yuxin-Qiao force-pushed the codex/test-token-activity-dashboard branch from d82ccbd to 3a159a7 Compare August 10, 2026 03:52
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 10, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Aug 10, 2026
@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — the test now exercises the production default SpendDashboardSource activity-loader path (no injected loader), the provider-architecture gatekeeper entries were re-anchored after the seam, and CI is green on 52b9b68.

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

steipete added a commit to openclaw/clawsweeper that referenced this pull request Aug 10, 2026
… stored slugs (#1100)

Every direct publication for a mixed-case repository name failed
deterministically: one side of the pipeline preserved the repository's case
in the expected slug while the other lowercased it in the record path, and
the Worker's containment checks compared with ===. GitHub repository names
are case-insensitive identifiers, so a case mismatch must never reject a
publication. ~170 of the ~191 tuple_protocol_invalid dead letters were one
mixed-case repository, and items like steipete/CodexBar#2797 were re-reviewed
to batch revision 14+ because their publication never persisted -- a full
Codex review burned per cycle, failing identically each time.

Validation at all seven comparison sites (Worker and client) is now
case-insensitive, and -- per review finding -- accepted slugs are
canonicalized to lowercase before durable writes, so storage keeps exactly
one namespace and an accepted uppercase path cannot fork the canonical or
export tables. Error messages preserve the original input case.

After deploy, the existing dead-letter reconciler re-runs the affected items
(all fresh_recovery.eligible) and they publish; the re-review loop stops
because publications finally persist.

Proof: docs/proof/mixed-case-publication-slugs drives the real Worker and
Durable Object over HTTP: a mixed-case plan with lowercase paths is accepted,
served from the lowercase namespace with no uppercase namespace rows, a
truly-foreign path is still rejected with the detailed 400, and lowercase
repos behave identically. Verified on the reviewed head in a Docker-backed
Crabbox local-container.
@steipete

Copy link
Copy Markdown
Owner

@clawsweeper re-review

The branch was updated onto current main to avoid a stale-green merge. Please review exact head bab3a2910a5b8531a4de567926b98e2fe3d99e64; the contributor-authored functional diff is unchanged and fresh CI is running.

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 68f26b5 into steipete:main Aug 10, 2026
9 checks passed
@steipete

Copy link
Copy Markdown
Owner

Merged as 68f26b5d65c96cf3239722a4caff97acfaf7162d after refreshing the branch onto current main.

Proof:

  • Focused exact-head terminal proof in the PR body: swift test --filter SpendDashboardTokenActivityIntegrationTests — 2/2 passed through the production default activity-loader path.
  • Broader contributor proof: swift test --filter SpendDashboard — 128 tests passed; swift test --filter ProviderArchitectureGatekeeperTests — 38 tests passed.
  • Exact refreshed head: bab3a2910a5b8531a4de567926b98e2fe3d99e64.
  • CI run https://github.com/steipete/CodexBar/actions/runs/31414195643 — lint, both macOS test shards, Linux x64/arm64, musl, and aggregate lint-build-test all passed.
  • Fresh ClawSweeper review on the exact refreshed head found no actionable issues.

No live app proof was needed: this is regression-test coverage plus a narrow internal cache-root injection seam, with runtime defaults unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants