Skip to content
Merged
11 changes: 11 additions & 0 deletions browser_tests/fixtures/components/AgentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class AgentPanel {
public readonly fileInput: Locator
public readonly composerAssetSection: Locator
public readonly attachmentChips: Locator
public readonly composer: Locator
public readonly sendButton: Locator

constructor(private readonly page: Page) {
this.root = page.locator('#agent-panel-root')
Expand All @@ -41,6 +43,10 @@ export class AgentPanel {
this.fileInput = this.root.getByTestId('agent-file-input')
this.composerAssetSection = this.root.getByTestId('composer-asset-section')
this.attachmentChips = this.root.getByTestId('agent-attachment-chip')
this.composer = this.root.getByRole('textbox', { name: /^Describe ideas/ })
this.sendButton = this.root.getByRole('button', {
name: enMessages.agent.send
})
}

/**
Expand Down Expand Up @@ -77,6 +83,11 @@ export class AgentPanel {
await expect(this.workflowPicker).toHaveText(name)
}

async sendMessage(message: string): Promise<void> {
await this.composer.fill(message)
await this.sendButton.click()
}

async turnOffOptionalReportSources(): Promise<void> {
await this.serverLogsSwitch.click()
await this.settingsSwitch.click()
Expand Down
63 changes: 63 additions & 0 deletions browser_tests/tests/agent/agentAttachmentUpload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from '@playwright/test'

import enMessages from '@/locales/en/main.json' with { type: 'json' }

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

test.describe('Agent attachment cancellation', { tag: '@cloud' }, () => {
test('closing the panel removes a pending upload and preserves a sendable draft', async ({
comfyPage,
agentPanel
}) => {
const page = comfyPage.page
let releaseUpload = () => {}
const uploadHeld = new Promise<void>((resolve) => {
releaseUpload = resolve
})
await page.route('**/api/upload/image', async (route) => {
await uploadHeld
await route.abort()
})

try {
const openButton = page.getByRole('button', {
name: enMessages.agent.entryButton,
exact: true
})
await openButton.click()
await agentPanel.selectWorkflow()
const panel = page.locator('#agent-panel-root')
const composer = panel.getByRole('textbox', { name: /^Describe ideas/ })
const send = panel.getByRole('button', { name: 'Send', exact: true })
await composer.fill('Keep this draft')
await expect(send).toBeEnabled()

const uploadReceived = page.waitForRequest('**/api/upload/image')
await panel.getByTestId('agent-file-input').setInputFiles({
name: 'pending.mp4',
mimeType: 'video/mp4',
buffer: Buffer.from('pending upload')
})
await uploadReceived
await expect(
panel.getByTestId('composer-asset-section').getByText('pending.mp4')
).toBeVisible()
await expect(send).toBeDisabled()

await panel
.getByRole('button', { name: enMessages.g.close, exact: true })
.click()
await expect(panel).toHaveCount(0)
await openButton.click()

await expect(composer).toHaveText('Keep this draft')
await expect(panel.getByText('pending.mp4', { exact: true })).toHaveCount(
0
)
await expect(send).toBeEnabled()
} finally {
releaseUpload()
await page.unrouteAll({ behavior: 'wait' })
}
})
})
92 changes: 92 additions & 0 deletions browser_tests/tests/agent/agentPanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,42 @@ test.describe('In-App Agent panel', { tag: '@cloud' }, () => {
await expect(panel.getByText('Resize image node')).toBeVisible()
})

test('shows an admission paywall without losing the rejected prompt', async ({
agentPanel,
comfyPage
}) => {
const page = comfyPage.page
await page.route('**/api/agent/threads/*/messages', (route) =>
route.fulfill({
status: 402,
contentType: 'application/json',
body: JSON.stringify({
error: {
message: 'Add credits to continue.',
type: 'PAYMENT_REQUIRED',
reason: 'no_funds'
}
})
})
)

await agentPanel.open()
await agentPanel.selectWorkflow()
const panel = agentPanel.root

const prompt = 'Build a product photo workflow'
await panel.getByRole('textbox', { name: /^Describe ideas/ }).fill(prompt)
await panel.getByRole('button', { name: 'Send' }).click()

await expect(panel.getByTestId('user-message-bubble')).toHaveText(prompt)
await expect(
panel.getByRole('textbox', { name: /^Describe ideas/ })
).toHaveText(prompt)
const paywall = panel.getByRole('alert')
await expect(paywall).toContainText(enMessages.agent.paywall.title)
await expect(paywall).toContainText('Add credits to continue.')
})

