Open History to see the last commit
1import { test, expect } from './fixtures'
2import type { Page } from '@playwright/test'
3
4/** Click Run once the page hydrated. A click before hydration does nothing. */
5async function run(page: Page) {
6 await page.waitForLoadState('networkidle')
7 await expect(async () => {
8 await page.getByTestId('run').click()
9 await expect(page.getByTestId('message-count')).not.toHaveText('0', {
10 timeout: 2_000,
11 })
12 }).toPass({ timeout: 15_000 })
13}
14
15function open(
16 page: Page,
17 scenario: 'route' | 'approval' | 'tool' | 'brief',
18 testId: string,
19 aimockPort: number,
20) {
21 return page.goto(
22 `/subagents-test?scenario=${scenario}&testId=${encodeURIComponent(testId)}&aimockPort=${aimockPort}`,
23 )
24}
25
26test.describe('subagents', () => {
27 test('a routed child keeps its reasoning, tool call, and reply on its card', async ({
28 page,
29 testId,
30 aimockPort,
31 }) => {
32 await open(page, 'route', testId, aimockPort)
33 await run(page)
34
35 await expect(page.getByTestId('card-status-researcher')).toHaveText(
36 'finished',
37 )
38 const card = page.getByTestId('card-researcher')
39 await expect(card).toContainText('thinking:Look up the facts first.')
40 await expect(card).toContainText('tool:lookupFacts')
41 await expect(card).toContainText('result:')
42 await expect(card).toContainText('text:Squids have three hearts.')
43 // Nothing from the child lands on the parent message.
44 await expect(page.getByTestId('parent-part-types')).toHaveText('subagent')
45 })
46
47 test('a child approval pauses the run, then the same child finishes', async ({
48 page,
49 testId,
50 aimockPort,
51 }) => {
52 await open(page, 'approval', testId, aimockPort)
53 await run(page)
54
55 await expect(page.getByTestId('card-status-cleaner')).toHaveText(
56 'suspended',
57 )
58 await expect(page.getByTestId('card-cleaner')).toContainText(
59 'tool:deleteLogs:approval-requested',
60 )
61
62 await page.getByTestId('approve-deleteLogs').click()
63
64 await expect(page.getByTestId('card-status-cleaner')).toHaveText('finished')
65 const card = page.getByTestId('card-cleaner')
66 await expect(card).toContainText('result:')
67 await expect(card).toContainText('text:Deleted the old logs.')
68 await expect(page.getByTestId('approve-deleteLogs')).toHaveCount(0)
69 // One card: the resume continued the same child.
70 await expect(page.getByTestId('card-cleaner')).toHaveCount(1)
71 })
72
73 test('a card overrides the kit widgets for its own parts', async ({
74 page,
75 testId,
76 aimockPort,
77 }) => {
78 await page.goto(
79 `/subagents-ui-test?testId=${encodeURIComponent(testId)}&aimockPort=${aimockPort}`,
80 )
81 await run(page)
82
83 const card = page.getByTestId('card-researcher')
84 await expect(card.getByTestId('root-text')).toHaveText(
85 'Squids have three hearts.',
86 )
87 // The card's own thinking widget, not the root one.
88 await expect(card.getByTestId('card-thinking')).toHaveText(
89 'Look up the facts first.',
90 )
91 await expect(card.getByTestId('root-thinking')).toHaveCount(0)
92 // No card override for the tool, so the root widget renders it.
93 await expect(card.getByTestId('root-tool')).toContainText('lookupFacts:')
94 })
95
96 test('without a router the model starts the child and reads its result', async ({
97 page,
98 testId,
99 aimockPort,
100 }) => {
101 await open(page, 'tool', testId, aimockPort)
102 await run(page)
103
104 await expect(page.getByTestId('parent-text')).toHaveText(
105 'Research is done.',
106 )
107 await expect(page.getByTestId('card-status-researcher')).toHaveText(
108 'finished',
109 )
110 await expect(page.getByTestId('card-researcher')).toContainText(
111 'text:Squids have three hearts.',
112 )
113 })
114
115 test('the parent model writes the brief the child runs on', async ({
116 page,
117 testId,
118 aimockPort,
119 }) => {
120 await open(page, 'brief', testId, aimockPort)
121 await run(page)
122
123 await expect(page.getByTestId('parent-text')).toHaveText(
124 'The comparison is ready.',
125 )
126 await expect(page.getByTestId('card-status-researcher')).toHaveText(
127 'finished',
128 )
129 // The child's fixture matches only the brief. A child that got the
130 // transcript instead would get no reply.
131 await expect(page.getByTestId('card-researcher')).toContainText(
132 'text:Squids have three hearts and blue blood.',
133 )
134 })
135})