Open History to see the last commit
1import { expect, test } from '@playwright/test'
2import { sendMessage } from './helpers'
3
4test('renders typed tools and interrupts once', async ({ page }) => {
5 await page.goto('/headless-ui')
6 await sendMessage(page, 'Purchase one keyboard')
7
8 await expect(page.getByTestId('purchase-tool')).toHaveCount(1)
9 await expect(page.getByTestId('purchase-approval')).toHaveCount(1)
10 await expect(page.getByTestId('standalone-tool-result')).toHaveCount(1)
11
12 await page.getByRole('button', { name: 'Approve purchase' }).click()
13 await expect(page.getByTestId('purchase-output')).toContainText('approved')
14})
15
16test('keeps the Parts subtree mounted while a message streams', async ({
17 page,
18}) => {
19 await page.goto('/headless-ui')
20 await sendMessage(page, 'Purchase one keyboard')
21
22 const tool = page.getByTestId('purchase-tool')
23 await expect(tool).toHaveCount(1)
24
25 // The run delivers the tool call across several chunks (start, args, end),
26 // so this widget re-renders each time. `message` receives one stable `Parts`
27 // component, so the subtree survives; a `Parts` rebuilt per render would
28 // remount it and push the mount sequence past 1.
29 await expect(tool).toHaveAttribute('data-mount-seq', '1')
30
31 await page.getByRole('button', { name: 'Approve purchase' }).click()
32 await expect(page.getByTestId('purchase-output')).toContainText('approved')
33
34 // Resuming after the approval streams more chunks into the same message.
35 await expect(tool).toHaveAttribute('data-mount-seq', '1')
36})