Open History to see the last commit
1import { expect, test } from '@playwright/test'
2import { sendMessage, waitForResponse } from './helpers'
3
4/**
5 * AG-UI activity is frontend-only (issue #1286). Live ACTIVITY_SNAPSHOT /
6 * ACTIVITY_DELTA must show up as `role: 'activity'`, a MESSAGES_SNAPSHOT
7 * ActivityMessage must hydrate the same way, and the next send must not put
8 * that row back into model input.
9 *
10 * Provider-free: `/api/activity-test` streams a fixed AG-UI sequence.
11 */
12
13test.describe('AG-UI activity', () => {
14 test('live snapshot and delta surface a patched activity row', async ({
15 page,
16 }) => {
17 await page.goto('/activity-test')
18
19 await sendMessage(page, '[activity] search')
20 await waitForResponse(page)
21
22 const activity = page.getByTestId('activity-message')
23 await expect(activity).toHaveCount(1)
24 await expect(activity).toHaveAttribute('data-activity-id', 'act-e2e-1')
25 await expect(activity).toHaveAttribute('data-activity-type', 'SEARCH')
26 await expect(page.getByTestId('activity-content')).toHaveText(
27 JSON.stringify({
28 query: 'e2e-activity-needle',
29 status: 'done',
30 hits: 3,
31 }),
32 )
33 await expect(page.getByTestId('assistant-message')).toContainText(
34 'ACTIVITY_FOUND',
35 )
36 })
37
38 test('the next turn does not send activity as model input', async ({
39 page,
40 }) => {
41 await page.goto('/activity-test')
42
43 await sendMessage(page, '[activity] search')
44 await waitForResponse(page)
45 await expect(page.getByTestId('activity-message')).toHaveCount(1)
46
47 await sendMessage(page, '[activity] again')
48 await waitForResponse(page)
49
50 await expect(page.getByTestId('activity-message')).toHaveCount(1)
51 await expect(page.getByTestId('assistant-message').last()).toContainText(
52 'ACTIVITY_CLEAN',
53 )
54 })
55
56 test('MESSAGES_SNAPSHOT hydrates an ActivityMessage', async ({ page }) => {
57 await page.goto('/activity-test?mode=snapshot')
58
59 await sendMessage(page, '[activity] hydrate')
60 await waitForResponse(page)
61
62 const activity = page.getByTestId('activity-message')
63 await expect(activity).toHaveCount(1)
64 await expect(activity).toHaveAttribute('data-activity-id', 'act-e2e-1')
65 await expect(activity).toHaveAttribute('data-activity-type', 'SEARCH')
66 await expect(page.getByTestId('activity-content')).toHaveText(
67 JSON.stringify({
68 query: 'e2e-activity-needle',
69 status: 'done',
70 hits: 3,
71 }),
72 )
73 await expect(page.getByTestId('assistant-message')).toContainText(
74 'ACTIVITY_FOUND',
75 )
76 })
77})
78
79test.describe('AG-UI activity reconstruct', () => {
80 test('reconstructChat interleaves stored activity from ActivityStore', async ({
81 request,
82 }) => {
83 const threadId = `activity-${crypto.randomUUID()}`
84 const runId = crypto.randomUUID()
85 const run = await request.post('/api/activity-test?mode=persist', {
86 data: { threadId, runId },
87 })
88 expect(run.ok()).toBe(true)
89
90 const hydration = await request.get(
91 `/api/activity-test?threadId=${threadId}`,
92 )
93 expect(hydration.ok()).toBe(true)
94 const body = (await hydration.json()) as {
95 messages: Array<{
96 role: string
97 parts: Array<Record<string, unknown>>
98 }>
99 }
100 expect(body.messages.map((message) => message.role)).toEqual([
101 'user',
102 'activity',
103 'assistant',
104 ])
105 expect(body.messages[1]?.parts).toEqual([
106 {
107 type: 'activity',
108 activityType: 'SEARCH',
109 content: {
110 query: 'e2e-activity-needle',
111 status: 'done',
112 hits: 3,
113 },
114 },
115 ])
116 })
117})