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 test('RUN_ERROR rawEvent survives transport and reaches the consumer', async ({
32 page,
33 testId,
34 aimockPort,
35 }) => {
36 await selectScenario(page, 'error', testId, aimockPort)
37 await runTest(page)
38
39 await page.waitForFunction(
40 () =>
41 document
42 .querySelector('#test-metadata')
43 ?.getAttribute('data-has-error') === 'true',
44 { timeout: 10000 },
45 )
46
47 // The provider's structured error body forwarded as RUN_ERROR.rawEvent must
48 // survive SSE transport + the strip-to-spec middleware and be recoverable
49 // on the consumer-facing error.
50 const metadata = await getMetadata(page)
51 expect(metadata.errorRawEvent).not.toBe('')
52 expect(JSON.parse(metadata.errorRawEvent)).toEqual({
53 provider_name: 'test-provider',
54 raw: { reason: 'upstream overloaded' },
55 })
56 })
57
58 // Fixture loaded from fixtures/error/basic.json (static, shared across workers)
59 test('aimock error fixture returns error to client', async ({
60 page,
61 testId,
62 aimockPort,
63 }) => {
64 await page.goto(featureUrl('openai', 'chat', testId, aimockPort))
65
66 await sendMessage(page, '[error-test] trigger server error')
67
68 // Wait for loading to finish (error completes the stream)
69 await page.waitForTimeout(5000)
70
71 // Should not be loading
72 await expect(page.getByTestId('loading-indicator')).not.toBeVisible()
73
74 // Error response should not produce a normal assistant message with content
75 const assistantMsgs = page.getByTestId('assistant-message')
76 const count = await assistantMsgs.count()
77 if (count > 0) {
78 const text = await assistantMsgs.last().innerText()
79 expect(text).not.toContain('recommend')
80 expect(text).not.toContain('guitar')
81 }
82 })
83})