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

cross-model-replay-wire.spec.ts

56 lines1.9 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * A conversation that starts on Claude and goes on with OpenAI. Claude's
5 * signed thinking and tool call must reach OpenAI as plain text and paired
6 * tool rows, never as a Claude signature.
7 * `/api/cross-model-replay-wire` scripts both providers and returns what the
8 * OpenAI request held.
9 */
10test.describe('cross-model replay — Claude history sent to OpenAI', () => {
11 test('drops the signature, keeps the thinking as text, and pairs the tool rows', async ({
12 request,
13 }) => {
14 const response = await request.post('/api/cross-model-replay-wire')
15 expect(response.ok()).toBe(true)
16 const result = (await response.json()) as {
17 ok: boolean
18 error?: string
19 claudeSources: Array<{ provider: string; api: string; model: string }>
20 openaiCalls: number
21 hasSignature: boolean
22 hasThinkingText: boolean
23 toolCallIds: Array<string>
24 toolResultIds: Array<string>
25 roles: Array<string>
26 }
27 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
28​
29 // Each Claude answer records where it came from.
30 expect(result.claudeSources.length).toBeGreaterThan(0)
31 for (const source of result.claudeSources) {
32 expect(source).toEqual({
33 provider: 'anthropic',
34 api: 'anthropic-messages',
35 model: 'claude-sonnet-4-5',
36 })
37 }
38​
39 // OpenAI gets the history without Claude's signature. The thinking is
40 // readable, so it goes on as text.
41 expect(result.openaiCalls).toBe(1)
42 expect(result.hasSignature).toBe(false)
43 expect(result.hasThinkingText).toBe(true)
44​
45 // The tool call and its result keep the same ID.
46 expect(result.toolCallIds).toHaveLength(1)
47 expect(result.toolResultIds).toEqual(result.toolCallIds)
48 expect(result.roles).toEqual([
49 'user',
50 'assistant',
51 'tool',
52 'assistant',
53 'user',
54 ])
55 })
56})