diff --git a/tests/bugbash/repros/editAfterEmptyFailedReply.e2e.ts b/tests/bugbash/repros/editAfterEmptyFailedReply.e2e.ts index 1b288b77be2..7e7aa4854ce 100644 --- a/tests/bugbash/repros/editAfterEmptyFailedReply.e2e.ts +++ b/tests/bugbash/repros/editAfterEmptyFailedReply.e2e.ts @@ -3,7 +3,8 @@ // refused the edit once with "History changed". Proves the first Send of such an edit goes through. import { test } from "@e2e-dev/web"; import { expect } from "e2e"; -import { openPlayground, sendMessage, sendMessageForEdit } from "./helpers"; +import { openPlayground, sendMessageForEdit } from "./helpers"; +import { WORKSPACE_STOP_IN_PROGRESS_SEND_BLOCKED_MESSAGE } from "../../../src/constants/agentMessaging"; import { EDIT_HISTORY_CHANGED_MESSAGE } from "../../../src/constants/transcriptBarrier"; test( @@ -21,10 +22,54 @@ test( await screen.getByRole("button", /^Stop/).tap(); await expect(screen.getByText("Auto-retry stopped:")).toBeVisible({ timeout: 10_000 }); - // This send's server drops the empty failed reply from history. + // This send's server drops the empty failed reply from history. "Auto-retry stopped" shows + // before the Stop has settled, and the UI has no signal for that point (the stop latch's + // release): a send in between is refused as retryable (#7655). So send again after each such + // refusal, as its message asks ("retry once it has settled"). Any other refusal fails here. + // The UI should wait for the Stop instead: #7658. const followUp = `6116 follow-up ${stamp}`; - await sendMessage(screen, followUp); - await expect(screen.getByText(`Mock response: ${followUp}`)).toBeVisible({ timeout: 20_000 }); + const composer = screen.getByRole("textbox", "Message"); + const followUpAnswered = screen.getByText(`Mock response: ${followUp}`); + const stopBusy = screen.getByText(WORKSPACE_STOP_IN_PROGRESS_SEND_BLOCKED_MESSAGE); + // Any error toast, whatever its title: an alert has no accessible name, and refusal titles + // vary, so match the toast by its Dismiss button. + const sendFailed = screen + .getByRole("alert") + .filter({ has: screen.getByRole("button", "Dismiss") }) + .first(); + const outcome = async () => + (await followUpAnswered.isVisible()) + ? "answered" + : (await stopBusy.isVisible()) + ? "stop in progress" + : (await sendFailed.isVisible()) + ? "refused" + : ""; + const deadline = Date.now() + 20_000; + await composer.fill(followUp); + for (;;) { + await screen.getByRole("button", "Send message").tap(); + await expect.poll(outcome, { timeout: Math.max(deadline - Date.now(), 1) }).not.toBe(""); + const seen = await outcome(); + if (seen !== "stop in progress") { + expect(seen).toBe("answered"); + break; + } + await screen.getByRole("button", "Dismiss").tap(); + // Dismissing clears the toast after its fade: a refusal shown before then would go too. + await expect(stopBusy).not.toBeVisible(); + // The refused text comes back into the composer. + await expect(composer).toHaveValue(followUp); + // A Stop that never settles must fail here, not resend until the runner's global timeout. + if (Date.now() >= deadline) { + throw new Error("the Stop did not settle within 20 s: every follow-up send was refused"); + } + } + + // The reply text shows while it still streams. An edit tapped mid-stream was refused as + // "History changed" in 1 of 6 phone runs. This test covers an edit after the reply, so wait + // for the stream to end. + await expect(screen.getByRole("button", "Stop streaming")).not.toBeVisible({ timeout: 20_000 }); await edit.tap(); const editBox = screen.getByRole("textbox", "Edit message");