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

openrouter-stream-options-wire.spec.ts

40 lines1.3 KB

1import { test, expect } from './fixtures'
2​
3type JournalEntry = {
4 headers?: Record<string, string>
5 body: {
6 stream_options?: Record<string, unknown>
7 } | null
8}
9​
10test.describe('openrouter — stream_options wire format', () => {
11 for (const scenario of ['usage-off', 'default'] as const) {
12 test(`${scenario}: stream_options on the wire (#1037)`, async ({
13 request,
14 aimockPort,
15 testId,
16 }) => {
17 const response = await request.post(
18 `/api/openrouter-stream-options-wire?testId=${encodeURIComponent(testId)}&scenario=${scenario}`,
19 )
20 expect(response.ok()).toBe(true)
21 expect(((await response.json()) as { ok: boolean }).ok).toBe(true)
22​
23 const journalResponse = await request.get(
24 `http://127.0.0.1:${aimockPort}/v1/_requests`,
25 )
26 const entries = (await journalResponse.json()) as Array<JournalEntry>
27 const captured = entries.find(
28 (entry) => entry.headers?.['x-test-id'] === testId,
29 )
30 expect(captured).toBeDefined()
31 expect(captured?.body).toEqual(expect.any(Object))
32​
33 if (scenario === 'usage-off') {
34 expect(captured?.body).not.toHaveProperty('stream_options')
35 } else {
36 expect(captured?.body?.stream_options).toEqual({ include_usage: true })
37 }
38 })
39 }
40})