Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * `/api/moonshot-usage-details` streams a chat through the OpenAI-compatible
5 * adapter from a mount that returns Moonshot's usage shape. Cache reads and
6 * cache writes must reach `RUN_FINISHED.usage`.
7 */
8test.describe('openai-compatible — Moonshot usage', () => {
9 test('cache read and cache write tokens reach RUN_FINISHED.usage', async ({
10 request,
11 }) => {
12 const res = await request.post('/api/moonshot-usage-details')
13 expect(res.ok()).toBe(true)
14
15 const { ok, usage, error } = (await res.json()) as {
16 ok: boolean
17 error?: string
18 usage?: {
19 promptTokensDetails?: {
20 cachedTokens?: number
21 cacheWriteTokens?: number
22 }
23 }
24 }
25
26 expect(error ?? null).toBeNull()
27 expect(ok).toBe(true)
28 expect(usage).toMatchObject({
29 promptTokens: 1000,
30 completionTokens: 50,
31 totalTokens: 1050,
32 promptTokensDetails: { cachedTokens: 800, cacheWriteTokens: 150 },
33 })
34 })
35})