Skip to content

fix(e2e): WebKit admin sign-in — wait for hydration, verify the session identity (#1178) - #1191

Merged
frankbria merged 2 commits into
mainfrom
fix/1178-webkit-admin-signin
Nov 9, 2026
Merged

frankbria merged 2 commits into
mainfrom
fix/1178-webkit-admin-signin

Conversation

@frankbria

Copy link
Copy Markdown
Owner

Closes #1178.

Cause

On WebKit, signInAs typed the admin address before React hydrated /auth/signin. The form is controlled and prefilled with the default test user, so hydration put [email protected] back in the field. The admin password was then posted for that user. The credentials callback still answered 200 (with ?error=CredentialsSignin in its body), so the helper returned a signed-out context. The specs failed later and looked unrelated: /admin 307, and "no apiToken" in plan-limit. Chromium hydrates fast enough to hide the race, and the default user can't hit it because their address is the prefill.

Evidence (WebKit probe): the posted body was email=test%40narrativeml.com… and the response was {"url":"…/auth/signin?error=CredentialsSignin&code=credentials"}. No authjs.session-token cookie was set.

Fix (e2e/helpers/apiAuth.ts, shared by global-setup, admin-guard and plan-limit)

  • Before typing, wait for the /api/auth/session fetch that SessionProvider makes once it has mounted.
  • After the callback, read /api/auth/session and require its email to be the requested one. Otherwise throw signInAs(<email>): signed in as <who> instead.

Verification

  • --grep "admin|plan" on webkit-full and chromium-full: 8/8 passed (failed 2/3 before).
  • Full @smoke on webkit-full + chromium-smoke: 90 passed, 1 skipped.
  • Mutation: removing the hydration wait makes WebKit fail at once with signInAs(admin-e2e@…): signed in as nobody instead.

Review

Review chain: REQUEST_CHANGES.

  • MAJOR, "SessionProvider gets session={null} so it never fetches; the wait will time out": refuted. Probes on both engines logged the /api/auth/session fetches on the fresh sign-in page, and 90 smoke tests ran through the wait with none timing out. The new postcondition fails loudly if that signal ever stops arriving in time.
  • MINOR, "a cookie-name check misses chunked .0 cookies": taken. The check is now the session's email, which covers every cookie form and names the wrong identity.

🤖 Generated with Claude Code

frankbria and others added 2 commits November 8, 2026 19:19
…#1178)

WebKit typed the admin address before React hydrated the sign-in form,
which reset it to the prefilled default user; the admin password then
failed, the callback still answered 200, and the specs failed later as
a 307 or a missing apiToken. Wait for SessionProvider's post-mount
session fetch before typing, and throw when no session cookie is set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#1178)

Review follow-up: checking the session's email instead of a cookie name
also covers chunked and __Secure- cookies, and names the wrong identity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@frankbria

Copy link
Copy Markdown
Owner Author

Third-party review (review chain) — first commit b6acf64

Findings

  • CRITICAL: None.

  • MAJOR — The hydration wait will time out. apiAuth.ts:56 assumes SessionProvider fetches /api/auth/session after mounting. However, RootLayout supplies session={null} for an unauthenticated request. The installed Auth.js treats null as an already-synchronized initial value, so its mount effect does not fetch the session. SSR’s auth() call is server-side and cannot satisfy Playwright’s response listener. An earlier navigation cannot satisfy it either because this is a fresh page and the listener is installed before its first navigation. Use an explicit form-hydration sentinel; even a provider effect is not a rigorous descendant-hydration barrier under selective hydration.

  • MINOR — The cookie assertion rejects valid chunked sessions. apiAuth.ts:71 correctly accepts both authjs.session-token and __Secure-authjs.session-token, but rejects chunked names such as authjs.session-token.0 and __Secure-authjs.session-token.0. Conversely, endsWith could accept an unrelated prefixed cookie. Match the two exact base names with an optional .<digits> suffix. Stronger still, query /api/auth/session after login and verify the authenticated email, which proves the cookie is usable and belongs to the requested identity.

Verdict: the cookie check improves failure locality, but the proposed hydration barrier breaks signInAs in the current provider configuration.

🟢 Review complete; one major synchronization defect requires correction

REQUEST_CHANGES

Dispositions are in the PR body; follow-up 793eee2 takes the MINOR.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T02:26:20.280815Z 793eee2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review

Small, focused e2e helper fix. No blocking issues.

Correctness

  • Registering waitForResponse in Promise.all with goto is the right way to avoid missing the response. r.url().includes('/api/auth/session') could also match /api/auth/session?... variants. That's fine. It will also match a session fetch fired by an earlier navigation, but this is a fresh context, so it's safe.
  • Waiting for the session fetch is a heuristic for hydration. It assumes SessionProvider fetches on mount in every browser and that the fetch happens after the controlled form's initial state is set. If the app ever seeds the session server-side (SessionProvider session={...}), no fetch fires and this will time out after 20s. A comment noting that dependency is already there, which is good. A more direct signal, such as a hydration marker or expect(input).toHaveValue(defaultEmail) before filling, would be more robust. Alternatively, use fill followed by expect(...).toHaveValue(email) right before clicking, to catch a reset.
  • The post-sign-in check is a real improvement. It makes a refused sign-in fail loudly, which matches the repo's "assertions must be able to fail" rule. context.request.get('/api/auth/session') relies on baseURL being set on the context. It looks like it is, since page.goto('/auth/signin') already uses a relative path. Please confirm .json() can't throw on a non-JSON error response. A res.ok() check with a clearer message would help diagnosis.
  • The cast as { user?: ... } | null is fine. The email comparison is case-sensitive, so a backend that normalizes case would false-fail. Consider comparing lowercased.

Tests

Style

  • The inline cast line is long. Prettier or lint may want it wrapped.

Security and performance: no concerns. This is test-only code, and the extra request is negligible.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Third Party Review — Kimi

✅ Third Party Review: no defects found.

Scope checked: the hydration wait's listener-before-navigation ordering, context.request baseURL/cookie sharing, the session-email postcondition against the credentials provider's verbatim email return (auth.ts, lib/test-credentials.ts), and caller emails in global-setup.ts / admin-guard.spec.ts / plan-limit.spec.ts. CI E2E Smoke Tests is green on the head commit. Prior chains already covered the wait-timeout concern (empirically refuted), cookie-name shapes (superseded by the email check), and the .ok()/case-sensitivity diagnostics — not repeated here.

Model: k3[1m]

@frankbria
frankbria merged commit 8aa7b25 into main Nov 9, 2026
17 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Reviewer failover

  • Codex: ⚠️ failed (failure) for a reason other than quota — investigate the job run
  • Kimi: reviewed
  • glm-5.2: not run (no secret, or an earlier reviewer finished)

@frankbria
frankbria deleted the fix/1178-webkit-admin-signin branch November 9, 2026 02:35
frankbria added a commit that referenced this pull request Nov 9, 2026
…lated sign-ins (#1198)

Since #1191 moved page.close() after an extra session request, three CI
smoke runs hung in global setup for the full 30-minute job timeout,
right after saving the default user's state. page.close() is the one
call there with no timeout, and it now ran while the post-login /upload
page was loading (compiled cold on CI). Close it straight after the
credentials callback again, as before #1191, and check the session over
the context's request API. Each isolated sign-in now fails after 60s,
naming the user, instead of holding the job.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[P3.63] [testing] WebKit: the admin tenant's session fails admin-guard and plan-limit smoke

1 participant