Skip to content

Commit 61bb66b

Browse files
committed
✅ test: close final coverage gap (#404)
1 parent 380bc30 commit 61bb66b

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,5 +1185,25 @@ describe("AnthropicHandler", () => {
11851185
const reasoning = chunks.filter((c) => c.type === "reasoning")
11861186
expect(reasoning.some((c) => c.text === "hmm")).toBe(true)
11871187
})
1188+
1189+
it("should yield usage from message_delta events", async () => {
1190+
mockCreate.mockImplementationOnce(async () => ({
1191+
async *[Symbol.asyncIterator]() {
1192+
yield { type: "message_start", message: { usage: { input_tokens: 1, output_tokens: 1 } } }
1193+
yield { type: "content_block_start", index: 0, content_block: { type: "text", text: "hi" } }
1194+
yield { type: "message_delta", usage: { output_tokens: 5 } }
1195+
yield { type: "message_stop" }
1196+
},
1197+
}))
1198+
1199+
const stream = handler.createMessage("sys", [{ role: "user", content: "hi" }])
1200+
const chunks: any[] = []
1201+
for await (const c of stream) {
1202+
chunks.push(c)
1203+
}
1204+
const usageChunks = chunks.filter((c) => c.type === "usage")
1205+
expect(usageChunks.length).toBeGreaterThanOrEqual(2)
1206+
expect(usageChunks[1]).toEqual({ type: "usage", inputTokens: 0, outputTokens: 5 })
1207+
})
11881208
})
11891209
})

src/api/providers/__tests__/poe.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,35 @@ describe("PoeHandler", () => {
248248
)
249249
})
250250

251+
it("respects modelMaxTokens with reasoning effort", async () => {
252+
const handler = new PoeHandler({
253+
poeApiKey: "key",
254+
apiModelId: "openai/o3",
255+
enableReasoningEffort: true,
256+
reasoningEffort: "high",
257+
modelMaxTokens: 1024,
258+
})
259+
260+
const fullStream = (async function* () {
261+
yield { type: "text-delta", text: "Answer" }
262+
})()
263+
264+
mockStreamText.mockReturnValue({
265+
fullStream,
266+
usage: Promise.resolve({ inputTokens: 10, outputTokens: 5 }),
267+
})
268+
269+
for await (const _ of handler.createMessage("system", [{ role: "user" as const, content: "reason" }])) {
270+
/* drain */
271+
}
272+
273+
expect(mockStreamText).toHaveBeenCalledWith(
274+
expect.objectContaining({
275+
maxOutputTokens: 1024,
276+
}),
277+
)
278+
})
279+
251280
it("does not pass providerOptions when reasoning is disabled", async () => {
252281
const handler = new PoeHandler({
253282
poeApiKey: "key",

0 commit comments

Comments
 (0)