Repository navigation
Add regression coverage for Z.AI input and cache token totals - #75383
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Reviewed the test-only changes. The added coverage is useful and the aggregation assertions are aligned with the reported regression.
Highlights
- One portability concern: the JavaScript summary assertion hard-codes US comma formatting despite locale-sensitive rendering; see the inline comment.
- No correctness or security-blocking issues found in the changed lines.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
| cache_write_tokens: 0, | ||
| }); | ||
| const markdown = mockCore.summary.addRaw.mock.calls[0][0]; | ||
| expect(markdown).toMatch(/\|\s*38,719\s*\|\s*4,058\s*\|\s*112,640\s*\|\s*0\s*\|/); |
There was a problem hiding this comment.
This assertion makes the regression test locale-dependent, so CI on a non-US locale can fail even when token aggregation is correct.
💡 Make the expected formatting deterministic
toLocaleString() uses the runner locale, while this regex hard-codes comma grouping (38,719). Pass an explicit locale in the production/test formatter or assert the parsed table row using a locale-independent representation; also scope the match to the intended model row so another row cannot satisfy it accidentally.
There was a problem hiding this comment.
Updated the row check to use the runtime locale’s number formatting and scope the match to the glm53 row. Commit: 36744f1.
There was a problem hiding this comment.
🟢 Approval recommended
The supplied status records no active issues for this regression-coverage change, which targets preservation of Z.AI token totals through aggregation and detection reporting.
No open issues 🎉
What changed in this PR
Adds regression coverage for preserving Z.AI input, output, cache-read, and cache-write token totals through CLI aggregation and detection reporting.
Changes:
- Adds Go tests for aggregate and per-model token totals.
- Adds JavaScript tests for detection summaries and usage artifacts.
- Covers the reported totals: 38,719 input, 4,058 output, and 112,640 cache-read tokens.
| File | Summary | Findings |
|---|---|---|
pkg/cli/token_usage_test.go |
Verifies aggregate and per-model Z.AI token totals. | No issues identified. |
actions/setup/js/parse_token_usage.test.cjs |
Verifies detection summary rendering and usage artifact preservation. | Two moderate issues: the test does not configure and verify the detection artifact path, and its summary assertion is not anchored to the aggregate total row. |
This pull request requires changes.
Review effort: Lite (auto)
There was a problem hiding this comment.
What this change does:
Adds regression coverage for normalized Z.AI Anthropic-compatible usage in the Go parser and JavaScript detection path. It checks aggregate and per-model totals, summary rendering, and artifact output.
Nice to have
-
Derived total assertion adds no coverage (
pkg/cli/token_usage_test.go:L63)- What this is: This assertion recomputes a value from the three token totals already asserted above.
- Problem: It cannot catch a production regression independently; when those assertions pass, the sum is necessarily 155417, so it only adds another literal to maintain.
- Fix: Delete the assertion.
- If we skip it: The test carries a redundant check and a second place to update when the fixture totals change.
Verdict: Ship.
Lean: -1 lines possible.
Generated by ✂️ Ponytail Reviewer for #75383 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| assert.Equal(t, 4058, summary.TotalOutputTokens) | ||
| assert.Equal(t, 112640, summary.TotalCacheReadTokens) | ||
| assert.Zero(t, summary.TotalCacheWriteTokens) | ||
| assert.Equal(t, 155417, summary.TotalInputTokens+summary.TotalOutputTokens+summary.TotalCacheReadTokens) |
There was a problem hiding this comment.
What this is: This assertion recomputes a value from the three token totals already asserted above. Problem: It cannot catch a production regression independently; when those assertions pass, the sum is necessarily 155417, so it only adds another literal to maintain. Fix: Delete this assertion. If we skip it: The test carries a redundant check and a second place to update when the fixture totals change.
There was a problem hiding this comment.
Removed the redundant derived-total assertion. Commit: 36744f1.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd to the two new regression tests. No blocking issues. Two minor test-quality suggestions are posted inline.
📋 Key Themes & Highlights
Key Themes
- Test style: the JS test reads
addRaw.mock.calls[0][0]directly, while the rest of the file usestoHaveBeenCalledWith(expect.stringContaining(...), true). - Redundant assertion: the Go sum check (155417) repeats the three field assertions above it.
Positive Highlights
- ✅ Both tests use the same synthetic record, so the Go and JS coverage stay aligned.
- ✅ The JS test checks that the source JSONL is unchanged, which guards the artifact-preservation claim.
- ✅ The Go subtest passes locally (
go test -run TestParseTokenUsageFile, subtestZ.AI_Anthropic-compatible_usage).
Verification gap
I could not run the JS test. npm ci fails in this sandbox on a TLS certificate error from the npm registry, and vitest is not installed. I checked the JS assertions by reading the source: the table regex matches the column order in generateTokenUsageSummary, the addRaw mock is reset in beforeEach, and the file paths honour GH_AW_TMP_DIR. Please confirm the JS test in CI.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again
| cache_read_tokens: 112640, | ||
| cache_write_tokens: 0, | ||
| }); | ||
| const markdown = mockCore.summary.addRaw.mock.calls[0][0]; |
There was a problem hiding this comment.
[/tdd] The row check reads mock.calls[0][0], which depends on no earlier addRaw call and couples the test to call order. Use the toHaveBeenCalledWith(expect.stringContaining(...), true) style that other tests in this file already use, so the assertion reads as a spec.
💡 Suggested change
expect(mockCore.summary.addRaw).toHaveBeenCalledWith(expect.stringMatching(/\|\s*38,719\s*\|\s*4,058\s*\|\s*112,640\s*\|\s*0\s*\|/), true);This also removes the local markdown variable.
@copilot please address this.
There was a problem hiding this comment.
Changed the assertion to toHaveBeenCalledWith and made it target the glm53 row using locale-aware values. Commit: 36744f1.
| assert.Equal(t, 4058, summary.TotalOutputTokens) | ||
| assert.Equal(t, 112640, summary.TotalCacheReadTokens) | ||
| assert.Zero(t, summary.TotalCacheWriteTokens) | ||
| assert.Equal(t, 155417, summary.TotalInputTokens+summary.TotalOutputTokens+summary.TotalCacheReadTokens) |
There was a problem hiding this comment.
[/tdd] This sum check repeats the three field assertions above it and hard-codes a derived total (155417). It adds no coverage and goes stale if the fixture changes. Consider removing it.
@copilot please address this.
There was a problem hiding this comment.
Removed the redundant derived-total assertion. Commit: 36744f1.
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: 2d2968b
|
Sous-chef requested-head: 2d2968b Work is underway: merge the latest main, fix the locale-sensitive and call-order-dependent JavaScript assertion, remove the redundant Go total assertion, run focused validation, then report and resolve the review threads. |
Z.AI’s Anthropic-compatible endpoint reported zero input and cache-read tokens in proxy summaries despite nonzero CLI counts. The current AWF pin already includes the upstream capture fix; this PR adds downstream regression coverage.