Skip to content

fix: stop --pricing from being mistaken for the usage file - #17

Merged
ZhenghuaBao merged 1 commit into
mainfrom
fix/usage-summary-argv
Aug 19, 2026
Merged

fix: stop --pricing from being mistaken for the usage file#17
ZhenghuaBao merged 1 commit into
mainfrom
fix/usage-summary-argv

Conversation

@ZhenghuaBao

Copy link
Copy Markdown
Contributor

The bug

usage-summary.mjs picked its input file with a separate scan for "the first argv entry that does not start with --":

const file = argv.find((a) => !a.startsWith("--"));

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.

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:

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: it doesn't look like an error, it looks like a cheap model.

Scope

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.

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 --pricing or one followed by another flag does not swallow it.

Tests

6 added (27 -> 33 in this file):

  • --pricing before the usage file no longer steals it, and the price list is still applied
  • both argument orders produce identical output
  • the first positional wins; a stray extra one does not override it
  • --json is recognized wherever it appears
  • a valueless --pricing does not swallow the flag after it
  • a trailing --pricing with nothing after it is harmless

🤖 Generated with Claude Code

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>
@ZhenghuaBao
ZhenghuaBao merged commit 024fb64 into main Aug 19, 2026
2 checks passed
@ZhenghuaBao
ZhenghuaBao deleted the fix/usage-summary-argv branch August 19, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant