test(e2e): fix multi-window auth-signout flake (zz-logout-resurrect) + tray-search reuse race#3912
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-resurrectflake. 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" -> FLAKEThe earlier
emitTo("home")fix only kept the deep-linkloadUserin the mocked home window. But the auto-refresh effect inlib/hooks/use-settings.tsx(keyed onsettings.user?.token) firesloadUserin every window when the shared token changes, and those non-home calls hit the real network and 401.Fix: mock
/api/userin every window (tuneUserFetchMockAllWindows), restored per-window inafter()(restoreFetchAllWindows) so the patch cannot leak into later specs in the shared session. Every auto-refreshloadUsernow 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 secondopen_search_windowcould fire thatreplacebefore the first window finished its initial/searchload, 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