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} from './helpers'
10
11/**
12 * Chat Flow E2E Tests — tools-test page
13 *
14 * These tests verify basic text and tool-call scenarios using the /tools-test
15 * page and its /api/tools-test backend.
16 */
17
18test.describe('Chat Flow Tests (tools-test page)', () => {
19 test('text-only scenario completes without tool calls', async ({
20 page,
21 testId,
22 aimockPort,
23 }) => {
24 await selectScenario(page, 'text-only', testId, aimockPort)
25 await runTest(page)
26
27 // Wait for loading to finish
28 await page.waitForFunction(
29 () => {
30 const metadata = document.getElementById('test-metadata')
31 return metadata?.getAttribute('data-is-loading') === 'false'
32 },
33 { timeout: 15000 },
34 )
35
36 // Give it a moment to settle
37 await page.waitForTimeout(500)
38
39 // Verify no tool calls
40 const metadata = await getMetadata(page)
41 expect(parseInt(metadata.toolCallCount)).toBe(0)
42 expect(parseInt(metadata.completeToolCount)).toBe(0)
43 })
44
45 test('text-only scenario shows response in messages JSON', async ({
46 page,
47 testId,
48 aimockPort,
49 }) => {
50 await selectScenario(page, 'text-only', testId, aimockPort)
51 await runTest(page)
52
53 // Wait for loading to finish
54 await page.waitForFunction(
55 () => {
56 const metadata = document.getElementById('test-metadata')
57 return metadata?.getAttribute('data-is-loading') === 'false'
58 },
59 { timeout: 15000 },
60 )
61
62 await page.waitForTimeout(500)
63
64 // The messages JSON should be populated
65 const messagesJson = await page
66 .locator('#messages-json-content')
67 .textContent()
68 const messages = JSON.parse(messagesJson || '[]')
69
70 // Should have at least one message (user + assistant)
71 expect(messages.length).toBeGreaterThanOrEqual(1)
72 })
73
74 test('single server tool scenario triggers a tool call', async ({
75 page,
76 testId,
77 aimockPort,
78 }) => {
79 await selectScenario(page, 'server-tool-single', testId, aimockPort)
80 await runTest(page)
81
82 await waitForTestComplete(page, 15000, 1)
83
84 const metadata = await getMetadata(page)
85 expect(metadata.testComplete).toBe('true')
86 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(1)
87 expect(parseInt(metadata.completeToolCount)).toBeGreaterThanOrEqual(1)
88 })
89
90 test('single client tool triggers execution events', async ({
91 page,
92 testId,
93 aimockPort,
94 }) => {
95 await selectScenario(page, 'client-tool-single', testId, aimockPort)
96 await runTest(page)
97
98 await waitForTestComplete(page, 15000, 1)
99
100 const metadata = await getMetadata(page)
101 expect(metadata.testComplete).toBe('true')
102 expect(parseInt(metadata.toolCallCount)).toBeGreaterThanOrEqual(1)
103
104 // Verify client tool execution events were recorded
105 const events = await getEventLog(page)
106 const startEvents = events.filter((e) => e.type === 'execution-start')
107 const completeEvents = events.filter((e) => e.type === 'execution-complete')
108
109 expect(startEvents.length).toBeGreaterThanOrEqual(1)
110 expect(completeEvents.length).toBeGreaterThanOrEqual(1)
111 })
112
113 test('tool calls appear in tool-calls JSON', async ({
114 page,
115 testId,
116 aimockPort,
117 }) => {
118 await selectScenario(page, 'server-tool-single', testId, aimockPort)
119 await runTest(page)
120
121 await waitForTestComplete(page, 15000, 1)
122
123 const toolCalls = await getToolCalls(page)
124 expect(toolCalls.length).toBeGreaterThanOrEqual(1)
125 // Each entry should have id, name, state
126 expect(toolCalls[0]).toHaveProperty('id')
127 expect(toolCalls[0]).toHaveProperty('name')
128 expect(toolCalls[0]).toHaveProperty('state')
129 })
130
131 // Screenshot on failure
132 test.afterEach(async ({ page }, testInfo) => {
133 if (testInfo.status !== testInfo.expectedStatus) {
134 await page.screenshot({
135 path: `test-results/chat-flow-failure-${testInfo.title.replace(/\s+/g, '-')}.png`,
136 fullPage: true,
137 })
138
139 const events = await getEventLog(page)
140 const metadata = await getMetadata(page)
141
142 console.log('Test failed. Debug info:')
143 console.log('Metadata:', metadata)
144 console.log('Events:', events)
145 }
146 })
147})