diff --git a/surfaces/gui/e2e/turn-state.spec.ts b/surfaces/gui/e2e/turn-state.spec.ts index eb81f674..19cfefee 100644 --- a/surfaces/gui/e2e/turn-state.spec.ts +++ b/surfaces/gui/e2e/turn-state.spec.ts @@ -2,6 +2,10 @@ // whose turn is already running server-side never sees a live `turn_start`, so `running` // must be restored from the ws `ready` payload — otherwise the Stop button and the // "Waiting for agent" row vanish and the user cannot stop the turn. +// +// #506 regression: after switching AWAY from a running session and back, the re-opened +// session socket's `ready` (carrying server-truth `running`) must restore the Stop +// button — the composer must never fall back to Send on a live turn. import { expect } from "@playwright/test"; import { test } from "./fixtures"; @@ -16,6 +20,28 @@ test("opening a session with a live turn shows Stop and the waiting row", async await expect(page.getByText("Waiting for agent...")).toBeVisible(); // An idle session still gets the plain send arrow (running:false path). - await page.getByText("Draft the launch note").first().click(); + await page.getByTitle("Draft the launch note").first().click(); await expect(page.getByRole("button", { name: /Stop/ })).toHaveCount(0); }); + +test("switch away and back to a running session restores Stop (regression #506)", async ({ + page, +}) => { + await page.goto("/"); + await page.getByRole("button", { name: /Show more/ }).first().click(); + + // Running session: Stop replaces Send. + await page.getByTitle("Long audit").click(); + await expect(page.getByRole("button", { name: /Stop/ })).toBeVisible(); + + // Switch to an idle session — plain send arrow (this session is idle). + await page.getByTitle("Draft the launch note").first().click(); + await expect(page.getByRole("button", { name: "Send" })).toBeVisible(); + await expect(page.getByRole("button", { name: /Stop/ })).toHaveCount(0); + + // Switch BACK to the still-running session: `ready` carries running:true, so Stop + // must come back and Send must not (the turn is live and must stay interruptible). + await page.getByTitle("Long audit").click(); + await expect(page.getByRole("button", { name: /Stop/ })).toBeVisible(); + await expect(page.getByRole("button", { name: "Send" })).toHaveCount(0); +});