Skip to content

test(e2e): fix multi-window auth-signout flake (zz-logout-resurrect) + tray-search reuse race#3912

Merged
louis030195 merged 1 commit into
mainfrom
claude/fix-e2e-multiwindow-flake
Jun 9, 2026
Merged

test(e2e): fix multi-window auth-signout flake (zz-logout-resurrect) + tray-search reuse race#3912
louis030195 merged 1 commit into
mainfrom
claude/fix-e2e-multiwindow-flake

Conversation

@louis030195

Copy link
Copy Markdown
Collaborator

What

Fixes the two specs that have been intermittently reddening the E2E Tests workflow on main (Linux + Windows; macOS was unaffected). Both fixes are test-only, no product code changes.

This is the durable fix for the zz-logout-resurrect flake. Note: skipping/quarantining that spec was tried twice before and reverted, so this fixes the test harness instead.

Flake 1: zz-logout-resurrect (the dominant one, ~40% of runs)

The failure was always in Phase A (login setup), not in the in-flight-loadUser regression guard the spec exists to protect. The product code is correct; this was a multi-window test artifact.

sequenceDiagram
    participant T as Test
    participant H as Home window (mocked)
    participant O as Other window (NOT mocked)
    participant S as Shared settings store
    participant N as Real network

    T->>H: emitTo("home") deep-link login (fake token)
    H->>H: loadUser -> mock 200 -> user written
    H->>S: write user + token
    S-->>O: token changed (cross-window broadcast)
    O->>N: auto-refresh loadUser(fakeToken)
    N-->>O: 401 (fake token, real server)
    O->>S: auth interceptor -> user=null + emit("screenpipe-auth-signout")
    S-->>H: home session cleared
    Note over H: Phase A now sees "not logged in" -> FLAKE
Loading

The earlier emitTo("home") fix only kept the deep-link loadUser in the mocked home window. But the auto-refresh effect in lib/hooks/use-settings.tsx (keyed on settings.user?.token) fires loadUser in every window when the shared token changes, and those non-home calls hit the real network and 401.

Fix: mock /api/user in every window (tuneUserFetchMockAllWindows), restored per-window in after() (restoreFetchAllWindows) so the patch cannot leak into later specs in the shared session. Every auto-refresh loadUser now gets a 200 fake user, so no 401 and no cross-window sign-out.

Flake 2: tray-search "reuses the Search handle" (intermittent)

The product re-seeds the query on window reuse via window.location.replace("/search/?q=...") (src-tauri/.../window/show.rs). The second open_search_window could fire that replace before the first window finished its initial /search load, so the navigation was lost and ?q= never seeded.

Fix: wait for the first search window's input to exist (initial load committed) before reusing it.

Verification

The flake is Linux/Windows-specific, so it cannot be reproduced on a macOS dev box. Verification is this PR's E2E Tests run across all three platforms. I will re-run the E2E job a few times to confirm the flake is gone (a single green pass is not proof for a ~40% flake) before this is merged.

🤖 Generated with Claude Code

zz-logout-resurrect flaked ~40% on Linux/Windows in Phase A (the login
setup), not in the regression guard it exists to protect. After Phase A
writes the fake token into the SHARED settings store, every non-home
window's auto-refresh effect (lib/hooks/use-settings.tsx, keyed on
settings.user?.token) fires loadUser(fakeToken) against the real network,
gets a 401, and the global auth interceptor broadcasts
"screenpipe-auth-signout", which clears the just-logged-in home window. The
prior emitTo("home") fix only covered the deep-link login path, not the
auto-refresh path. Fix: mock /api/user in EVERY window (restored per-window
in after() so it can't leak into later specs). Test-only, no product change.

tray-search "reuses the Search handle" intermittently failed because the
reuse path re-seeds the query via window.location.replace("/search/?q=...")
(src-tauri window/show.rs); the second open_search_window could fire that
replace before the first window finished its initial load, losing it so the
?q= query never seeded. Fix: wait for the first search window's input to
exist before reusing it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@louis030195 louis030195 merged commit 50bee82 into main Jun 9, 2026
26 of 27 checks passed
@louis030195 louis030195 deleted the claude/fix-e2e-multiwindow-flake branch June 9, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant