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

openai-strict-tool-null-wire.spec.ts

62 lines1.7 KB

1import { expect, test } from './fixtures'
2​
3test.describe('openai strict tool optional fields', () => {
4 test('undoes provider-added nullability before tool validation and execution', async ({
5 request,
6 }) => {
7 const response = await request.post('/api/openai-strict-tool-null-wire')
8 expect(response.ok()).toBe(true)
9 const result = (await response.json()) as {
10 ok: boolean
11 error?: string
12 requestCount: number
13 firstRequestBody: {
14 tools: Array<{
15 name: string
16 strict: boolean
17 parameters: {
18 required: Array<string>
19 properties: Record<
20 string,
21 {
22 type?: string | Array<string>
23 anyOf?: Array<{ type: string }>
24 enum?: Array<unknown>
25 }
26 >
27 }
28 }>
29 }
30 executedInput: Record<string, unknown>
31 text: string
32 }
33​
34 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
35​
36 const tool = result.firstRequestBody.tools.find(
37 ({ name }) => name === 'ask_user',
38 )
39 expect(tool).toMatchObject({
40 strict: true,
41 parameters: {
42 required: ['mode', 'question', 'options', 'nullableNote'],
43 properties: {
44 mode: {
45 type: ['string', 'null'],
46 enum: ['canary', null],
47 },
48 options: { type: ['array', 'null'] },
49 nullableNote: {
50 anyOf: [{ type: 'string' }, { type: 'null' }],
51 },
52 },
53 },
54 })
55 expect(result.executedInput).toEqual({
56 question: 'Which option?',
57 nullableNote: null,
58 })
59 expect(result.requestCount).toBe(2)
60 expect(result.text).toBe('Tool executed.')
61 })
62})