diff --git a/browser_tests/fixtures/agentTurnLockFixture.ts b/browser_tests/fixtures/agentTurnLockFixture.ts index ec2f6554420..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 @@ -434,28 +449,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/agentApprovalRecovery.spec.ts similarity index 71% rename from browser_tests/tests/agent/agentApprovalSurvivesSocketDrop.spec.ts rename to browser_tests/tests/agent/agentApprovalRecovery.spec.ts index 74655d339cd..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,13 +94,33 @@ 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']) }) + + test('a refresh restores the persisted approval ask', async ({ + page, + turnLock + }) => { + turnLock.primePendingAsk(RUN_APPROVAL_EVENT) + + await page.reload() + await expect( + 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.runApprovalButton.click({ timeout: 10_000 }) + await expect + .poll(() => turnLock.answeredAsks(), { timeout: 10_000 }) + .toEqual(['run']) + + turnLock.push(await turnLock.liveSocket(), RUN_APPROVAL_RESOLVED_EVENT) + await expect(turnLock.runApprovalButton).toBeHidden({ timeout: 10_000 }) + expect(turnLock.answeredAsks()).toEqual(['run']) + }) } )