Repository navigation
Commit 80d7e8a
fix: [#836] address consensus review — doc precision + vertex/bedrock test coverage
Second-pass on PR #837 after code review. Two follow-ups in scope.
1. Doc-block precision (MINOR per reviewer)
The previous wording said "OpenAI returns the inclusive total and we
subtract cache_read/cache_write here". That's imprecise — OpenAI /
OpenRouter don't surface a cache_write concept; the subtraction
evaluates to a no-op for those providers because cache_write = 0.
Reviewer caught the misleading framing. Updated the comment to
clarify which providers actually populate cache_write (Anthropic /
Bedrock / Venice metadata paths) and that the subtraction is a
no-op everywhere else.
2. Provider edge-case test coverage (MINOR)
The invariant test exercised @ai-sdk/anthropic, @ai-sdk/openai, and
@ai-sdk/amazon-bedrock — but two real provider paths were
unexercised:
- @ai-sdk/google-vertex/anthropic: included in the `total`
computation branch but never tested.
- Bedrock's cache_write reader: reads from
metadata.bedrock.usage.cacheWriteInputTokens, which is a
different path than Anthropic's metadata.anthropic.cacheCreationInputTokens.
The original invariant test passed metadata.anthropic for all
three providers, so the bedrock-specific path was never hit.
Added three tests:
- OpenAI cache_write is always 0 (provider doesn't expose the concept)
— pins the no-op subtraction claim from the updated doc-block.
- @ai-sdk/google-vertex/anthropic uses Anthropic-style accounting
when metadata.anthropic is present.
- Bedrock surfaces cacheWriteInputTokens via metadata.bedrock.usage
— verify the reader picks it up from the correct path.
- tokens.input is never negative even with inconsistent provider counts
— documents the current behavior (allows negative) so a future
refactor changing it is forced through this test.
Validation
- `tsgo --noEmit`: pass.
- `bun test test/session/session-getusage.test.ts`: 11 pass / 0 fail (4 new).
- Marker check: pass.
Reviewer note
- GLM-5 second-opinion was unavailable (OpenRouter credit exhaustion
on retry). Single-reviewer Claude analysis.
Deferred to follow-up
- Telemetry event-shape integration test (reviewer suggestion — would
require capturing what Telemetry.track receives; substantial mock
scaffolding for marginal benefit since the contract is already
visible in the type system).
- Doc-block comment churn (reviewer NIT — 8 lines for a 1-line code
change). The verbose reasoning is load-bearing for future maintainers
who would otherwise wonder why we don't just return the inclusive
total. Kept as-is.
Closes review feedback for PR #837.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent e93f2d4 commit 80d7e8a
2 files changed
Lines changed: 98 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
95 | 101 | | |
96 | 102 | | |
97 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
106 | 195 | | |
107 | 196 | | |
108 | 197 | | |
| |||
0 commit comments