test.describe('composer sizing', () => {
test.use({
viewport: { width: 1920, height: 1080 },
Expand Down Expand Up @@ -305,6 +341,62 @@ test.describe('In-App Agent panel', { tag: '@cloud' }, () => {
.toBeLessThanOrEqual(1)
})

test('uses the server upload limit for Agent file attachments', async ({
comfyPage,
agentPanel
}) => {
test.setTimeout(60_000)
const page = comfyPage.page
let uploadCount = 0
await page.route('**/api/upload/image', async (route) => {
uploadCount += 1
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
name: 'uploaded_movie.mp4',
subfolder: '',
type: 'input'
})
})
})
await page.evaluate(() => {
window.app!.api.serverFeatureFlags.value = {
...window.app!.api.serverFeatureFlags.value,
max_upload_size: 24 * 1024 * 1024
}
})

await agentPanel.open()
const panel = page.locator('#agent-panel-root')
const fileInput = panel.getByTestId('agent-file-input')

const uploadResponse = page.waitForResponse('**/api/upload/image')
await fileInput.setInputFiles({
name: 'movie.mp4',
mimeType: 'video/mp4',
buffer: Buffer.alloc(21 * 1024 * 1024)
})
expect((await uploadResponse).ok()).toBe(true)
await expect(
panel.getByTestId('composer-asset-section').getByText('movie.mp4')
).toBeVisible()
await expect.poll(() => uploadCount).toBe(1)

await fileInput.setInputFiles({
name: 'too-large.mp4',
mimeType: 'video/mp4',
buffer: Buffer.alloc(25 * 1024 * 1024)
})
await expect(
page.getByText('too-large.mp4 is larger than 24 MB')
).toBeVisible()
await expect(panel.getByText('too-large.mp4', { exact: true })).toHaveCount(
0
)
await expect.poll(() => uploadCount).toBe(1)
})

test('exits node selection when the active workflow changes', async ({
comfyPage
}) => {
Expand Down
25 changes: 25 additions & 0 deletions browser_tests/tests/agent/agentPanelMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
AgentTurnAccepted,
AgentWsEvent
} from '@/workbench/extensions/agent/schemas/agentApiSchema'
import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema'

import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import { mockBilling } from '@e2e/fixtures/utils/cloudBillingMocks'
Expand All @@ -37,6 +38,16 @@ const TURN_ACCEPTED: AgentTurnAccepted = {

const CANCEL_ACCEPTED: AgentCancelAccepted = { status: 'cancelling' }

export const FUNDS_UNAVAILABLE_MESSAGE =
'Billing status is temporarily unavailable; please retry.'
const FUNDS_UNAVAILABLE = zAgentAdmissionError.parse({
error: {
message: FUNDS_UNAVAILABLE_MESSAGE,
reason: 'funds_unavailable',
type: 'SERVICE_UNAVAILABLE'
}
})

export const THINKING_TEXT =
"I'll set the positive prompt to your red fox scene."

Expand Down Expand Up @@ -152,6 +163,7 @@ async function mockAgentBoot(
agentFlagEnabled,
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand Down Expand Up @@ -347,6 +359,15 @@ async function mockAgentBoot(
const request = route.request()
if (request.method() === 'POST') {
postedMessages.push(request.postData() ?? '')
if (agentRetryAfter !== undefined)
return route.fulfill({
status: 503,
headers: {
'content-type': 'application/json',
'retry-after': agentRetryAfter
},
body: JSON.stringify(FUNDS_UNAVAILABLE)
})
const accepted: AgentTurnAccepted = {
...TURN_ACCEPTED,
message_id:
Expand Down Expand Up @@ -388,6 +409,7 @@ type AgentFixtures = {
agentPanel: AgentPanel
agentPanelInitiallyOpen: boolean
agentOnboardingCompleted: boolean
agentRetryAfter: string | undefined
crdtDebugEnabled: boolean
/** `'server'` loads real node definitions instead of the empty catalog. */
objectInfo: 'server' | undefined
Expand All @@ -411,6 +433,7 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
},
agentPanelInitiallyOpen: [false, { option: true }],
agentOnboardingCompleted: [true, { option: true }],
agentRetryAfter: [undefined, { option: true }],
crdtDebugEnabled: [false, { option: true }],
objectInfo: [undefined, { option: true }],
page: async (
Expand All @@ -422,6 +445,7 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentFlagEnabled,
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand All @@ -439,6 +463,7 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentFlagEnabled,
agentPanelInitiallyOpen,
agentOnboardingCompleted,
agentRetryAfter,
crdtDebugEnabled,
initialFeatureFlags,
initialSettings,
Expand Down
49 changes: 49 additions & 0 deletions browser_tests/tests/agent/agentRetryAfterNotice.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect } from '@playwright/test'

import enMessages from '@/locales/en/main.json' with { type: 'json' }

import {
agentTest,
FUNDS_UNAVAILABLE_MESSAGE
} from '@e2e/tests/agent/agentPanelMocks'

agentTest.describe(
'Agent Retry-After notice',
{ tag: ['@cloud', '@ui'] },
() => {
agentTest.describe('with delay-seconds', () => {
agentTest.use({ agentRetryAfter: '30' })

agentTest(
'shows the retry delay the header names',
async ({ agentPanel }) => {
await agentTest.step(
'open the agent and select the workflow',
async () => {
await agentPanel.open()
await agentPanel.selectWorkflow()
}
)

await agentTest.step('submit a prompt', async () => {
await agentPanel.sendMessage('Make a red fox in the snow')
})

await agentTest.step(
'show the admission error and retry delay',
async () => {
await expect(
agentPanel.root.getByText(FUNDS_UNAVAILABLE_MESSAGE)
).toBeVisible()
await expect(
agentPanel.root.getByText(
enMessages.agent.retryAfterSeconds.replace('{seconds}', '30')
)
).toBeVisible()
}
)
}
)
})
}
)
Loading
Loading