Skip to content

OCPBUGS-105789: Recover expired Playwright sessions via auto re-login - #610

Closed
rhamilto wants to merge 1 commit into
OCPBUGS-105609from
OCPBUGS-105789
Closed

OCPBUGS-105789: Recover expired Playwright sessions via auto re-login#610
rhamilto wants to merge 1 commit into
OCPBUGS-105609from
OCPBUGS-105789

Conversation

@rhamilto

Copy link
Copy Markdown
Owner

Analysis / Root cause:

The Playwright e2e suite authenticates exactly once, in the setup projects (admin-auth.setup.ts, developer-auth.setup.ts), and freezes the session into a storageState snapshot. Every test project loads that static snapshot (playwright.config.ts) and nothing ever re-authenticates — performLogin is only referenced by the two setup files.

When the OpenShift OAuth token expires during a long run, subsequent page.goto() calls silently redirect to the login page, and tests hang waiting for elements (e.g. user-dropdown-toggle, #page-sidebar) that never appear, failing with generic toBeVisible/test-timeout errors. This showed up as widespread login-page hangs in CI.

Jira: https://redhat.atlassian.net/browse/OCPBUGS-105789

Solution description:

Add a self-healing auth fixture that overrides Playwright's built-in page fixture:

  • e2e/fixtures/auth-fixture.ts (new) — attaches a main-frame framenavigated listener that detects when a navigation lands on the login page and transparently re-runs performLogin for the active persona, then re-saves storageState so later tests reuse the fresh session. Re-entrancy is guarded via a WeakMap so the login flow's own navigations don't recurse, and it logs a warning when recovery fires so future occurrences are visible in CI logs.
  • e2e/setup/login-helper.ts — adds isOnLoginPage() and resolveCredentialsForStorageState() (dispatches to the existing getAdminCredentials()/getDeveloperCredentials() helpers based on the project's storage-state filename).
  • e2e/fixtures/index.ts — wires recovery into the shared page fixture. Since every spec imports test from here, coverage is suite-wide with no per-test changes.

Auth-disabled clusters and unset developer credentials cause recovery to no-op safely.

Note: This PR is based on OCPBUGS-105609 (not yet merged) because that branch refactors the same setup/login helpers. It targets the OCPBUGS-105609 branch so the diff shows only this change; it will be retargeted to main once OCPBUGS-105609 merges.

Screenshots / screen recording:

Test setup:

Requires a cluster whose OAuth access-token lifetime is shorter than the full e2e run so the session expires mid-run; the recovery path then re-authenticates transparently.

Test cases:

  • Full Playwright e2e run outlasting the OAuth token: post-expiry tests recover instead of hanging on the login page.
  • Admin and developer personas each re-authenticate with the correct credentials.
  • Auth-disabled cluster: recovery no-ops, tests unaffected.
  • Unset developer credentials: recovery no-ops without error.

Browser conformance:

  • Chrome

Additional info:

Test-infrastructure only — no product/runtime code changes.

Reviewers and assignees:

🤖 Generated with Claude Code

The Playwright e2e suite authenticates once in the setup projects and
freezes the session into a storageState snapshot that every test reuses.
Nothing re-authenticates, so when the OpenShift OAuth token expires during
a long run, navigations silently redirect to the login page and tests hang
waiting for elements that never appear.

Add a self-healing auth fixture that overrides the built-in page fixture:
a main-frame navigation listener detects when a navigation lands on the
login page and transparently re-runs performLogin for the active persona
(resolved from the project storageState path), then refreshes the stored
session so later tests reuse the fresh state. Re-entrancy is guarded so
the login flow's own navigations don't recurse.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rhamilto

Copy link
Copy Markdown
Owner Author

/hold for openshift#16953 to merge first

@rhamilto

Copy link
Copy Markdown
Owner Author

Wrong base — reopening against openshift/console:main.

@rhamilto rhamilto closed this Aug 11, 2026
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