YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
test(e2e): stabilize the flaky reload + overlay specs (shared robust reload helper) (#4220)
Louis Beaumont9585670e18fe
diff --git a/apps/screenpipe-app-tauri/e2e/helpers/test-utils.ts b/apps/screenpipe-app-tauri/e2e/helpers/test-utils.tsindex 7a3942cb9..8eb4bd65c 100644--- a/apps/screenpipe-app-tauri/e2e/helpers/test-utils.ts+++ b/apps/screenpipe-app-tauri/e2e/helpers/test-utils.ts@@ -48,6 +48,40 @@ export async function waitForAppReady(): Promise<void> {await browser.pause(t(3000));}+/**+ * Reload the current webview and wait for the Home page to re-render.+ *+ * Shared so the per-spec inline copies don't drift. The bare+ * `window.location.reload()` + poll pattern was flaky in CI: while the document+ * is being torn down, `browser.execute(...)` intermittently throws+ * "WebDriverError: Session ... not found" / "execution context destroyed", and+ * uncaught that rejects the `waitUntil` and reds the run as "home did not+ * re-render after reload". Trapping those transient errors inside the poll+ * (return false -> keep polling) makes the reload robust, matching the proven+ * home-page wait in `finishOpenHomeWindow`.+ */+export async function reloadAndWaitForHome(timeoutMs = t(30000)): Promise<void> {+ // The reload itself can race the execution-context teardown — ignore.+ await browser.execute(() => window.location.reload()).catch(() => {});+ await browser.waitUntil(+ async () => {+ try {+ return (await browser.execute(+ () => !!document.querySelector('[data-testid="home-page"]')+ )) as boolean;+ } catch {+ // Transient during the reload (session/context not ready) — retry.+ return false;+ }+ },+ {+ timeout: timeoutMs,+ interval: 500,+ timeoutMsg: 'home did not re-render after reload',+ }+ );+}+type ShowWindowPayload = { Home: { page: null } };async function finishOpenHomeWindow(): Promise<void> {diff --git a/apps/screenpipe-app-tauri/e2e/specs/main-overlay-visibility.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/main-overlay-visibility.spec.tsindex 06d99be2a..06de5bc54 100644--- a/apps/screenpipe-app-tauri/e2e/specs/main-overlay-visibility.spec.ts+++ b/apps/screenpipe-app-tauri/e2e/specs/main-overlay-visibility.spec.ts@@ -32,13 +32,19 @@ async function waitForAnyMainHandle(timeoutMs = t(12_000)): Promise<MainLabel> {async function expectMainOverlayVisible(expected: boolean, timeoutMs = t(15_000)): Promise<void> {await browser.waitUntil(async () => {- // Use Home as the invoke() context. Some surfaces (like Main) can be hidden- // and still have a handle, but Home is always a stable Tauri IPC origin.- if ((await browser.getWindowHandles()).includes("home")) {- await browser.switchToWindow("home");+ try {+ // Use Home as the invoke() context. Some surfaces (like Main) can be hidden+ // and still have a handle, but Home is always a stable Tauri IPC origin.+ if ((await browser.getWindowHandles()).includes("home")) {+ await browser.switchToWindow("home");+ }+ const visible = await invokeOrThrow<boolean>("e2e_main_overlay_visible");+ return visible === expected;+ } catch {+ // Transient during a window switch / IPC-not-ready — retry rather than+ // hard-failing the waitUntil (the fragility that intermittently reded CI).+ return false;}- const visible = await invokeOrThrow<boolean>("e2e_main_overlay_visible");- return visible === expected;}, {timeout: timeoutMs,interval: 250,diff --git a/apps/screenpipe-app-tauri/e2e/specs/updater-banner.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/updater-banner.spec.tsindex ea6188e17..877d5b265 100644--- a/apps/screenpipe-app-tauri/e2e/specs/updater-banner.spec.ts+++ b/apps/screenpipe-app-tauri/e2e/specs/updater-banner.spec.ts@@ -34,7 +34,13 @@import { existsSync } from "node:fs";import { saveScreenshot } from "../helpers/screenshot-utils.js";-import { openHomeWindow, waitForAppReady, waitForTestId, t } from "../helpers/test-utils.js";+import {+ openHomeWindow,+ reloadAndWaitForHome,+ waitForAppReady,+ waitForTestId,+ t,+} from "../helpers/test-utils.js";// A version far above any real release so the banner's dismissed-version gate// can never suppress it and later specs in the shared session never collide.@@ -53,16 +59,7 @@ describe("Update banner surfacing", function () {// variant is a single install button with no dismiss affordance. Reload the// webview to reset `isVisible` so the synthetic banner does not leak into// later specs that share this session.- await browser.execute(() => window.location.reload());- await browser- .waitUntil(- async () =>- (await browser.execute(- () => !!document.querySelector('[data-testid="home-page"]'),- )) as boolean,- { timeout: t(30_000), interval: 500, timeoutMsg: "home did not re-render after reload" },- )- .catch(() => {});+ await reloadAndWaitForHome().catch(() => {});});it("surfaces the restart-to-update banner on update-available, without relaunching", async () => {diff --git a/apps/screenpipe-app-tauri/e2e/specs/zz-account-stale-subscription.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/zz-account-stale-subscription.spec.tsindex c1641f0e4..190b17f60 100644--- a/apps/screenpipe-app-tauri/e2e/specs/zz-account-stale-subscription.spec.ts+++ b/apps/screenpipe-app-tauri/e2e/specs/zz-account-stale-subscription.spec.ts@@ -43,7 +43,13 @@import { existsSync } from "node:fs";import { saveScreenshot } from "../helpers/screenshot-utils.js";-import { openHomeWindow, waitForAppReady, waitForTestId, t } from "../helpers/test-utils.js";+import {+ openHomeWindow,+ reloadAndWaitForHome,+ waitForAppReady,+ waitForTestId,+ t,+} from "../helpers/test-utils.js";import { invoke } from "../helpers/tauri.js";const FAKE_TOKEN = "e2e-fake-token-stale-subscription";@@ -174,28 +180,18 @@ async function loginAsSubscriber(): Promise<boolean> {}async function reloadHomeToAccount(): Promise<void> {- await browser.execute(() => window.location.reload());- await browser.waitUntil(- async () =>- (await browser.execute(- () => !!document.querySelector('[data-testid="home-page"]'),- )) as boolean,- { timeout: t(30_000), interval: 500, timeoutMsg: "home did not re-render after reload" },- );+ await reloadAndWaitForHome();await openAccountSettings();}-// QUARANTINED 2026-06-16 (Louis CI unblock): this spec is flaky in CI. Its-// `window.location.reload()` intermittently loses the webdriver session-// ("WebDriverError: Session ... not found") and then times out in-// `reloadHomeToAccount` ("home did not re-render after reload"), reding E2E on-// all three platforms (it was the ONLY failing spec once the coverage-map +-// Windows-ORT fixes landed). It fails on the reload infrastructure BEFORE the-// card assertion, so no product regression is being hidden. The spec was added-// in #4172 but merged while E2E was already red (a missing coverage-map entry),-// so it was never validated green. Re-enable by dropping `.skip` once the-// reload is stabilized (e.g. a more robust re-render signal than `home-page`,-// or a reload that can't drop the session).+// QUARANTINED (describe.skip): the shared `reloadAndWaitForHome` helper stabilized+// the OTHER reload specs (zz-logout-resurrect, updater-banner) and main-overlay,+// which now pass green, but this one still times out in `reloadHomeToAccount` even+// with the transient-trapping poll. After the all-window fetch-mock plus+// secret-store token clear, the reload genuinely doesn't re-render `home-page`+// within 30s (not just a transient error), so it needs local wdio debugging of+// that specific sequence. Kept skipped so it doesn't red E2E; the helper and the+// other three fixes still ship.describe.skip("Account never shows an active plan card under a not-logged-in header", function () {this.timeout(180_000);@@ -222,16 +218,7 @@ describe.skip("Account never shows an active plan card under a not-logged-in hea// best-effort}await forEachWindow(() => restoreFetch()).catch(() => {});- await browser.execute(() => window.location.reload());- await browser- .waitUntil(- async () =>- (await browser.execute(- () => !!document.querySelector('[data-testid="home-page"]'),- )) as boolean,- { timeout: t(30_000), interval: 500, timeoutMsg: "home did not re-render after reload" },- )- .catch(() => {});+ await reloadAndWaitForHome().catch(() => {});});it("hides the cloud plan card once the token is gone but cloud_subscribed lingers", async () => {diff --git a/apps/screenpipe-app-tauri/e2e/specs/zz-logout-resurrect.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/zz-logout-resurrect.spec.tsindex 1acfd4372..4e8101bbe 100644--- a/apps/screenpipe-app-tauri/e2e/specs/zz-logout-resurrect.spec.ts+++ b/apps/screenpipe-app-tauri/e2e/specs/zz-logout-resurrect.spec.ts@@ -40,7 +40,13 @@import { existsSync } from "node:fs";import { saveScreenshot } from "../helpers/screenshot-utils.js";-import { openHomeWindow, waitForAppReady, waitForTestId, t } from "../helpers/test-utils.js";+import {+ openHomeWindow,+ reloadAndWaitForHome,+ waitForAppReady,+ waitForTestId,+ t,+} from "../helpers/test-utils.js";const FAKE_TOKEN = "e2e-fake-token-logout-resurrect";const FAKE_EMAIL = "[email protected]";@@ -184,6 +190,50 @@ async function restoreFetchAllWindows(): Promise<void> {if (start) await browser.switchToWindow(start).catch(() => {});}+/** Make every PEER window answer /api/user with a hard 401 so its auto-refresh+ * retry loop STOPS and it can no longer 200-write the fake user back and+ * broadcast it to home after logout. Home keeps its slow 200 mock (its in-flight+ * loadUser is the thing under test).+ *+ * Why a 401 MOCK and not the previous clear-token + restoreFetch():+ * - The auto-refresh effect (use-settings.tsx ~1158) keys on the IN-MEMORY+ * settings.user.token, not the secret store — clearing the secret token does+ * not stop a peer that already has the token in memory.+ * - That loop only stops the retries on a literal 401/403 (use-settings.tsx+ * ~1176); a transient non-401 network error keeps it retrying. Restoring REAL+ * fetch therefore left the loop alive on a contended macOS runner and the+ * peer kept resurrecting the session (the flake we still saw).+ * A deterministic 401 both stops the loop AND, via the auth interceptor,+ * reinforces sign-out — so even a peer that transiently wrote the user back gets+ * re-cleared. Best-effort + resilient to the macOS WebDriver session dropping a+ * switchToWindow mid-loop. */+async function block401InPeerWindows(): Promise<void> {+ const home = await browser.getWindowHandle().catch(() => null);+ for (const handle of await browser.getWindowHandles().catch(() => [] as string[])) {+ if (handle === home) continue;+ try {+ await browser.switchToWindow(handle);+ await browser.execute(() => {+ const w = window as unknown as Record<string, unknown>;+ const orig = (w.__E2E_ORIG_FETCH as typeof window.fetch) || window.fetch.bind(window);+ if (!w.__E2E_ORIG_FETCH) w.__E2E_ORIG_FETCH = orig;+ window.fetch = (input: RequestInfo | URL, init?: RequestInit) => {+ const url =+ typeof input === "string" ? input : (input as Request)?.url ?? String(input);+ if (url.includes("/api/user")) {+ return Promise.resolve(new Response("{}", { status: 401, statusText: "Unauthorized" }));+ }+ return orig(input, init);+ };+ w.__E2E_FETCH_PATCHED = true;+ });+ } catch {+ // window may have closed or the macOS session hiccuped mid-iteration+ }+ }+ if (home) await browser.switchToWindow(home).catch(() => {});+}+async function userFetchCalls(): Promise<number> {return (await browser.execute(() => ((window as unknown as Record<string, unknown>).__E2E_USER_CALLS as number) || 0,@@ -276,16 +326,7 @@ describe("Logout is not resurrected by an in-flight loadUser", function () {// best-effort}await restoreFetchAllWindows().catch(() => {});- await browser.execute(() => window.location.reload());- await browser- .waitUntil(- async () =>- (await browser.execute(- () => !!document.querySelector('[data-testid="home-page"]'),- )) as boolean,- { timeout: t(30_000), interval: 500, timeoutMsg: "home did not re-render after reload" },- )- .catch(() => {});+ await reloadAndWaitForHome().catch(() => {});});it("stays logged out after one click even when a slow loadUser resolves afterwards", async () => {@@ -324,9 +365,19 @@ describe("Logout is not resurrected by an in-flight loadUser", function () {const logoutBtn = await waitForTestId("account-logout-button", 8_000);await logoutBtn.click();- // Logout clears the session immediately.+ // Immediately 401 every PEER window's /api/user so its auto-refresh retry+ // loop stops and can't 200-resurrect the session after logout (the+ // macOS/webkit flake). Done right after the click — before the "not logged+ // in" wait — so the race window between logout and neutralization is minimal;+ // if a peer did transiently resurrect, its own 401 now drives a sign-out that+ // re-clears home, which the wait below then observes.+ await block401InPeerWindows();++ // Logout clears the session. Generous timeout: under CI load the logout+ // click -> updateSettings -> React re-render can take a few seconds, and a+ // transient peer resurrection may need its 401-driven sign-out to land.await browser.waitUntil(async () => (await loginStatusText()).includes("not logged in"), {- timeout: t(8_000),+ timeout: t(20_000),interval: 200,timeoutMsg: "logout did not clear the session",});