Repository navigation
Conversation
#433 shipped cache-write (cache-creation) billing with one test on each half: `both_usage_parsers_read_anthropic_cache_creation_tokens` feeds the parsers, `settle_bills_cache_write_tokens_at_the_configured_price` feeds `settle_usage` directly. The propagation between those halves was crossed by no test. Measured: hard-coding the fourth argument of either `settle_usage` call to 0.0 (non-stream `parse_usage` path, and the same-protocol streaming `UsageCapture::finish` path) left all 588 existing tests green. These two end-to-end tests post a real request through the router to a fake Anthropic upstream and read the ledger back, one per path. Each asserts the token count in `transactions.cache_write_tokens` and in `usage_records.cache_write_tokens`, that `tokens` still excludes the write segment, and the charge at a configured price. Both set a non-zero `cache_write_input_per_m` on their own models row: every shipped model ships 0, so at the default price the charge term is zero and a recorded token is indistinguishable from a dropped one. Related: #433
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.
Summary
#433 shipped cache-write (cache-creation) billing with one test on each half of the feature:
both_usage_parsers_read_anthropic_cache_creation_tokensfeeds the parsers only;settle_bills_cache_write_tokens_at_the_configured_pricefeedssettle_usagedirectly.The propagation between those halves was crossed by no test. This PR adds the missing end-to-end coverage: one test per path, each posting a real request through the router to a fake Anthropic upstream and reading the ledger back.
parse_usagefour-tuple →settle_usage(4th arg)e2e_anthropic_cache_creation_reaches_the_ledgerUsageCapture::finishfour-tuple → flow-tailsettle_usagee2e_anthropic_stream_cache_creation_reaches_the_ledgerEach asserts:
transactions.cache_write_tokenscarries the upstreamusage.cache_creation_input_tokens;usage_records.cache_write_tokenscarries the same count;tokensstill means input + cached + output (the write segment stays in its own column, as feat(billing): bill cache-write (cache-creation) tokens #433 specified);Why the price must be configured in the test
Every shipped model sets
cache_write_input_per_m = 0, so at the default price the cache-write term is zero and a test cannot tell "the token reached the ledger" from "the token was dropped". Both tests therefore set a non-zero price on their ownmodelsrow and assert the money alongside the count.Measured teeth (not just green)
Each seam was mutated on its own, and each mutation reddens exactly one test:
settle_usage4th argument →0.0:e2e_anthropic_cache_creation_reaches_the_ledgerfails at thecache_write_tokensassertion (left: 0.0, right: 400.0), the streaming test stays green.settle_usagelast argument →0.0:e2e_anthropic_stream_cache_creation_reaches_the_ledgerfails at itscache_write_tokensassertion (left: 0.0, right: 400.0), the non-stream test stays green.Before this PR both mutations left the whole suite green.
Related Issue
Follow-up to #433, which is already merged — this closes the coverage gap that feature left, it does not change behaviour. No production code is touched: the diff is test-only (
src/gateway.rs, +226 lines insidemod tests).Tests
cargo test: 590 passed, 0 failed (588 before this PR)cargo fmt --checkcleancargo clippy --all-targets -- -D warningsclean