Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

reasoning-wire.spec.ts

89 lines2.6 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * Wire-format check for `chat({ reasoning: { level: 'medium' } })`.
5 *
6 * `/api/reasoning-wire` records the raw OpenAI and Anthropic request bodies
7 * with `wrapFetch`, because aimock's journal normalizes them. For Gemini, the
8 * `/reasoning-wire-gemini` mount answers only when the thinking config is
9 * right, so the answer text is the proof.
10 */
11type WireResponse = {
12 ok: boolean
13 error?: string
14 text?: string
15 bodies: Array<Record<string, unknown>>
17​
18async function run(
19 request: import('@playwright/test').APIRequestContext,
20 provider: string,
21 testId: string,
22): Promise<WireResponse> {
23 const res = await request.post(
24 `/api/reasoning-wire?provider=${provider}&testId=${encodeURIComponent(testId)}`,
25 )
26 expect(res.ok()).toBe(true)
27 const payload = (await res.json()) as WireResponse
28 expect(payload.error).toBeUndefined()
29 expect(payload.ok).toBe(true)
30 return payload
32​
33test.describe('chat({ reasoning }) — wire format', () => {
34 test('openai sends reasoning.effort with a summary', async ({
35 request,
36 testId,
37 }) => {
38 const { bodies } = await run(request, 'openai', testId)
39 expect(bodies[0]?.['model']).toBe('o3')
40 expect(bodies[0]?.['reasoning']).toEqual({
41 effort: 'medium',
42 summary: 'auto',
43 })
44 })
45​
46 test('anthropic sends budget thinking for a budget model', async ({
47 request,
48 testId,
49 }) => {
50 const { bodies } = await run(request, 'anthropic', testId)
51 expect(bodies[0]?.['model']).toBe('claude-sonnet-4-5')
52 expect(bodies[0]?.['thinking']).toEqual({
53 type: 'enabled',
54 budget_tokens: 8192,
55 })
56 expect(bodies[0]?.['max_tokens']).toBeGreaterThan(8192)
57 })
58​
59 test('anthropic sends output_config.effort for Claude 4.6', async ({
60 request,
61 testId,
62 }) => {
63 const { bodies } = await run(request, 'anthropic-adaptive', testId)
64 expect(bodies[0]?.['model']).toBe('claude-sonnet-4-6')
65 expect(bodies[0]?.['thinking']).toEqual({
66 type: 'adaptive',
67 display: 'summarized',
68 })
69 expect(bodies[0]?.['output_config']).toEqual({ effort: 'medium' })
70 expect(bodies[0]).not.toHaveProperty('effort')
71 })
72​
73 test('grok sends no reasoning for a model with no levels', async ({
74 request,
75 testId,
76 }) => {
77 const { bodies } = await run(request, 'grok', testId)
78 expect(bodies[0]?.['model']).toBe('xai/grok-4.20-reasoning')
79 expect(bodies[0]).not.toHaveProperty('reasoning')
80 })
81​
82 test('gemini sends a thinking budget with includeThoughts', async ({
83 request,
84 testId,
85 }) => {
86 const { text } = await run(request, 'gemini', testId)
87 expect(text).toBe('Thinking config accepted')
88 })
89})