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

openrouter-json-object-wire.spec.ts

75 lines2.2 KB

1import { test, expect } from './fixtures'
2​
3type JournalEntry = {
4 headers?: Record<string, string>
5 body: {
6 response_format?: Record<string, unknown>
7 messages?: Array<{ role: string; content: unknown }>
8 } | null
9}
10​
11test.describe('openrouter — json_object structured output', () => {
12 test.beforeEach(async ({ request, aimockPort }) => {
13 await request.delete(`http://127.0.0.1:${aimockPort}/v1/_requests`)
14 })
15​
16 test('preserves json_object through the SDK wire path (#1005)', async ({
17 request,
18 aimockPort,
19 testId,
20 }) => {
21 const response = await request.post(
22 `/api/openrouter-json-object-wire?testId=${encodeURIComponent(testId)}`,
23 )
24 expect(response.ok()).toBe(true)
25 expect(await response.json()).toEqual({
26 ok: true,
27 result: { name: 'Alice', age: 30 },
28 })
29​
30 const journalResponse = await request.get(
31 `http://127.0.0.1:${aimockPort}/v1/_requests`,
32 )
33 const entries = (await journalResponse.json()) as Array<JournalEntry>
34 const captured = entries.find(
35 (entry) => entry.headers?.['x-test-id'] === testId,
36 )
37​
38 expect(captured?.body?.response_format).toEqual({
39 type: 'json_object',
40 })
41 })
42​
43 test('sends json_object and the schema prompt for qwen/qwen3.7-flash (#1005)', async ({
44 request,
45 aimockPort,
46 testId,
47 }) => {
48 const response = await request.post(
49 `/api/openrouter-json-object-wire?via=catalog&testId=${encodeURIComponent(testId)}`,
50 )
51 expect(response.ok()).toBe(true)
52 expect(await response.json()).toEqual({
53 ok: true,
54 result: { name: 'Alice', age: 30 },
55 })
56​
57 const journalResponse = await request.get(
58 `http://127.0.0.1:${aimockPort}/v1/_requests`,
59 )
60 const entries = (await journalResponse.json()) as Array<JournalEntry>
61 const captured = entries.find(
62 (entry) =>
63 entry.headers?.['x-test-id'] === testId &&
64 entry.body?.response_format != null,
65 )
66​
67 expect(captured?.body?.response_format).toEqual({
68 type: 'json_object',
69 })
70 expect(captured?.body?.messages?.[0]).toEqual({
71 role: 'system',
72 content: expect.stringContaining('"required":["name","age"]'),
73 })
74 })
75})