From 12dbb114aad72b89d17d6d1c668d8d4c3fdad2ae Mon Sep 17 00:00:00 2001 From: Diem Nguyen Date: Tue, 29 Sep 2026 15:59:30 -0700 Subject: [PATCH] test(desktop): fix flaky forum empty-draft replacement e2e (#7981) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary The `replacement=` cases (`add` and `publish`) of `forum source visit …: A→B→A retains source draft` in `forum-agent-invitation.spec.ts` are flaky. They fail at line 449 because the source draft still reads `@RemoteScout hello`. Cause: Playwright's `fill("")` on a contenteditable sets a DOM selection and then presses `Delete`. ProseMirror handles `Delete` with its own selection, which sometimes hasn't synced from the DOM yet. When that happens the key press does nothing, `onUpdate` never fires, and the clear is never recorded. I confirmed this with temporary logging: failing runs have no authored-content update after the fill. Non-empty `fill` uses `insertText`, which goes through ProseMirror's DOM input path, so it isn't affected. Fix (test only): - Clear the draft with `ControlOrMeta+a` followed by `Delete`, so ProseMirror owns the selection. - Assert the replacement text before navigating away. ### Related issue None found. The spec hasn't changed since #7125. This test failed in 10 of the last 40 CI runs of `Desktop Smoke E2E (2)`, for example #3700. ### Testing - `--repeat-each=100 --retries=0 --workers=4` on the two affected cases: - Before the fix: 14 of 200 runs failed at `:449`. - After the fix: 200 of 200 passed. - Full `forum-agent-invitation.spec.ts`: 19 passed. - Pre-push hooks passed (desktop typecheck and desktop tests). Signed-off-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz> Co-authored-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz> --- desktop/tests/e2e/forum-agent-invitation.spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/desktop/tests/e2e/forum-agent-invitation.spec.ts b/desktop/tests/e2e/forum-agent-invitation.spec.ts index b17f5fcc04..e3898085ba 100644 --- a/desktop/tests/e2e/forum-agent-invitation.spec.ts +++ b/desktop/tests/e2e/forum-agent-invitation.spec.ts @@ -430,8 +430,17 @@ for (const stage of ["add", "publish"] as const) { await expect( page.getByRole("button", { name: "Remove attachment" }), ).toBeVisible(); - if (replacement !== null) + if (replacement === "") { + // fill("") presses Delete over a DOM selection ProseMirror may not + // have synced yet; select through the editor's own keymap instead. + await page.getByTestId("message-input").click(); + await page.keyboard.press("ControlOrMeta+a"); + await page.keyboard.press("Delete"); + } else if (replacement !== null) { await page.getByTestId("message-input").fill(replacement); + } + if (replacement !== null) + await expect(page.getByTestId("message-input")).toHaveText(replacement); await navigate(1); await releaseForumGate(page); expect(