From e6405aaef13f89c4f16882a7bdb4d02ae94dd642 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 03:40:02 +0000 Subject: [PATCH 1/5] test(agent): prove persisted approvals recover on refresh Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/18952#discussion_r4128112069 --- .../fixtures/agentTurnLockFixture.ts | 22 ---------------- .../agentApprovalSurvivesSocketDrop.spec.ts | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/browser_tests/fixtures/agentTurnLockFixture.ts b/browser_tests/fixtures/agentTurnLockFixture.ts index ec2f6554420..41134a2c5d4 100644 --- a/browser_tests/fixtures/agentTurnLockFixture.ts +++ b/browser_tests/fixtures/agentTurnLockFixture.ts @@ -434,28 +434,6 @@ export class AgentTurnLockHarness { return this.server.answers.flat() } - /** Posts an answer through the browser so the real route validator sees it. */ - async postAnswer( - threadId: string, - askId: string, - selected: string[] - ): Promise { - return await this.page.evaluate( - async ({ threadId, askId, selected }) => { - const response = await fetch( - `/api/agent/threads/${encodeURIComponent(threadId)}/asks/${encodeURIComponent(askId)}/answer`, - { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ selected }) - } - ) - return response.status - }, - { threadId, askId, selected } - ) - } - /** The socket the client is currently on, with no drop. */ async liveSocket(): Promise { return this.getWebSocket() diff --git a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts index 74655d339cd..666e13fb366 100644 --- a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts +++ b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts @@ -111,5 +111,31 @@ test.describe( .click() await expect.poll(() => turnLock.answeredAsks()).toEqual(['run']) }) + + test('a refresh restores the persisted approval ask', async ({ + page, + turnLock + }) => { + turnLock.primePendingAsk(RUN_APPROVAL_EVENT) + expect(turnLock.pendingAskIsPrimed()).toBe(true) + + await page.reload() + await expect( + page.getByTestId('integrated-tab-bar-actions') + ).toHaveAttribute('data-agent-gate-settled', 'true', { timeout: 30_000 }) + await expect(turnLock.panel).toBeVisible({ timeout: 30_000 }) + await expect( + turnLock.panel.getByText(enMessages.agent.runApproval.question) + ).toBeVisible() + + await turnLock.panel + .getByRole('button', { + name: enMessages.agent.runApproval.run, + exact: true + }) + .click() + await expect.poll(() => turnLock.answeredAsks()).toEqual(['run']) + expect(turnLock.pendingAskIsPrimed()).toBe(false) + }) } ) From 4af7b724234a35df690783b8a57b88ec0211c89b Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 22:45:48 +0000 Subject: [PATCH 2/5] test(agent): bound refreshed approval waits Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4129664617 --- .../tests/agent/agentApprovalSurvivesSocketDrop.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts index 666e13fb366..1fc369d2fc4 100644 --- a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts +++ b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts @@ -126,15 +126,17 @@ test.describe( await expect(turnLock.panel).toBeVisible({ timeout: 30_000 }) await expect( turnLock.panel.getByText(enMessages.agent.runApproval.question) - ).toBeVisible() + ).toBeVisible({ timeout: 30_000 }) await turnLock.panel .getByRole('button', { name: enMessages.agent.runApproval.run, exact: true }) - .click() - await expect.poll(() => turnLock.answeredAsks()).toEqual(['run']) + .click({ timeout: 10_000 }) + await expect + .poll(() => turnLock.answeredAsks(), { timeout: 10_000 }) + .toEqual(['run']) expect(turnLock.pendingAskIsPrimed()).toBe(false) }) } From f3f3df579edfa2cf7265ae4c6cf5cff882aaa080 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 22:46:01 +0000 Subject: [PATCH 3/5] test(agent): detect duplicate refreshed approval answers Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4129664621 --- .../tests/agent/agentApprovalSurvivesSocketDrop.spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts index 1fc369d2fc4..6b4af46bd1d 100644 --- a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts +++ b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts @@ -137,7 +137,11 @@ test.describe( await expect .poll(() => turnLock.answeredAsks(), { timeout: 10_000 }) .toEqual(['run']) - expect(turnLock.pendingAskIsPrimed()).toBe(false) + + // Give a duplicate submission time to reach the fake server after the + // persisted ask has resolved, then verify exactly one answer was sent. + await page.waitForTimeout(1_000) + expect(turnLock.answeredAsks()).toEqual(['run']) }) } ) From d35048ea4d247dd57f39bfcda966ba032561bac2 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 22:48:54 +0000 Subject: [PATCH 4/5] test(agent): wait on refreshed approval state Follow-up to https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4129664621 --- .../agent/agentApprovalSurvivesSocketDrop.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts index 6b4af46bd1d..650bb02fd56 100644 --- a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts +++ b/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts @@ -138,9 +138,14 @@ test.describe( .poll(() => turnLock.answeredAsks(), { timeout: 10_000 }) .toEqual(['run']) - // Give a duplicate submission time to reach the fake server after the - // persisted ask has resolved, then verify exactly one answer was sent. - await page.waitForTimeout(1_000) + // Wait for the persisted ask to leave the UI, then verify resolving it + // sent exactly one answer to the fake server. + await expect( + turnLock.panel.getByRole('button', { + name: enMessages.agent.runApproval.run, + exact: true + }) + ).toBeHidden({ timeout: 10_000 }) expect(turnLock.answeredAsks()).toEqual(['run']) }) } From 03a229ab7f375fe69bb87112f3acf426c3457989 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 29 Sep 2026 17:13:12 -0700 Subject: [PATCH 5/5] test(agent): resolve persisted approval after refresh Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174599 https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174612 https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174617 https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174632 https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174642 https://github.com/Comfy-Org/ComfyUI_frontend/pull/19340#discussion_r4139174652 --- .../fixtures/agentTurnLockFixture.ts | 23 ++++++-- ....spec.ts => agentApprovalRecovery.spec.ts} | 52 +++++-------------- 2 files changed, 32 insertions(+), 43 deletions(-) rename browser_tests/tests/agent/{agentApprovalSurvivesSocketDrop.spec.ts => agentApprovalRecovery.spec.ts} (74%) diff --git a/browser_tests/fixtures/agentTurnLockFixture.ts b/browser_tests/fixtures/agentTurnLockFixture.ts index 41134a2c5d4..a4547e548cd 100644 --- a/browser_tests/fixtures/agentTurnLockFixture.ts +++ b/browser_tests/fixtures/agentTurnLockFixture.ts @@ -115,16 +115,26 @@ export const RUN_APPROVAL_EVENT: AgentWsEvent = { } } +export const RUN_APPROVAL_RESOLVED_EVENT: AgentWsEvent = { + type: 'agent_ask_resolved', + data: { + message_id: TURN_ID, + thread_id: THREAD_ID, + ask_id: RUN_APPROVAL_ASK_ID, + status: 'answered', + selected: [RUN_APPROVAL_OPTION_IDS[0]] + } +} + /** * The server's half of a turn, modelled on the real single-active-turn guard: * an assistant row goes `streaming` when a turn starts and only leaves that * state when the turn completes, fails, or is cancelled. Dropping the client's * socket does not touch it — that asymmetry is what these specs exercise. * - * `transcript()` and the cancel route are not reached by the current specs. - * They are here so the fake stays a faithful server: a repair that re-hydrates - * on reconnect, or a spec that clicks Stop, needs both, and a half-modelled - * server would make such a fix look broken. + * Transcript hydration backs the refresh-recovery case. The cancel route is + * not reached by the current specs, but keeps the fake faithful for a case + * that clicks Stop. */ class TurnLockServer { private streaming = false @@ -284,6 +294,7 @@ export class AgentTurnLockHarness { public readonly composer: Locator public readonly sendButton: Locator public readonly stopButton: Locator + public readonly runApprovalButton: Locator public readonly workSummary: Locator public readonly workingRow: Locator public readonly userBubbles: Locator @@ -308,6 +319,10 @@ export class AgentTurnLockHarness { name: enMessages.agent.stop, exact: true }) + this.runApprovalButton = this.panel.getByRole('button', { + name: enMessages.agent.runApproval.run, + exact: true + }) // WorkSummary.vue renders three labels off the elapsed total: `worked` // alone, `workedForSeconds`, or `workedForMinutes`. Anchoring on the // shared `worked` stem matches all three, so the negative assertions on diff --git a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts b/browser_tests/tests/agent/agentApprovalRecovery.spec.ts similarity index 74% rename from browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts rename to browser_tests/tests/agent/agentApprovalRecovery.spec.ts index 650bb02fd56..4c390a3dfc6 100644 --- a/browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts +++ b/browser_tests/tests/agent/agentApprovalRecovery.spec.ts @@ -3,8 +3,10 @@ import { expect } from '@playwright/test' import enMessages from '@/locales/en/main.json' with { type: 'json' } import { RUN_APPROVAL_EVENT, + RUN_APPROVAL_RESOLVED_EVENT, agentTurnLockTest as test } from '@e2e/fixtures/agentTurnLockFixture' +import { TestIds } from '@e2e/fixtures/selectors' // The worst shape a stall can take, from a real user report: they asked for an // img2img workflow, then for img2video, and the panel went dead. They restarted @@ -23,15 +25,14 @@ import { // to: `ingestBackgroundTurnEvent` returns at `!entry` and the frame is gone. // Nothing errors, the panel looks idle, the server looks healthy. // -// Deliberately not a refresh: on a refresh the ask comes back, because the -// persisted row carries `pending_ask` and `normalizeAgentTranscript` restores -// the card. That asymmetry is why restarting the tab "fixed" it for the user -// and why this only ever showed up through a feedback form. +// A refresh restores the card from the persisted row's `pending_ask`; a socket +// blip does not. That asymmetry is why restarting the tab "fixed" it for the +// user and why this only ever showed up through a feedback form. test.describe.configure({ timeout: 120_000 }) test.use({ connectWebSocketToServer: false }) test.describe( - 'an approval ask survives a socket drop', + 'approval ask recovery across socket drop and refresh', { tag: ['@cloud', '@ui'] }, () => { const PROMPT = 'turn this image into a video' @@ -60,12 +61,7 @@ test.describe( await expect( turnLock.panel.getByText(enMessages.agent.runApproval.question) ).toBeVisible() - await expect( - turnLock.panel.getByRole('button', { - name: enMessages.agent.runApproval.run, - exact: true - }) - ).toBeVisible() + await expect(turnLock.runApprovalButton).toBeVisible() }) test('the user can answer the ask that arrived after the reconnect', async ({ @@ -79,12 +75,7 @@ test.describe( test.fail() // Recovery must restore both the card and its active turn identity; // `answerAsk` deliberately refuses to POST without `activeTurnId`. - await turnLock.panel - .getByRole('button', { - name: enMessages.agent.runApproval.run, - exact: true - }) - .click({ timeout: 10_000 }) + await turnLock.runApprovalButton.click({ timeout: 10_000 }) await expect.poll(() => turnLock.answeredAsks()).toEqual(['run']) }) @@ -103,12 +94,7 @@ test.describe( await expect( turnLock.panel.getByText(enMessages.agent.runApproval.question) ).toBeVisible() - await turnLock.panel - .getByRole('button', { - name: enMessages.agent.runApproval.run, - exact: true - }) - .click() + await turnLock.runApprovalButton.click() await expect.poll(() => turnLock.answeredAsks()).toEqual(['run']) }) @@ -117,35 +103,23 @@ test.describe( turnLock }) => { turnLock.primePendingAsk(RUN_APPROVAL_EVENT) - expect(turnLock.pendingAskIsPrimed()).toBe(true) await page.reload() await expect( - page.getByTestId('integrated-tab-bar-actions') + page.getByTestId(TestIds.topbar.integratedTabBarActions) ).toHaveAttribute('data-agent-gate-settled', 'true', { timeout: 30_000 }) await expect(turnLock.panel).toBeVisible({ timeout: 30_000 }) await expect( turnLock.panel.getByText(enMessages.agent.runApproval.question) ).toBeVisible({ timeout: 30_000 }) - await turnLock.panel - .getByRole('button', { - name: enMessages.agent.runApproval.run, - exact: true - }) - .click({ timeout: 10_000 }) + await turnLock.runApprovalButton.click({ timeout: 10_000 }) await expect .poll(() => turnLock.answeredAsks(), { timeout: 10_000 }) .toEqual(['run']) - // Wait for the persisted ask to leave the UI, then verify resolving it - // sent exactly one answer to the fake server. - await expect( - turnLock.panel.getByRole('button', { - name: enMessages.agent.runApproval.run, - exact: true - }) - ).toBeHidden({ timeout: 10_000 }) + turnLock.push(await turnLock.liveSocket(), RUN_APPROVAL_RESOLVED_EVENT) + await expect(turnLock.runApprovalButton).toBeHidden({ timeout: 10_000 }) expect(turnLock.answeredAsks()).toEqual(['run']) }) }