Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * Claude encrypts some thinking as a `redacted_thinking` block with opaque
5 * `data`. The next request must send that block back unchanged, and a failed
6 * tool result must say `is_error: true`.
7 * `/api/anthropic-redacted-thinking-wire` scripts the responses and returns
8 * what the follow-up requests sent.
9 */
10test.describe('anthropic — redacted thinking and tool errors on the wire', () => {
11 test('the next turn, the same run, and a failed tool send them back', async ({
12 request,
13 }) => {
14 const response = await request.post('/api/anthropic-redacted-thinking-wire')
15 expect(response.ok()).toBe(true)
16 const result = (await response.json()) as {
17 ok: boolean
18 error?: string
19 nextTurnBlocks: Array<Record<string, unknown>>
20 sameRunBlocks: Array<string>
21 toolResult?: Record<string, unknown>
22 }
23 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
24
25 // A new turn from the client history: the block crossed the wire.
26 expect(result.nextTurnBlocks).toEqual([
27 { type: 'redacted_thinking', data: 'opaque-1' },
28 { type: 'text', text: 'Hello.' },
29 ])
30
31 // The same run continues after the tool, with the block first.
32 expect(result.sameRunBlocks).toEqual(['redacted_thinking', 'tool_use'])
33
34 // The failed tool is marked as an error.
35 expect(result.toolResult).toMatchObject({
36 tool_use_id: 'toolu_1',
37 is_error: true,
38 })
39 })
40})