Skip to content

fix(e2e): target deep-link login at home window only (zz-logout-resurrect flake)#3894

Merged
louis030195 merged 2 commits into
mainfrom
fix/e2e-logout-resurrect-windows-flake
Jun 7, 2026
Merged

fix(e2e): target deep-link login at home window only (zz-logout-resurrect flake)#3894
louis030195 merged 2 commits into
mainfrom
fix/e2e-logout-resurrect-windows-flake

Conversation

@louis030195

@louis030195 louis030195 commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Problem

zz-logout-resurrect.spec.ts failed intermittently on E2E — ~50% on Windows, occasionally on Linux, never on macOS — always at the Phase A login setup (:192):

Expected substring: "e2e-logout@screenpipe.test"
Received string:    "not logged in"

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 ran loadUser(api_key):

 deep-link login (global emit, fake token)
        |
        +--> HOME window:    loadUser -> /api/user  [MOCKED 200]  -> "logged in as e2e-logout@..."   <- waitUntil passes
        |
        +--> FOREIGN windows: loadUser -> /api/user  [REAL net]   -> 401
                                                          |
                                   auth interceptor: clearSession() + emit "screenpipe-auth-signout"
                                                          |
                                   writes user:null into the SHARED settings store (settingsStore.listen)
                                                          |
                                   HOME window clears -> "not logged in"   <- line 192 reads this, FAILS

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 global emit, so every loadUser stays in the one window that has the /api/user mock. 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.

Note: an earlier push tried mocking /api/user in every window by switching WebDriver windows — that poisoned the shared session (hung the after-hook, cascaded Failed to create a session). Reverted in favor of this targeted-emit approach.

🤖 Generated with Claude Code

…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>
@louis030195 louis030195 marked this pull request as draft June 7, 2026 03:13
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>
@louis030195 louis030195 changed the title fix(e2e): stop Windows flake in zz-logout-resurrect (foreign-window 401) fix(e2e): target deep-link login at home window only (zz-logout-resurrect flake) Jun 7, 2026
@louis030195 louis030195 marked this pull request as ready for review June 7, 2026 03:55
@louis030195 louis030195 merged commit 6479314 into main Jun 7, 2026
18 checks passed
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