fix: stop --pricing from being mistaken for the usage file - #17
Merged
Conversation
usage-summary.mjs picked its input with a separate scan for "the first argv
entry that does not start with --". A flag's VALUE is not a positional
argument, though: --pricing takes a path, and a path does not start with
"--", so putting the flag first made the price list get read as the metering
file.
The failure was silent rather than loud. A price list is itself valid JSON,
so it parsed as a single metering row with no token fields:
node usage-summary.mjs --pricing pricing.json usage.jsonl --json
-> calls: 1, prompt_tokens: 0
Exit 0, no warning, not even a malformed-line count -- and the real usage
file never read. For a script whose entire purpose is comparing model costs,
a plausible-looking $0.00 is the worst possible output.
Fold the two scans into one pass that advances past a flag's value, and only
consume that value when it is actually a value, so a trailing --pricing or
one followed by another flag does not swallow it.
Not reachable from action.yml, which calls `node "$USAGE_SUMMARY"
"$USAGE_FILE"` -- file first, and no --pricing at all. This only bit manual
cost-comparison runs, which is exactly when --pricing gets used.
Adds 6 tests: both orders agree, the first positional wins, --json is
position-independent, and the two valueless --pricing shapes are harmless.
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.
The bug
usage-summary.mjspicked its input file with a separate scan for "the first argv entry that does not start with--":A flag's value is not a positional argument, though.
--pricingtakes a path, and a path does not start with--, so putting the flag first made the price list get read as the metering file.Why it mattered
The failure was silent rather than loud. A price list is itself valid JSON, so it parsed as a single metering row with no token fields:
Exit 0, no warning, not even a malformed-line count — and the real usage file never read. For a script whose entire purpose is comparing model costs, a plausible-looking
$0.00is the worst possible output: it doesn't look like an error, it looks like a cheap model.Scope
Not reachable from
action.yml, which callsnode "$USAGE_SUMMARY" "$USAGE_FILE"— file first, and no--pricingat all. This only bit manual cost-comparison runs, which is exactly when--pricinggets used.The fix
Fold the two scans into one pass that advances past a flag's value. The value is only consumed when it actually is one, so a trailing
--pricingor one followed by another flag does not swallow it.Tests
6 added (27 -> 33 in this file):
--pricingbefore the usage file no longer steals it, and the price list is still applied--jsonis recognized wherever it appears--pricingdoes not swallow the flag after it--pricingwith nothing after it is harmless🤖 Generated with Claude Code