Skip to content

test(translation): cover Claude Code 2.1.84 billing-header rotation variants#580

Open
icebear0828 wants to merge 1 commit into
devfrom
test/billing-header-variant-fixtures
Open

test(translation): cover Claude Code 2.1.84 billing-header rotation variants#580
icebear0828 wants to merge 1 commit into
devfrom
test/billing-header-variant-fixtures

Conversation

@icebear0828
Copy link
Copy Markdown
Owner

Summary

Lock down the existing x-anthropic-billing-header strip against silent regression. Three batches of live /v1/messages ingress samples (~50 requests) confirmed Claude Code 2.1.84 always emits the billing header as a standalone system[0] block with rotating cc_version (3-hex suffix) and cch (5-hex cache-buster token) per request. The existing startsWith strip handles this shape, but only one fixture covered it — a future refactor (regex swap, inline cleanup) could quietly leak cch into instructions and defeat the upstream prompt-cache anchor.

Changes

  • tests/unit/translation/anthropic-to-codex.test.ts
    • Add it.each over five observed cc_version suffixes (c8e / 76b / f51 / 5b4 / 4f3)
    • Each variant uses the real 3-block shape (billing block + "You are Claude Code..." + main prompt) with cache_control: ephemeral markers on the prompt blocks
    • Each variant asserts byte-identical instructions AND that the output contains no cch= / cc_version= / x-anthropic-billing substring
    • Add an explicit invariance test: two different billing-header values produce identical instructions
  • CHANGELOG.md### Fixed bullet under [Unreleased]

No production code change.

Test Plan

  • npx vitest run tests/unit/translation/anthropic-to-codex.test.ts — 47 tests pass (40 existing + 6 new variant + 1 invariance)
  • Pre-push hook validates the whole branch

Notes

Data backing the variants comes from logs.capture_body=true on the local dev proxy with a real Claude Code client. All five cc_version suffixes and 50+ distinct cch tokens were observed; the strip is invariant across all of them today, this PR proves it.

…ariants

Three batches of live samples (~50 /v1/messages ingress) confirm Claude
Code 2.1.84 always emits x-anthropic-billing-header as a standalone
system[0] block with rotating cc_version (3-hex suffix) and cch (5-hex
token) per request. The existing prefix-startsWith strip handles this
shape correctly, but only a single fixture exercised it. A future
refactor — swapping the prefix check for a regex, adding inline
cleanup, etc. — could silently regress and leak cch back into the
flattened instructions, defeating the cache-buster guard that
inspired the strip in the first place.

Add an it.each fixture across five observed cc_version suffixes
(c8e / 76b / f51 / 5b4 / 4f3) plus an explicit invariance assertion
that two different billing-header values produce byte-identical
instructions. Fixture mirrors the real 3-block shape including
cache_control ephemeral markers on the prompt blocks.

No production code change.
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