Open History to see the last commit
1import { test, expect } from './fixtures'
2
3/**
4 * Issue #613: on the #605 native combined path the structured JSON lands on a
5 * `structured-output` part, not a text part, so the assistant turn reaches the
6 * next request only while a completed part is re-serialized as content. Lose
7 * that and the turn goes out empty — which only Anthropic shows, because
8 * `mergeConsecutiveSameRoleMessages` filters the empty turn and merges the two
9 * user turns left adjacent. aimock then matches turn 1's fixture on the merged
10 * prompt and replays the first recipe; OpenAI keeps the empty turn, so its
11 * last user message is still turn 2's prompt and nothing looks wrong.
12 *
13 * `multi-turn-structured.spec.ts` covers the rendered outcome. This pins the
14 * cause, so the next regression says so instead of "turn 2 shows turn 1's
15 * recipe".
16 */
17test.describe('anthropic — multi-turn structured wire shape', () => {
18 test('the second turn keeps the first recipe on its own assistant turn', async ({
19 request,
20 }) => {
21 const response = await request.post(
22 '/api/anthropic-multi-turn-structured-wire',
23 )
24 expect(response.ok()).toBe(true)
25 const result = (await response.json()) as {
26 ok: boolean
27 error?: string
28 requestBodies: Array<{
29 messages: Array<{ role: string; content: unknown }>
30 output_config?: { format?: { type?: string } }
31 }>
32 }
33 if (!result.ok) throw new Error(`Route failed: ${result.error}`)
34
35 expect(result.requestBodies).toHaveLength(2)
36 const [firstRequest, secondRequest] = result.requestBodies
37
38 expect(firstRequest!.messages.map((m) => m.role)).toEqual(['user'])
39 // Guards the premise: without `output_config` the JSON would come back as
40 // plain text and a text part would satisfy the round trip anyway.
41 expect(secondRequest!.output_config?.format?.type).toBe('json_schema')
42
43 // A merged pair of user turns here means the assistant turn went out empty.
44 const replayed = secondRequest!.messages
45 expect(replayed.map((m) => m.role)).toEqual(['user', 'assistant', 'user'])
46 expect(JSON.stringify(replayed[0])).toContain(
47 '[multiturn-structured-wire-1] pasta dinner for two',
48 )
49 // The model sees its own prior answer, verbatim.
50 expect(JSON.stringify(replayed[1])).toContain('Classic Spaghetti Pomodoro')
51 expect(JSON.stringify(replayed[2])).toContain(
52 '[multiturn-structured-wire-2] now make it vegan',
53 )
54 expect(JSON.stringify(replayed[2])).not.toContain('pasta dinner for two')
55 })
56})