-
Notifications
You must be signed in to change notification settings - Fork 670
Expand file tree
/
Copy pathagentPanel.spec.ts
More file actions
270 lines (225 loc) · 8.95 KB
/
Copy pathagentPanel.spec.ts
File metadata and controls
270 lines (225 loc) · 8.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import type { WebSocketRoute } from '@playwright/test'
import { expect, mergeTests } from '@playwright/test'
import { webSocketFixture } from '@e2e/fixtures/ws'
import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { AgentWsEvent } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import {
DRAFT_PATCH,
INTERMEDIATE_MESSAGE_EVENT,
MESSAGE_DELTA_EVENT,
MESSAGE_DONE_EVENT,
OPEN_TAB_TOOL_EVENT,
RESIZE_IMAGE_TOOL_EVENT,
RESUMED_THINKING_EVENT,
THINKING_EVENT,
THINKING_TEXT,
TOOL_CALL_EVENT,
agentTest
} from '@e2e/tests/agent/agentPanelMocks'
const test = mergeTests(agentTest, webSocketFixture)
const OPEN_AGENT_LABEL = enMessages.agent.askComfyAgent
function pushEvent(ws: WebSocketRoute, event: AgentWsEvent): void {
ws.send(JSON.stringify(event))
}
test.describe('In-App Agent panel', { tag: '@cloud' }, () => {
test.use({ connectWebSocketToServer: false })
test.describe('flag off', () => {
test.use({ agentFlagEnabled: false })
test('does not expose the Ask Comfy Agent button', async ({
comfyPage,
postedMessages
}) => {
expect(postedMessages).toHaveLength(0)
await expect(
comfyPage.page.getByRole('button', { name: OPEN_AGENT_LABEL })
).toHaveCount(0)
})
})
test('shows the greeting, inserts a suggested prompt, and completes a chat turn', async ({
comfyPage,
postedMessages,
getWebSocket
}) => {
test.setTimeout(30_000)
const page = comfyPage.page
const openButton = page.getByRole('button', { name: OPEN_AGENT_LABEL })
await expect(openButton).toBeVisible()
await openButton.click()
const panel = page.locator('#agent-panel-root')
await expect(panel).toBeVisible()
await expect(panel.getByText(/^Hello/)).toBeVisible()
await expect(panel.getByText('What do you want to make?')).toBeVisible()
const firstPrompt = enMessages.agent.suggestedPrompts[0]
const promptChip = panel.getByRole('button', { name: firstPrompt })
await expect(promptChip).toBeVisible()
const composer = panel.getByRole('textbox', { name: /^Describe ideas/ })
const sendButton = panel.getByRole('button', { name: 'Send' })
await expect(composer).toHaveValue('')
await promptChip.click()
await expect(composer).toHaveValue(firstPrompt)
expect(
postedMessages,
'inserting a prompt must not POST a message'
).toHaveLength(0)
const ws = await getWebSocket()
await sendButton.click()
await expect.poll(() => postedMessages.length).toBeGreaterThanOrEqual(1)
expect(postedMessages[0]).toContain(firstPrompt)
await expect(composer).toHaveValue('')
pushEvent(ws, THINKING_EVENT)
await expect(panel.getByText(THINKING_TEXT)).toBeVisible()
pushEvent(ws, TOOL_CALL_EVENT)
const firstSummary = panel.getByRole('button', {
name: 'Ran 1 tool call for 1.3 seconds'
})
await expect(firstSummary).toBeVisible()
await expect(firstSummary).toHaveAttribute('aria-expanded', 'true')
await expect(panel.getByText('Set widget')).toBeVisible()
await expect(panel.getByText(THINKING_TEXT)).toBeHidden()
pushEvent(ws, INTERMEDIATE_MESSAGE_EVENT)
await expect(
panel.getByText(
'The first graph edit is complete. I will check the remaining work.'
)
).toBeVisible()
await expect(firstSummary).toHaveAttribute('aria-expanded', 'true')
await expect(panel.getByText('Set widget')).toBeVisible()
pushEvent(ws, RESUMED_THINKING_EVENT)
await expect(
panel.getByText('Checking the remaining edits.', { exact: true })
).toBeVisible()
pushEvent(ws, OPEN_TAB_TOOL_EVENT)
const secondSummary = panel.getByRole('button', {
name: 'Ran 1 tool call for 0.5 seconds'
})
await expect(secondSummary).toBeVisible()
await expect(firstSummary).toHaveAttribute('aria-expanded', 'true')
await expect(panel.getByText('Set widget')).toBeVisible()
await expect(
panel.getByText('Checking the remaining edits.', { exact: true })
).toHaveCount(0)
pushEvent(ws, RESIZE_IMAGE_TOOL_EVENT)
const finalSummary = panel.getByRole('button', {
name: 'Ran 2 tool calls for 0.7 seconds'
})
await expect(finalSummary).toBeVisible()
await expect(finalSummary).toHaveAttribute('aria-expanded', 'true')
await expect(
panel.getByRole('button', {
name: /^Ran \d+ tool calls?(?: for \d+(?:\.\d+)? seconds)?$/
})
).toHaveCount(2)
await expect(firstSummary).toHaveCount(1)
await expect(secondSummary).toHaveCount(0)
const toolRows = panel.getByRole('listitem')
await expect(toolRows).toHaveCount(3)
await expect(toolRows.filter({ hasText: 'Set widget' })).toBeVisible()
await expect(
toolRows.filter({ hasText: 'Opened a new tab' }).getByText('0.5s')
).toBeVisible()
await expect(
toolRows.filter({ hasText: 'Resize image node' }).getByText('0.2s')
).toBeVisible()
pushEvent(ws, MESSAGE_DELTA_EVENT)
await expect(
panel.locator('strong', { hasText: 'fully ready' })
).toBeVisible()
pushEvent(ws, RESUMED_THINKING_EVENT)
await expect(
panel.getByText('Checking the remaining edits.', { exact: true })
).toBeVisible()
await expect(finalSummary).toHaveAttribute('aria-expanded', 'true')
await expect(firstSummary).toHaveAttribute('aria-expanded', 'true')
await expect(panel.getByText('Opened a new tab')).toBeVisible()
pushEvent(ws, MESSAGE_DONE_EVENT)
await expect(panel.getByRole('button', { name: 'Send' })).toBeVisible()
await expect(panel.getByRole('button', { name: 'Stop' })).toHaveCount(0)
await expect(
panel.getByRole('button', { name: /ran 2 tool calls/i })
).toHaveAttribute('aria-expanded', 'false')
await expect(firstSummary).toHaveAttribute('aria-expanded', 'false')
})
test('keeps the Agent scrollbar track transparent', async ({ comfyPage }) => {
const page = comfyPage.page
await page.getByRole('button', { name: OPEN_AGENT_LABEL }).click()
const scrollContainer = page
.locator('#agent-panel-root div.overflow-y-auto')
.first()
await expect(scrollContainer).toBeVisible()
const track = await scrollContainer.evaluate((element) => ({
backgroundColor: getComputedStyle(element, '::-webkit-scrollbar-track')
.backgroundColor,
backgroundImage: getComputedStyle(element, '::-webkit-scrollbar-track')
.backgroundImage,
scrollbarColor: getComputedStyle(element).scrollbarColor
}))
expect(track.backgroundColor).toBe('rgba(0, 0, 0, 0)')
expect(track.backgroundImage).toBe('none')
expect(track.scrollbarColor).toMatch(/rgba\(0, 0, 0, 0\)$/)
})
test('sizes the add-to-prompt menu around its longest item', async ({
comfyPage
}) => {
const page = comfyPage.page
await page.getByRole('button', { name: OPEN_AGENT_LABEL }).click()
const panel = page.locator('#agent-panel-root')
await panel
.getByRole('button', { name: enMessages.agent.addToPrompt })
.click()
const menu = page.getByRole('menu')
const longestItem = menu.getByRole('menuitem', {
name: enMessages.agent.addFromAssets
})
const icon = longestItem.locator('span').first()
const label = longestItem.getByText(enMessages.agent.addFromAssets, {
exact: true
})
await expect(longestItem).toBeVisible()
await expect
.poll(() => menu.boundingBox().then((box) => box?.width))
.toBeGreaterThan(186)
await expect
.poll(async () => {
const [itemBox, iconBox, labelBox] = await Promise.all([
longestItem.boundingBox(),
icon.boundingBox(),
label.boundingBox()
])
if (!itemBox || !iconBox || !labelBox) return Number.POSITIVE_INFINITY
const leftInset = iconBox.x - itemBox.x
const rightInset =
itemBox.x + itemBox.width - (labelBox.x + labelBox.width)
return Math.abs(leftInset - rightInset)
})
.toBeLessThanOrEqual(1)
})
test('applies a draft_patch graph to the canvas', async ({
comfyPage,
postedMessages,
getWebSocket
}) => {
test.setTimeout(30_000)
const page = comfyPage.page
const panel = page.locator('#agent-panel-root')
const openButton = page.getByRole('button', { name: OPEN_AGENT_LABEL })
await expect(openButton).toBeVisible()
await openButton.click()
await expect(panel).toBeVisible()
await panel
.getByRole('textbox', { name: /^Describe ideas/ })
.fill('Build it')
await panel.getByRole('button', { name: 'Send' }).click()
await expect.poll(() => postedMessages.length).toBeGreaterThanOrEqual(1)
const ws = await getWebSocket()
pushEvent(ws, { type: 'draft_patch', data: DRAFT_PATCH })
await expect
.poll(() => page.evaluate(() => window.app!.graph!.nodes.length))
.toBe(2)
const nodeTypes = await page.evaluate(() =>
window.app!.graph!.nodes.map((n) => n.type)
)
expect(nodeTypes).toEqual(
expect.arrayContaining(['CheckpointLoaderSimple', 'SaveImage'])
)
})
})