Skip to content

Commit fbb14bc

Browse files
committed
feat(heatmap): blue gradient 6 levels, white borders, and 221 new tests
1 parent b3e90bf commit fbb14bc

9 files changed

Lines changed: 1334 additions & 15 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,44 @@ describe("MistralHandler", () => {
156156
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow("API Error")
157157
})
158158

159+
it("should yield usage chunk with totalCost from stream", async () => {
160+
mockCreate.mockImplementationOnce(async (_options) => {
161+
const stream = {
162+
[Symbol.asyncIterator]: async function* () {
163+
yield {
164+
data: {
165+
choices: [
166+
{
167+
delta: { content: "Hello" },
168+
index: 0,
169+
},
170+
],
171+
usage: {
172+
promptTokens: 100,
173+
completionTokens: 50,
174+
totalTokens: 150,
175+
},
176+
},
177+
}
178+
},
179+
}
180+
return stream
181+
})
182+
183+
const iterator = handler.createMessage(systemPrompt, messages)
184+
const chunks: any[] = []
185+
for await (const chunk of iterator) {
186+
chunks.push(chunk)
187+
}
188+
189+
const usageChunks = chunks.filter((c) => c.type === "usage")
190+
expect(usageChunks.length).toBe(1)
191+
expect(usageChunks[0].inputTokens).toBe(100)
192+
expect(usageChunks[0].outputTokens).toBe(50)
193+
expect(usageChunks[0].totalCost).toBeDefined()
194+
expect(typeof usageChunks[0].totalCost).toBe("number")
195+
})
196+
159197
it("should handle thinking content as reasoning chunks", async () => {
160198
// Mock stream with thinking content matching new SDK structure
161199
mockCreate.mockImplementationOnce(async (_options) => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ describe("MoonshotHandler", () => {
191191
expect(usageChunks.length).toBeGreaterThan(0)
192192
expect(usageChunks[0].inputTokens).toBe(10)
193193
expect(usageChunks[0].outputTokens).toBe(5)
194+
expect(usageChunks[0].totalCost).toBeDefined()
195+
expect(typeof usageChunks[0].totalCost).toBe("number")
194196
})
195197

196198
it("should include cache metrics in usage information", async () => {
@@ -267,6 +269,8 @@ describe("MoonshotHandler", () => {
267269
expect(result.outputTokens).toBe(50)
268270
expect(result.cacheWriteTokens).toBe(0)
269271
expect(result.cacheReadTokens).toBe(20)
272+
expect(result.totalCost).toBeDefined()
273+
expect(typeof result.totalCost).toBe("number")
270274
})
271275

272276
it("should handle missing cache metrics gracefully", () => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ describe("OpenAiHandler", () => {
163163
expect(usageChunk).toBeDefined()
164164
expect(usageChunk?.inputTokens).toBe(10)
165165
expect(usageChunk?.outputTokens).toBe(5)
166+
expect(usageChunk?.totalCost).toBeDefined()
167+
expect(typeof usageChunk?.totalCost).toBe("number")
166168
})
167169

168170
it("should handle tool calls in non-streaming mode", async () => {
@@ -1020,6 +1022,8 @@ describe("OpenAiHandler", () => {
10201022
expect(usageChunk).toBeDefined()
10211023
expect(usageChunk?.inputTokens).toBe(10)
10221024
expect(usageChunk?.outputTokens).toBe(5)
1025+
expect(usageChunk?.totalCost).toBeDefined()
1026+
expect(typeof usageChunk?.totalCost).toBe("number")
10231027

10241028
// Verify the API call was made with correct Azure AI Inference Service path
10251029
expect(mockCreate).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)