Open History to see the last commit
1import { test, expect } from './fixtures'
2import { sendMessage, waitForResponse } from './helpers'
3import {
4 closeDevtools,
5 devtoolsUrl,
6 expectClassChangesOnHover,
7 hookRow,
8 openDevtools,
9 selectHook,
10 waitForDevtoolsHarness,
11} from './devtools-helpers'
12
13test.beforeEach(async ({ page }) => {
14 await page.addInitScript(() => localStorage.clear())
15})
16
17test('chat devtools shows user-visible conversation state and clears activity after viewing', async ({
18 page,
19 testId,
20 aimockPort,
21}) => {
22 await page.goto(devtoolsUrl('/devtools-chat', testId, aimockPort))
23 await openDevtools(page)
24 await expect(page.getByText(/\d+ new/)).toHaveCount(0)
25 await closeDevtools(page)
26
27 await sendMessage(page, '[chat] recommend a guitar')
28 await waitForResponse(page)
29 await expect(page.getByTestId('assistant-message')).toContainText(
30 'Fender Stratocaster',
31 )
32
33 await openDevtools(page)
34 await expect(hookRow(page, 'Support Chat')).toContainText('new')
35 await selectHook(page, 'Support Chat')
36 await expect(hookRow(page, 'Support Chat')).not.toContainText('new')
37 await expect(page.getByTestId('ai-devtools-hook-tab')).toContainText([
38 'Conversation',
39 'Tools',
40 'State',
41 ])
42 await expect(
43 page.getByTestId('ai-devtools-hook-metric-messages'),
44 ).toBeVisible()
45 await expect(page.getByTestId('ai-devtools-hook-metric-tokens')).toBeVisible()
46 await expect(page.getByTestId('ai-devtools-timeline-message')).toHaveCount(2)
47 await expect(page.getByTestId('ai-devtools-preview-message')).toHaveCount(2)
48 await expect(
49 page.getByTestId('ai-devtools-preview-message').filter({ hasText: 'user' }),
50 ).toContainText('[chat] recommend a guitar')
51 await expect(
52 page
53 .getByTestId('ai-devtools-preview-message')
54 .filter({ hasText: 'assistant' }),
55 ).toContainText('Fender Stratocaster')
56
57 await expectClassChangesOnHover(
58 page.getByTestId('ai-devtools-timeline-message').first(),
59 page.getByTestId('ai-devtools-preview-message').first(),
60 )
61 await expectClassChangesOnHover(
62 page.getByTestId('ai-devtools-preview-message').last(),
63 page.getByTestId('ai-devtools-timeline-message').last(),
64 )
65})
66
67test('structured useChat renders streaming raw and parsed data without duplicate user-view pane', async ({
68 page,
69 testId,
70 aimockPort,
71}) => {
72 await page.goto(devtoolsUrl('/devtools-structured', testId, aimockPort))
73 await waitForDevtoolsHarness(page)
74 await sendMessage(page, '[structured-stream] recommend a guitar as json')
75 await waitForResponse(page)
76 await expect(page.getByTestId('content-delta-count')).toHaveAttribute(
77 'data-count',
78 /[1-9]\d*/,
79 )
80 await expect(page.getByTestId('structured-partial-json')).toContainText(
81 'Fender Stratocaster',
82 )
83
84 await openDevtools(page)
85 await selectHook(page, 'Structured Recommendation')
86 await expect(page.getByTestId('ai-devtools-hook-technical-name')).toHaveText(
87 'useChat',
88 )
89 await expect(page.getByTestId('ai-devtools-hook-title')).toHaveText(
90 'Structured Recommendation',
91 )
92 await expect(page.getByTestId('ai-devtools-preview-pane')).toHaveCount(0)
93 await expect(
94 page
95 .getByTestId('ai-devtools-timeline-part')
96 .filter({ hasText: 'structured' }),
97 ).toContainText('Fender Stratocaster')
98})