From fd57e82d902fe0a1991b6b8227e586a451a03394 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Tue, 17 Nov 2026 13:37:28 +1100 Subject: [PATCH] test(browser): deflake relay-recovery and solo-legacy-invitation Two WebKit journeys fail now and then in CI on branches that cannot affect them. Both are races in the tests, not product defects. This changes the two spec files only; no production code. relay-recovery.spec.mjs: wait for the open channel's own refused read The test cuts the network, waits for the open channel's catch-up read to meet the outage, jumps the clock 30 s and expects the connection notice to stay up. The wait accepted a refused /query from any community. CI traces show the second community's background reads refused first, so the clock jumped before the open channel's read was refused. The notice then cleared once the live socket returned, and the later refusal started a fresh 30 s timer that the test's clock never advances. The failure is toBeInViewport "element(s) not found" on the notice, for example run 43995560292 job 133746953063 (webkit 5/18). It began after PR #3459 added a background session for other communities. The wait now passes only when a refused primary /query carries the open channel's timeline head. The filter test is the one isChannelHead uses in src/features/relay/session.ts, depth_limit clause included. The comment above the wait already asked for this; the condition now does what it says. solo-legacy-invitation.spec.mjs: seed the colour mode before boot Each colour-mode pass did goto, a localStorage write, then reload about 40 ms later, while the app was still booting. In WebKit that reload can fail the document request with "WebKit encountered an internal error" (run 43995560292 job 133746953195, webkit 6/18). PR #1972 fixed the same pattern in settings.spec.mjs and account-profile.spec.mjs. As there, the mode is now written by an init script before the document loads, and the boot reload is gone. The second pass adds a second script; scripts run in the order added, so the last mode wins. The reload the test is about, after Retry, is unchanged, and the existing data-color-mode assertion still proves each pass booted in its mode. Not touched: find-on-screen.spec.mjs. Its race is fixed by a commit in open PR #3647. Evidence. All local, macOS 27.2, Playwright 1.63.0, on 23d1d7045b plus this change, with --no-deps and the config's two workers. Hosted CI runs Linux WebKit and was not run. relay-recovery, forced ordering. Temporary copies of the spec outside the repository, each with the same two additions: a refused second-community /query recorded at the moment of the outage, and a one second pause before the toBeInViewport assertion, as on a slower runner. - Previous wait (the spec at 23d1d7045b): 20 of 20 fail, 10 Chromium and 10 WebKit, every one at the toBeInViewport assertion with "element(s) not found", the CI error. - New wait (the spec in this commit): 20 of 20 pass, 10 Chromium and 10 WebKit. relay-recovery, unforced. The committed spec with --repeat-each=10: 20 of 20 pass, 10 Chromium and 10 WebKit. solo-legacy-invitation. The committed spec with --repeat-each=10: 20 of 20 pass, 10 Chromium and 10 WebKit. There is no fail-before run: the CI failure has not been reproduced on macOS WebKit, so these runs show the journey still works, not that the flake is gone. That proof is the error staying absent from CI. One guard check for the new seeding, in a temporary copy with the init script removed: the "dark" pass fails on both engines at the data-color-mode assertion (expected "dark", received "light"). So the init script is what sets the mode, and that assertion is live. Static checks, in the new worktree: - pnpm typecheck (tsc --noEmit) passed. - pnpm lint (biome lint --error-on-warnings plus the icon check) passed. It reports 39 infos, none in the touched files. - biome format on the two files reports no changes. - git diff --check is clean. Not run: the rest of the browser suite, the unit tests, and any hosted CI job. Signed-off-by: Matt Toohey Co-Authored-By: Claude Fable 5.2 --- tests/browser/relay-recovery.spec.mjs | 28 +++++++++++++++---- tests/browser/solo-legacy-invitation.spec.mjs | 7 +++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/browser/relay-recovery.spec.mjs b/tests/browser/relay-recovery.spec.mjs index 9d07d075ea..c91bfa22fe 100644 --- a/tests/browser/relay-recovery.spec.mjs +++ b/tests/browser/relay-recovery.spec.mjs @@ -16,6 +16,8 @@ test("relay reads recover automatically after the network returns", async ({ // refused by the broker (503), so saves stay behind the edge page from the // outage on. let slept = false; + // The open channel's own catch-up read was refused. + let headRefused = false; app.report.relayFailures = []; await page.route("**/api/relay/**", async (route) => { const url = route.request().url(); @@ -24,6 +26,22 @@ test("relay reads recover automatically after the network returns", async ({ offline || (slept && pathname.endsWith("/read-state-publish")); if (!refused || pathname.endsWith("/session")) return route.fallback(); app.report.relayFailures.push(url); + // The same shape the session treats as a channel's timeline head. + if ( + pathname.endsWith("/primary/query") && + route + .request() + .postDataJSON() + .some( + (filter) => + filter["#h"]?.includes("alpha") && + filter.top_level === true && + filter.until === undefined && + filter.depth_limit === undefined && + filter.kinds?.includes(9), + ) + ) + headRefused = true; await route.fulfill({ status: 403, contentType: "text/html", @@ -56,12 +74,10 @@ test("relay reads recover automatically after the network returns", async ({ exact: true, }); // Wait for the channel's catch-up read to meet the outage. An earlier - // failure, such as presence, can recover once the broker's own relay - // socket returns, and jumping the clock on it would leave the notice to - // clear while the network is still down. - await expect - .poll(() => app.report.relayFailures.some((url) => url.endsWith("/query"))) - .toBe(true); + // failure, such as presence or another community's read, can recover once + // the broker's own relay socket returns, and jumping the clock on it would + // leave the notice to clear while the network is still down. + await expect.poll(() => headRefused).toBe(true); // A short outage, like waking from sleep, says nothing. await expect(notice).toHaveCount(0); await page.clock.fastForward(30_000); diff --git a/tests/browser/solo-legacy-invitation.spec.mjs b/tests/browser/solo-legacy-invitation.spec.mjs index 0369a203bb..5ceae241c3 100644 --- a/tests/browser/solo-legacy-invitation.spec.mjs +++ b/tests/browser/solo-legacy-invitation.spec.mjs @@ -149,12 +149,13 @@ test("Outbox Retry reconciles a recorded then removed Solo invitation without re const summary = panel.locator("summary").filter({ hasText: /^Outbox ยท/ }); const outbox = summary.locator(".."); for (const mode of ["dark", "light"]) { - await page.goto(app.origin); - await page.evaluate( + // Seed before boot: a reload during boot can fail the document request + // in WebKit. Later scripts run after earlier ones, so the last mode wins. + await page.addInitScript( (mode) => localStorage.setItem("buzz-appearance.v1", mode), mode, ); - await page.reload(); + await page.goto(app.origin); await expect(page.locator("html")).toHaveAttribute("data-color-mode", mode); await openPage(page, "Messages"); await page