Open History to see the last commit
1import { test, expect } from './fixtures'
2import { selectScenario, runTest, getMetadata } from './tools-test/helpers'
3import { sendMessage, featureUrl } from './helpers'
4
5test.describe('Error Handling', () => {
6 test('displays error when server returns RUN_ERROR', async ({
7 page,
8 testId,
9 aimockPort,
10 }) => {
11 await selectScenario(page, 'error', testId, aimockPort)
12 await runTest(page)
13
14 // Wait for error to appear
15 await page.waitForFunction(
16 () =>
17 document
18 .querySelector('#test-metadata')
19 ?.getAttribute('data-has-error') === 'true',
20 { timeout: 10000 },
21 )
22
23 const metadata = await getMetadata(page)
24 expect(metadata.hasError).toBe('true')
25 expect(metadata.isLoading).toBe('false')
26
27 // Error should be visible in UI
28 await expect(page.locator('#error-display')).toBeVisible()
29 })
30
31 // Fixture loaded from fixtures/error/basic.json (static, shared across workers)
32 test('aimock error fixture returns error to client', async ({
33 page,
34 testId,
35 aimockPort,
36 }) => {
37 await page.goto(featureUrl('openai', 'chat', testId, aimockPort))
38
39 await sendMessage(page, '[error-test] trigger server error')
40
41 // Wait for loading to finish (error completes the stream)
42 await page.waitForTimeout(5000)
43
44 // Should not be loading
45 await expect(page.getByTestId('loading-indicator')).not.toBeVisible()
46
47 // Error response should not produce a normal assistant message with content
48 const assistantMsgs = page.getByTestId('assistant-message')
49 const count = await assistantMsgs.count()
50 if (count > 0) {
51 const text = await assistantMsgs.last().innerText()
52 expect(text).not.toContain('recommend')
53 expect(text).not.toContain('guitar')
54 }
55 })
56})