fix(e2e): target deep-link login at home window only (zz-logout-resurrect flake)#3894
Merged
Merged
Conversation
…01 signed app back out) The deep-link login in this spec broadcasts loadUser() to every window, but the test only mocked /api/user in the home window. A foreign window then hit the real network with the fake token, got a 401, and the auth interceptor broadcast "screenpipe-auth-signout", clearing the freshly-logged-in home window too. On slow Windows CI that 401 landed between the "logged in as" wait and the email assertion, so Phase A setup flapped to "not logged in" and the spec failed about half the time on Windows only (Linux/macOS always passed). Install the /api/user mock in every window (forEachWindow helper) so no real 401 can fire, and restore fetch everywhere on teardown so the mock can't leak into the next spec in the shared session. Also tighten Phase A's wait to poll for the email itself, not just "logged in as", as defense in depth. The core Phase B regression assertion is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replaces the earlier forEachWindow approach, which poisoned the shared
WebDriver session (switching across ~7 windows hung the after-hook and
cascaded "Failed to create a session" to later specs).
Root cause of the flake: the deep-link login used a global emit, so every
window's deep-link handler ran loadUser(api_key). Only the home window has the
/api/user mock; the others hit the real network with the fake token, 401, and
the auth interceptor broadcast "screenpipe-auth-signout" -> wrote user:null
into the shared settings store -> cleared the freshly-logged-in home window.
On slow CI that landed mid-login, so Phase A flapped to "not logged in"
(~50% on Windows, also seen on Linux).
Fix: emit the deep-link with emitTo("home", ...) so every loadUser stays in
the one mocked window. No foreign 401, no cross-window signout, no window
switching. The resurrection race this spec guards is per-window (home fires
the slow loadUser, home logs out, home's generation guard aborts the late
write), so coverage is unchanged. Also poll Phase A for the email itself, not
just "logged in as", as defense in depth.
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.
Problem
zz-logout-resurrect.spec.tsfailed intermittently on E2E — ~50% on Windows, occasionally on Linux, never on macOS — always at the Phase A login setup (:192):It has been flaky since it landed (passed on 3 of the last 7 main commits, failed on 4), so it reds
main's E2E roughly every other merge.Root cause (a real cross-window race)
The deep-link login used a global
emit, so every window's deep-link handler ranloadUser(api_key):On slower CI the foreign-window 401 lands between the
waitUntil("logged in")and the email assertion, so Phase A flaps to logged-out.Fix
Emit the deep-link with
emitTo("home", ...)instead of the globalemit, so everyloadUserstays in the one window that has the/api/usermock. No foreign 401, no cross-window sign-out, no window switching.The resurrection race this spec guards is per-window (home fires the slow
loadUser, home clicks logout, home's generation guard must abort the late write), so coverage is unchanged. Also polls Phase A for the email itself (not just "logged in as") as defense in depth.Test-only change. No product code touched.
🤖 Generated with Claude Code