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

lone-surrogates-wire.spec.ts

29 lines1.0 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * A lone UTF-16 surrogate in a prompt, a tool result, or the arguments of a
5 * replayed tool call went to the provider unchanged. Providers reject that
6 * request as invalid JSON / UTF-8. `/api/lone-surrogates-wire` returns the
7 * raw Anthropic request body.
8 */
9test.describe('lone UTF-16 surrogates', () => {
10 test('are removed from the request body and valid pairs stay', async ({
11 request,
12 }) => {
13 const response = await request.post('/api/lone-surrogates-wire')
14 expect(response.ok()).toBe(true)
15 const result = (await response.json()) as {
16 ok: boolean
17 error?: string
18 requestBodies: Array<string>
19 }
20 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
21​
22 expect(result.requestBodies).toHaveLength(1)
23 const body = result.requestBodies[0]!
24 // `JSON.stringify` writes a lone surrogate as a `\udXXX` escape.
25 expect(body).not.toMatch(/\\ud[89a-f][0-9a-f]{2}/i)
26 expect(body).toContain('abc😀')
27 expect(body).toContain('"input":{"q":"ab"}')
28 })
29})