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

anthropic-thinking-order-wire.spec.ts

43 lines1.6 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * Claude signs each thinking block against the blocks before it. When
5 * web_search runs inside one response, a follow-up request that replays the
6 * turn as "thinking, thinking, text, server_tool_use, result" fails with
7 * "thinking blocks in the latest assistant message cannot be modified".
8 * `/api/anthropic-thinking-order-wire` scripts that response and returns what
9 * the wire and the client saw.
10 */
11test.describe('anthropic — signed thinking order around web_search', () => {
12 test('replay, client tools, and the interrupt view keep the order', async ({
13 request,
14 }) => {
15 const response = await request.post('/api/anthropic-thinking-order-wire')
16 expect(response.ok()).toBe(true)
17 const result = (await response.json()) as {
18 ok: boolean
19 error?: string
20 replayedBlocks: Array<string>
21 clientToolRequests: Array<string>
22 viewAfterInterrupt: Array<Array<string>>
23 }
24 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
25​
26 // The second request replays the first turn in the order Claude signed it.
27 expect(result.replayedBlocks).toEqual([
28 'thinking',
29 'server_tool_use',
30 'web_search_tool_result',
31 'thinking',
32 'text',
33 ])
34​
35 // Only the real client tool waits on the client. web_search already ran.
36 expect(result.clientToolRequests).toEqual(['toolu_pick'])
37​
38 // After the interrupt snapshot the client still shows one message.
39 expect(result.viewAfterInterrupt).toEqual([
40 ['thinking', 'tool-call', 'thinking', 'text', 'tool-call'],
41 ])
42 })
43})