Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * Verifies that detailed token-usage breakdowns reach `RUN_FINISHED.usage`. The
5 * `/api/openai-usage-details` route drives the OpenAI chat adapter against an
6 * aimock mount whose stream ends with a usage chunk carrying
7 * `prompt_tokens_details.cached_tokens` and
8 * `completion_tokens_details.reasoning_tokens`. The shared `@tanstack/openai-base`
9 * extractor normalizes those into the canonical `TokenUsage` shape, so this is
10 * the end-to-end proof that detailed usage survives the chat pipeline + SSE.
11 */
12test.describe('openai — detailed usage breakdown', () => {
13 test('cached and reasoning token details reach RUN_FINISHED.usage', async ({
14 request,
15 }) => {
16 const res = await request.post('/api/openai-usage-details')
17 expect(res.ok()).toBe(true)
18
19 const { ok, usage, error } = (await res.json()) as {
20 ok: boolean
21 error?: string
22 usage?: {
23 promptTokens?: number
24 completionTokens?: number
25 totalTokens?: number
26 promptTokensDetails?: { cachedTokens?: number }
27 completionTokensDetails?: { reasoningTokens?: number }
28 }
29 }
30
31 expect(error ?? null).toBeNull()
32 expect(ok).toBe(true)
33 expect(usage).toMatchObject({
34 promptTokens: 100,
35 completionTokens: 50,
36 totalTokens: 150,
37 promptTokensDetails: { cachedTokens: 80 },
38 completionTokensDetails: { reasoningTokens: 30 },
39 })
40 })
41})