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): fix multi-window auth-signout flake + tray-search reuse race (#3912)
Louis Beaumont50bee82ea15a
diff --git a/apps/screenpipe-app-tauri/e2e/specs/tray-search.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/tray-search.spec.tsindex 54282b4b9..b2aa5d722 100644--- a/apps/screenpipe-app-tauri/e2e/specs/tray-search.spec.ts+++ b/apps/screenpipe-app-tauri/e2e/specs/tray-search.spec.ts@@ -121,6 +121,17 @@ describe("Tray: Search window", function () {await invokeOrThrow("open_search_window", { query: null });await waitForWindowHandle("search", t(20_000));+ // Wait for the first search window to finish its initial /search load before+ // reusing it. The reuse path re-seeds the query by eval-ing+ // window.location.replace("/search/?q=…") (src-tauri window/show.rs); if that+ // fires before the initial load has committed, the replace is lost and the+ // ?q= query never seeds — the source of this spec's flake on slow CI.+ // Switching in and waiting for the input guarantees the webview is ready.+ await browser.switchToWindow("search");+ await (+ await $('input[placeholder*="search memory"]')+ ).waitForExist({ timeout: t(20_000) });+await invokeOrThrow("open_search_window", { query: "?q=tray-e2e" });await waitForWindowHandle("search", t(20_000));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 1ec70f35f..0c52ea981 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@@ -141,6 +141,49 @@ async function restoreFetch(): Promise<void> {});}+/** Install the /api/user mock in EVERY open window, not just home.+ *+ * The emitTo("home") deep-link targeting above keeps the LOGIN loadUser in the+ * mocked home window. But that only covers the deep-link path. After Phase A+ * writes the fake token into the SHARED settings store, the auto-refresh effect+ * (lib/hooks/use-settings.tsx, the effect keyed on settings.user?.token) fires+ * loadUser(fakeToken) in EVERY window. Non-home windows have no mock, so they+ * hit the real network, 401, and the global auth interceptor broadcasts+ * "screenpipe-auth-signout" — which clears the freshly-logged-in home window,+ * flaking Phase A (Linux/Windows worst, ~50%).+ *+ * Mocking the endpoint in every window keeps those auto-refresh loadUsers on a+ * 200 fake user: no 401, no cross-window sign-out. Restored per-window in+ * after() (restoreFetchAllWindows) so the patch can't leak into later specs. */+async function tuneUserFetchMockAllWindows(delayMs: number, email: string): Promise<void> {+ const start = await browser.getWindowHandle();+ for (const handle of await browser.getWindowHandles()) {+ try {+ await browser.switchToWindow(handle);+ await tuneUserFetchMock(delayMs, email);+ } catch {+ // window may have closed mid-iteration; best-effort+ }+ }+ await browser.switchToWindow(start).catch(() => {});+}++/** Undo tuneUserFetchMockAllWindows: restore window.fetch in every window so a+ * fake /api/user response cannot leak into later specs in the shared session. */+async function restoreFetchAllWindows(): Promise<void> {+ const start = await browser.getWindowHandle().catch(() => null);+ const handles = await browser.getWindowHandles().catch(() => [] as string[]);+ for (const handle of handles) {+ try {+ await browser.switchToWindow(handle);+ await restoreFetch();+ } catch {+ // best-effort+ }+ }+ if (start) await browser.switchToWindow(start).catch(() => {});+}+async function userFetchCalls(): Promise<number> {return (await browser.execute(() => ((window as unknown as Record<string, unknown>).__E2E_USER_CALLS as number) || 0,@@ -169,7 +212,10 @@ describe("Logout is not resurrected by an in-flight loadUser", function () {before(async () => {await waitForAppReady();await openHomeWindow();- await tuneUserFetchMock(0, FAKE_EMAIL);+ // Mock /api/user in every window (not just home) so non-home windows'+ // auto-refresh loadUser can't 401 and broadcast a session-clearing+ // sign-out mid-test. See tuneUserFetchMockAllWindows.+ await tuneUserFetchMockAllWindows(0, FAKE_EMAIL);await openAccountSettings();});@@ -184,7 +230,7 @@ describe("Logout is not resurrected by an in-flight loadUser", function () {} catch {// best-effort}- await restoreFetch().catch(() => {});+ await restoreFetchAllWindows().catch(() => {});await browser.execute(() => window.location.reload());await browser.waitUntil(