Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * When the provider bills a `decide()` call but returns an answer that cannot
5 * be mapped, `decide()` rejects. The usage must still reach the `onUsage`
6 * middleware hook so the spend is not lost.
7 *
8 * The `/api/evaluate-usage-on-failure` route drives the OpenAI evaluate
9 * adapter against an aimock mount whose `/v1/decisions` response carries
10 * usage and a choice with no entry in `probabilities`.
11 */
12test.describe('evaluate — usage when answer mapping fails', () => {
13 test('decide() rejects and still reports usage', async ({ request }) => {
14 const res = await request.post('/api/evaluate-usage-on-failure')
15 expect(res.ok()).toBe(true)
16
17 const { error, onUsageReports } = (await res.json()) as {
18 error?: { name: string; message: string }
19 onUsageReports: Array<unknown>
20 }
21
22 expect(error).toEqual({
23 name: 'Error',
24 message: 'decide(): missing probability for choice "sales" on "queue"',
25 })
26 const usage = { promptTokens: 42, completionTokens: 7, totalTokens: 49 }
27 expect(onUsageReports).toEqual([expect.objectContaining(usage)])
28 })
29})