Open History to see the last commit
1import { test, expect } from '../fixtures'
2import {
3 selectScenario,
4 runTest,
5 waitForTestComplete,
6 getMetadata,
7 getEventLog,
8 getToolCalls,
9 getToolCallParts,
10} from './helpers'
11
12/**
13 * Continuation Re-execution — Tool Call Arguments E2E Tests
14 *
15 * These tests verify that tool call arguments are correctly preserved during
16 * continuation re-executions. When a client tool completes and the conversation
17 * continues, the server re-processes message history containing pending tool
18 * calls. Without emitting TOOL_CALL_START + TOOL_CALL_ARGS before
19 * TOOL_CALL_END, tool-call parts arrive at the client with empty
20 * arguments {}, potentially causing infinite re-execution loops.
21 */
22
23test.describe('Continuation Re-execution — Tool Call Arguments', () => {
24 test('single client tool arguments preserved after continuation', async ({
25 page,
26 testId,
27 aimockPort,
28 }) => {
29 await selectScenario(page, 'client-tool-single', testId, aimockPort)
30 await runTest(page)
31 await waitForTestComplete(page)
32
33 const metadata = await getMetadata(page)
34 expect(metadata.testComplete).toBe('true')
35 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(1)
36
37 const parts = await getToolCallParts(page)
38 expect(parts.length).toBeGreaterThanOrEqual(1)
39
40 const notificationCall = parts.find((tc) => tc.name === 'show_notification')
41 expect(notificationCall).toBeDefined()
42 expect(notificationCall?.arguments).toEqual({
43 message: 'Hello from the AI!',
44 type: 'info',
45 })
46 })
47
48 test('sequential client tool arguments preserved across multiple continuations', async ({
49 page,
50 testId,
51 aimockPort,
52 }) => {
53 await selectScenario(page, 'sequential-client-tools', testId, aimockPort)
54 await runTest(page)
55 await waitForTestComplete(page, 15000, 2)
56
57 // Wait for execution events to propagate
58 await page.waitForFunction(
59 () => {
60 const el = document.querySelector('#test-metadata')
61 return (
62 parseInt(el?.getAttribute('data-execution-complete-count') || '0') >=
63 2
64 )
65 },
66 { timeout: 10000 },
67 )
68
69 const metadata = await getMetadata(page)
70 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(2)
71
72 const parts = await getToolCallParts(page)
73 const notificationCalls = parts.filter(
74 (tc) => tc.name === 'show_notification',
75 )
76 expect(notificationCalls.length).toBeGreaterThanOrEqual(2)
77
78 // Both sets of arguments must be present (order may vary)
79 const allArgs = notificationCalls.map((tc) => tc.arguments)
80 expect(allArgs).toContainEqual({
81 message: 'First notification',
82 type: 'info',
83 })
84 expect(allArgs).toContainEqual({
85 message: 'Second notification',
86 type: 'warning',
87 })
88
89 // No tool call should have empty arguments
90 expect(
91 notificationCalls.every((tc) => Object.keys(tc.arguments).length > 0),
92 ).toBe(true)
93 })
94
95 test('parallel client tool arguments preserved in batch continuation', async ({
96 page,
97 testId,
98 aimockPort,
99 }) => {
100 await selectScenario(page, 'parallel-client-tools', testId, aimockPort)
101 await runTest(page)
102 await waitForTestComplete(page, 15000, 2)
103
104 const metadata = await getMetadata(page)
105 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(2)
106
107 const parts = await getToolCallParts(page)
108 expect(parts.length).toBeGreaterThanOrEqual(2)
109
110 const notificationCall = parts.find((tc) => tc.name === 'show_notification')
111 const chartCall = parts.find((tc) => tc.name === 'display_chart')
112
113 expect(notificationCall).toBeDefined()
114 expect(chartCall).toBeDefined()
115
116 expect(notificationCall?.arguments).toEqual({
117 message: 'Parallel 1',
118 type: 'info',
119 })
120 expect(chartCall?.arguments).toEqual({
121 type: 'bar',
122 data: [1, 2, 3],
123 })
124 })
125
126 test('mixed server and client tool arguments preserved in sequence', async ({
127 page,
128 testId,
129 aimockPort,
130 }) => {
131 // Server tool (fetch_data) followed by client tool (display_chart)
132 await selectScenario(page, 'sequence-server-client', testId, aimockPort)
133 await runTest(page)
134 await waitForTestComplete(page, 20000, 1)
135
136 const metadata = await getMetadata(page)
137 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(2)
138
139 const parts = await getToolCallParts(page)
140 expect(parts.length).toBeGreaterThanOrEqual(2)
141
142 const fetchCall = parts.find((tc) => tc.name === 'fetch_data')
143 const chartCall = parts.find((tc) => tc.name === 'display_chart')
144
145 expect(fetchCall).toBeDefined()
146 expect(chartCall).toBeDefined()
147
148 expect(fetchCall?.arguments).toEqual({ source: 'api' })
149 expect(chartCall?.arguments).toEqual({ type: 'bar', data: [1, 2, 3] })
150 })
151
152 // Screenshot on failure
153 test.afterEach(async ({ page }, testInfo) => {
154 if (testInfo.status !== testInfo.expectedStatus) {
155 await page.screenshot({
156 path: `test-results/continuation-args-failure-${testInfo.title.replace(/\s+/g, '-')}.png`,
157 fullPage: true,
158 })
159
160 const events = await getEventLog(page)
161 const toolCalls = await getToolCalls(page)
162 const metadata = await getMetadata(page)
163
164 console.log('Test failed. Debug info:')
165 console.log('Metadata:', metadata)
166 console.log('Events:', events)
167 console.log('Tool calls:', toolCalls)
168 }
169 })
170})