Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ async function setUpFixture(page: Page) {
await test.step('open the agent panel and target the workflow', async () => {
await loadSeedIntoActiveTab(page, seed)
await new AgentPanel(page).open()
await expect(panel).toBeVisible()
await panel
.getByRole('button', { name: enMessages.agent.switchWorkflow })
.click()
Expand Down
3 changes: 1 addition & 2 deletions browser_tests/fixtures/agentConversationFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ export class AgentConversationHarness {
)

await loadSeedIntoActiveTab(this.page, this.conversation.workflow.seed)
await new AgentPanel(this.page).open()
await expect(this.panel).toBeVisible({ timeout: PANEL_MOUNT_TIMEOUT })
await new AgentPanel(this.page).open(PANEL_MOUNT_TIMEOUT)
await this.selectWorkflowTarget()
}

Expand Down
3 changes: 1 addition & 2 deletions browser_tests/fixtures/agentCrdtIdCollisionFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ export class IdCollisionHarness {
},
objectInfo: 'server'
})
await new AgentPanel(this.page).open()
await expect(this.panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(this.page).open(30_000)
await this.selectWorkflowTarget()
// `useAgentSession` only binds the CRDT workflow id (which is what makes
// the follower's `isTargetActive` watch subscribe) once a turn's POST ack
Expand Down
38 changes: 27 additions & 11 deletions browser_tests/fixtures/components/AgentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,35 @@ export class AgentPanel {
)
}

