Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

foreign-chunk-events.spec.ts

37 lines1.4 KB

1import { expect, test } from '@playwright/test'
2​
3/**
4 * An AG-UI producer may send TEXT_MESSAGE_CHUNK, TOOL_CALL_CHUNK and
5 * REASONING_MESSAGE_CHUNK in place of the START / CONTENT / END events
6 * (issue #1531). useChat must build the same message from them.
7 */
8test.describe('AG-UI *_CHUNK events from a foreign server', () => {
9 test('a turn sent as chunks keeps its reasoning, tool call and text', async ({
10 page,
11 }) => {
12 await page.goto('/foreign-chunk-events?case=turn')
13​
14 const message = page.getByTestId('message-msg-chunked')
15 await expect(message.getByTestId('text')).toHaveText('It is sunny in Kyiv.')
16 await expect(message.getByTestId('thinking')).toHaveText(
17 'Look up the weather.',
18 )
19 await expect(message.getByTestId('tool-call-get_weather')).toHaveText(
20 '{"city":"Kyiv"} -> "sunny"',
21 )
22 await expect(page.getByTestId('assistant-ids')).toHaveText('msg-chunked')
23 })
24​
25 test('a chunk before RUN_ERROR keeps its text, id and metadata', async ({
26 page,
27 }) => {
28 await page.goto('/foreign-chunk-events?case=error')
29​
30 const message = page.getByTestId('message-msg-error')
31 await expect(message.getByTestId('text')).toHaveText('the run failed')
32 // RUN_ERROR marks the message as failed, so the next request leaves it out.
33 await expect(message.getByTestId('metadata')).toHaveText(
34 '{"error":"upstream timeout","tanstack":{"stopReason":"error"}}',
35 )
36 })
37})