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

json-schema-tool-input.spec.ts

31 lines1.2 KB

1import { test, expect } from './fixtures'
2​
3test('a JSON Schema tool repairs "3" to 3, returns a tool error for input it cannot repair, and a nullable field takes null', async ({
4 request,
5}) => {
6 const response = await request.post('/api/json-schema-tool-input')
7​
8 expect(response.ok()).toBe(true)
9 const body = await response.json()
10 // The repaired call and the OpenAPI 3.0 nullable tool ran.
11 expect(body.runs).toEqual([{ count: 3 }, { label: null }])
12 expect(body.text).toContain('Input validation failed for tool count_items')
13 expect(body.text).toContain('#/count')
14 expect(body.text).toContain('Tool said: counted')
15 expect(body.text).toContain('Tool said: labeled')
16})
17​
18test('a repairToolInput function replaces the built-in repair', async ({
19 request,
20}) => {
21 const response = await request.post('/api/json-schema-tool-input', {
22 data: { repair: 'custom' },
23 })
24​
25 expect(response.ok()).toBe(true)
26 const body = await response.json()
27 // The function repaired 'many'. The built-in repair did not fix '3'.
28 expect(body.runs).toEqual([{ count: 2 }, { label: null }])
29 expect(body.text).toContain('Input validation failed for tool count_items')
30 expect(body.text).toContain('Tool said: counted')
31})