test: cover usage-summary.mjs - #14
Merged
Merged
Conversation
usage-summary.mjs shipped without tests, so the metering/cost path had no coverage at all. 27 tests across four areas: - aggregation: grouping by model, zero-defaults for missing fields, the "(unknown)" model bucket, blocked = status >= 400, retry summing. - best-effort I/O: blank vs malformed lines, unreadable price list degrading to tokens-only, and a missing file argument as the only exit-2 path. - price-list resolution: exact key, vendor-prefix drop, case-insensitive basename, dated-snapshot and release-channel suffix stripping, and an ambiguous basename staying unpriced rather than guessed. - cost math: ratio 1 == $2.00/1M input, completion_ratio on output only, cache_ratio discount, and the case that costs real money to get wrong -- a price entry with no cache_ratio bills cached tokens at the FULL input rate, so identical token counts cost double. Uses spawnSync rather than the async spawn in report.test.mjs: this script talks to no network, so the test event loop does not need to stay live. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
scripts/usage-summary.mjsshipped without any tests, so the metering and cost path had no coverage. This adds 27 tests.What is covered
Aggregation - grouping by model, zero-defaults for missing fields, the
(unknown)bucket,blockedcounting onlystatus >= 400, retry summing, andcache_hit_rate: nullwhen there are no prompt tokens.Best-effort I/O - blank lines are skipped without being counted as malformed; a malformed line is counted and skipped but still exits 0; an unreadable price list degrades to tokens-only; a missing file argument is the only exit-2 path.
Price-list resolution - exact key, vendor-prefix drop, case-insensitive basename, dated-snapshot (
-YYYY-MM-DD) and release-channel (-preview/-latest/-stable) suffix stripping, and an ambiguous basename staying unpriced rather than guessed.Cost math - ratio 1 == $2.00/1M input,
completion_ratioapplied to output only, thecache_ratiodiscount, and the case that costs real money to get wrong: a price entry with nocache_ratiobills cached tokens at the full input rate, so an identical token count costs double.Notes
spawnSyncrather than the asyncspawninreport.test.mjs. That file needs an async spawn because its mock control plane runs in the test process; this script talks to no network, so the event loop does not need to stay live.--pricing, which is the documented argument order.Separate issue found while writing these
Argument order is not handled: the file is picked as the first argv entry not starting with
--, so putting the flag first makes the pricing file get read as the usage file, silently and with no error.Not fixed here to keep this PR test-only.
🤖 Generated with Claude Code