Skip to content

Commit 4dc2269

Browse files
committed
test(api): assert reasoningTokens property absence in Anthropic usage fixtures
CodeRabbit finding on the unset-value usage assertions: toBeUndefined() only checks the value and Vitest toEqual ignores own properties whose value is undefined, so a regression that starts emitting easoningTokens: undefined would pass. Switch the Anthropic start/delta assertions and the Vertex unset-value fixture to not.toHaveProperty so the property absence is asserted directly.
1 parent a32bbb3 commit 4dc2269

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/api/providers/__tests__/anthropic-vertex.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,11 @@ describe("VertexHandler", () => {
15581558
outputTokens: 200,
15591559
},
15601560
])
1561+
// Property absence, not just undefined: toEqual ignores own properties whose
1562+
// value is undefined, so a regression that adds `reasoningTokens: undefined`
1563+
// to either chunk must fail these assertions.
1564+
expect(chunks[0]).not.toHaveProperty("reasoningTokens")
1565+
expect(chunks[1]).not.toHaveProperty("reasoningTokens")
15611566
})
15621567

15631568
it("should preserve a zero-valued thinking_tokens in message_start and message_delta usage chunks", async () => {

‎src/api/providers/__tests__/anthropic.spec.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,10 @@ describe("AnthropicHandler", () => {
596596
)
597597
const startUsage = usageChunks.find((chunk) => chunk.inputTokens > 0)
598598
expect(startUsage).toBeDefined()
599-
expect(startUsage?.reasoningTokens).toBeUndefined()
599+
// Property absence, not just undefined: toEqual ignores own properties
600+
// whose value is undefined, so a regression that adds
601+
// `reasoningTokens: undefined` must fail this assertion.
602+
expect(startUsage).not.toHaveProperty("reasoningTokens")
600603

601604
// message_delta surfaces the final reasoning token count
602605
const deltaUsage = usageChunks.find((chunk) => chunk.inputTokens === 0)
@@ -681,7 +684,8 @@ describe("AnthropicHandler", () => {
681684
const deltaUsage = usageChunks.find((chunk) => chunk.inputTokens === 0)
682685
expect(deltaUsage).toBeDefined()
683686
expect(deltaUsage?.outputTokens).toBe(200)
684-
expect(deltaUsage?.reasoningTokens).toBeUndefined()
687+
// Property absence, not just undefined (toEqual ignores undefined values).
688+
expect(deltaUsage).not.toHaveProperty("reasoningTokens")
685689
})
686690

687691
it("should preserve a zero-valued thinking_tokens in message_start and message_delta usage chunks", async () => {

0 commit comments

Comments
 (0)