async open(): Promise<void> {
for (let attempt = 0; attempt < 2; attempt++) {
if (await this.root.isVisible()) return
await this.openButton.click()
try {
await expect(this.root).toBeVisible({ timeout: 1_000 })
return
} catch {
// Startup activation can open between the visibility read and click,
// making that click close the panel. Retry from the observed state.
async open(timeout?: number): Promise<Locator> {
if (await this.root.isVisible()) return this.root

const dropClickIfAlreadyOpen = await this.openButton.evaluateHandle(
(button) => {
const listener = (event: Event) => {
if (button.getAttribute('aria-pressed') === 'true')
event.stopImmediatePropagation()
}
button.addEventListener('click', listener, true)
return listener
}
)
try {
await expect(async () => {
if (await this.root.isVisible()) return
await this.openButton.click({ timeout: 1_000 })
}).toPass({ timeout })
} finally {
await this.openButton.evaluate(
(button, listener) =>
button.removeEventListener('click', listener, true),
dropClickIfAlreadyOpen
)
await dropClickIfAlreadyOpen.dispose()
}
await expect(this.root).toBeVisible()

await expect(this.root).toBeVisible({ timeout })
return this.root
}

async selectWorkflow(name: string = 'Unsaved Workflow'): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,13 @@ for (const scenario of [
return route.fulfill(jsonRoute(messages))
})

await new AgentPanel(page).open()
const panel = await new AgentPanel(page).open()
await page
.getByRole('button', {
name: enMessages.sideToolbar.newBlankWorkflow,
exact: true
})
.click()
const panel = page.locator('#agent-panel-root')
await expect(panel).toBeVisible()
await panel
.getByRole('button', { name: enMessages.agent.switchWorkflow })
.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ test(
(route) => route.fulfill({ path: assetPath('image64x64.webp') })
)

await new AgentPanel(page).open()
const panel = await new AgentPanel(page).open()
await page
.getByRole('button', {
name: enMessages.sideToolbar.newBlankWorkflow,
exact: true
})
.click()
const panel = page.locator('#agent-panel-root')
await expect(panel).toBeVisible()
await panel
.getByRole('button', { name: enMessages.agent.switchWorkflow })
.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ async function driveThroughDocReset(
await loadSeedIntoActiveTab(page, SEED)

const panel = page.locator('#agent-panel-root')
await new AgentPanel(page).open()
await expect(panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(page).open(30_000)

let savedName: string | undefined
await page.route('**/api/userdata/*', (route) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ async function driveThroughToolCallDone(
})

const panel = page.locator('#agent-panel-root')
await new AgentPanel(page).open()
await expect(panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(page).open(30_000)

let savedName: string | undefined
await page.route('**/api/userdata/*', (route) => {
Expand Down
4 changes: 1 addition & 3 deletions browser_tests/tests/agent/agentComposerPaste.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ test(
await canvas.click()
await canvas.press('Control+c')

await new AgentPanel(page).open()
const panel = page.locator('#agent-panel-root')
await expect(panel).toBeVisible()
const panel = await new AgentPanel(page).open()

const composer = panel.getByRole('textbox', { name: /^Describe ideas/ })
await composer.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ test(
)
).toBe(PORTRAIT_PATH)

await new AgentPanel(page).open()
const panel = page.locator('#agent-panel-root')
await expect(panel).toBeVisible()
const panel = await new AgentPanel(page).open()
await expect(panel.getByTestId('user-message-bubble')).toHaveText([
'Earlier request'
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ test.describe(
})

const panel = page.locator('#agent-panel-root')
await new AgentPanel(page).open()
await expect(panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(page).open(30_000)

let savedName: string | undefined
await page.route('**/api/userdata/*', (route) => {
Expand Down
4 changes: 1 addition & 3 deletions browser_tests/tests/agent/agentInlineReferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ test(
mimeType: 'application/json',
buffer: Buffer.from(JSON.stringify(referenceWorkflow))
})
const agentPanel = new AgentPanel(page)
await agentPanel.open()
const panel = agentPanel.root
const panel = await new AgentPanel(page).open()
const editor = panel.getByRole('textbox')
await panel
.getByRole('button', { name: enMessages.agent.switchWorkflow })
Expand Down
36 changes: 34 additions & 2 deletions browser_tests/tests/agent/agentPanelAppMode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from '@playwright/test'

import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import enMessages from '@/locales/en/main.json' with { type: 'json' }
import type { WorkspaceStore } from '@e2e/types/globals'

import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import { agentTest as test } from '@e2e/tests/agent/agentPanelMocks'

const OPEN_AGENT_LABEL = enMessages.agent.entryButton
Expand Down Expand Up @@ -55,6 +55,38 @@ test.describe('In-App Agent panel across view modes', { tag: '@cloud' }, () => {
await expect.poll(activeWorkflowPath).toBe(selectedWorkflowPath)
})

test('keeps a user-closed panel hidden when toggling app mode and back', async ({
comfyPage
}) => {
test.setTimeout(30_000)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just bump the timeout globally?


const page = comfyPage.page
const dockedPanel = page.getByTestId('docked-agent-panel')
const storedOpenState = () =>
page.evaluate((key) => localStorage.getItem(key), OPEN_STORAGE_KEY)

await test.step('close and persist the panel state', async () => {
await expect(dockedPanel).toBeVisible({ timeout: 8_000 })
await dockedPanel
.getByRole('button', { name: enMessages.g.close, exact: true })
.click()
await expect(dockedPanel).toHaveCount(0)
await expect.poll(storedOpenState).toBe('false')
})

await test.step('keep the panel closed in app mode', async () => {
await comfyPage.appMode.toggleAppMode()
await expect(dockedPanel).toHaveCount(0)
await expect.poll(storedOpenState).toBe('false')
})

await test.step('keep the panel closed after returning to graph mode', async () => {
await comfyPage.appMode.toggleAppMode()
await expect(dockedPanel).toHaveCount(0)
await expect.poll(storedOpenState).toBe('false')
})
})

test('activation reopens a stored-closed panel across app mode changes', async ({
comfyPage
}) => {
Expand All @@ -71,7 +103,7 @@ test.describe('In-App Agent panel across view modes', { tag: '@cloud' }, () => {
)
await comfyPage.workflow.reloadAndWaitForApp()

await expect(dockedPanel).toBeVisible()
await expect(dockedPanel).toBeVisible({ timeout: 8_000 })
await expect.poll(storedOpenState).toBe('true')

await comfyPage.appMode.toggleAppMode()
Expand Down
99 changes: 99 additions & 0 deletions browser_tests/tests/agent/agentPanelLifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,105 @@ test.describe(
await expect(openButton).toBeVisible()
})

test.describe('opening from a user-closed panel', () => {
test.beforeEach(async ({ page }) => {
await bootAgentApp(page, true)
const agentPanel = new AgentPanel(page)
await expect(agentPanel.root).toBeVisible({ timeout: 8_000 })
await agentPanel.root
.getByRole('button', { name: enMessages.g.close })
.click()
await expect(agentPanel.root).toHaveCount(0)
})

test('waits for a delayed open without clicking again', async ({
page
}) => {
const agentPanel = new AgentPanel(page)
await agentPanel.openButton.evaluate<void, HTMLElement>((button) => {
button.dataset.testClickCount = '0'
button.addEventListener(
'click',
() => {
button.dataset.testClickCount = String(
Number(button.dataset.testClickCount) + 1
)
},
true
)

let delayed = false
const delayOpen = (event: Event) => {
event.stopImmediatePropagation()
if (delayed) return
delayed = true
window.setTimeout(() => {
button.removeEventListener('click', delayOpen, true)
button.click()
}, 1_500)
}
button.addEventListener('click', delayOpen, true)
})

await agentPanel.open(3_000)

await expect(agentPanel.openButton).toHaveAttribute(
'data-test-click-count',
'2'
)
})

test('rejects with the caller timeout while an open stays pending', async ({
page
}) => {
const agentPanel = new AgentPanel(page)
await agentPanel.openButton.evaluate((button) => {
button.addEventListener(
'click',
(event) => event.stopImmediatePropagation(),
true
)
})

await expect(agentPanel.open(250)).rejects.toThrow('250ms')
})

test('drops its click when activation opens the panel just before it lands', async ({
page
}) => {
const agentPanel = new AgentPanel(page)
await agentPanel.openButton.evaluate<void, HTMLElement>((button) => {
button.dataset.testClickCount = '0'
button.dataset.testActivationClickCount = '0'
button.addEventListener('click', (event) => {
button.dataset.testClickCount = String(
Number(button.dataset.testClickCount) + 1
)
if (!event.isTrusted) {
button.dataset.testActivationClickCount = String(
Number(button.dataset.testActivationClickCount) + 1
)
}
Comment on lines +182 to +186

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: isTrusted doesn't prove the pointerdown stand-in ran. A forced helper click, such as openButton.evaluate((b) => b.click()), is also untrusted and never fires pointerdown. I swapped that into open() and this test still passed, with one click counted as "activation". Marking the stand-in itself catches that case and removes the branch from the listener:

button.addEventListener(
  'pointerdown',
  () => {
    button.dataset.testActivationRan = 'true'
    button.click()
  },
  { capture: true, once: true }
)

Then assert data-test-activation-ran is 'true' next to data-test-click-count being '1'. Together those show the stand-in opened the panel and the helper's own click was dropped.

})
button.addEventListener('pointerdown', () => button.click(), {
capture: true,
once: true
})
})

await agentPanel.open()

await expect(agentPanel.openButton).toHaveAttribute(
'data-test-click-count',
'1'
)
await expect(agentPanel.openButton).toHaveAttribute(
'data-test-activation-click-count',
'1'
)
})
})

test('keeps the dock within the viewport and its documented width cap', async ({
page
}) => {
Expand Down
3 changes: 1 addition & 2 deletions browser_tests/tests/agent/agentReplyDrafts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ async function startTurn(page: Page, prompt: string): Promise<Turn> {
'true',
{ timeout: 8_000 }
)
await new AgentPanel(page).open()
await expect(panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(page).open(30_000)

let savedName: string | undefined
await page.route('**/api/userdata/*', (route) => {
Expand Down
3 changes: 1 addition & 2 deletions browser_tests/tests/agent/agentRunApprovalConsent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ async function startTurn(
'true',
{ timeout: 8_000 }
)
await new AgentPanel(page).open()
await expect(panel).toBeVisible({ timeout: 30_000 })
await new AgentPanel(page).open(30_000)

await mockWorkflowPersistence(page, WORKFLOW_ID)

Expand Down
Loading