Skip to content

refactor(playwright): one place that builds a signed-in page - #33218

Merged
chirag-madlani merged 3 commits into
flake/2-timeout-diagnosticsfrom
flake/3-signed-in-page-fixtures
Sep 28, 2026
Merged

chirag-madlani merged 3 commits into
flake/2-timeout-diagnosticsfrom
flake/3-signed-in-page-fixtures

Conversation

@chirag-madlani

@chirag-madlani chirag-madlani commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Stack 3 of 4. Targets #33217.

Deduplication

e2e/fixtures/pages.ts and support/fixtures/userPages.ts were near-identical copies of the same role-page fixtures, and had already drifted — one had viewOnlyPage, the other did not. userPages.ts now owns every role page and all the construction logic; pages.ts adds only the page → adminPage alias, which is the one behaviour that genuinely differs.

The missing sanctioned path

Specs kept hand-rolling their own account because there was nowhere else to go. support/fixtures/isolatedUser.ts adds:

Fixture Scope Use when
isolatedUserPage + isolatedUser one account per worker, fresh page per test the test needs an account that is not a seeded role but does not modify it
freshUserPage new account per test the test mutates the account it is signed in as

Both create and delete the account in fixture teardown, so the beforeAll + array + afterAll shape from #33216 cannot be written by accident.

UserClass.signIn()

Establishes the same session as login() with one POST instead of nine UI interactions. login() drives the form: navigate to /signin, wait, fill, Tab, fill, click, await the response, await the redirect, dismiss the getting-started dialog, collapse the sidebar. The suite does that ~290 times and none of it is what the tests are testing.

Both paths funnel through the same completeSignIn() — conditional reads off, dialog dismissed, sidebar collapsed — so they differ in how the session was established and nothing else. That last one matters: the sidebar collapse changes page geometry, so a sign-in path that skipped it would move every locator in the spec.

The mechanism is assembled from pieces already load-bearing here — the login request is the one createAdminApiContext makes (base64 password, matching the UI's btoa), and setToken is the exact inverse of the getToken that auth.setup.ts reads back after a real sign-in. signInViaApi asserts the app shell rendered, so a session the app refuses fails there naming the user, rather than timing out somewhere unrelated.

auth.setup.ts

Now takes that path too. Setup drops from 50.4s to 25.6s and still writes all eight storage states.

RoleFixtureSessions.spec.ts asserts each of those eight yields a signed-in page — the contract every lane depends on, which previously failed far from its cause when broken. It has already earned its keep twice: it caught expired storage states by name instead of letting eight unrelated specs fail on missing elements.

Verification (live server)

  • auth.setup from a wiped .auth/: all 8 states, 26.6s
  • RoleFixtureSessions 8/8; fresh user with a generated password signs in in 7.2s with the sidebar contract preserved
  • performUserLogin returns a page signed in as that user, not admin
  • 262 passed across RoleFixtureSessions + ExplorePageRightPanel + GlossaryPermissions + TaskComments

🤖 Generated with Claude Code

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with only the existing non-blocking isolated-user cleanup concern still outstanding.

Findings

  1. P2 Account cleanup can be skipped ▶
Summary

Refactors Playwright authentication and role-page fixtures around a single API-backed sign-in path.

  • Consolidates seeded role-page construction in support/fixtures/userPages.ts.
  • Adds worker- and test-scoped isolated-user fixtures with account teardown.
  • Uses API sign-in while preserving the existing post-login page contract.
  • Validates all generated role storage states with a dedicated session test.
  • Updates Playwright guidance and generated impact mappings.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[auth.setup.ts] --> B[UserClass.signIn]
  C[isolatedUser fixtures] --> B
  D[performUserLogin] --> B
  B --> E[signInViaApi]
  E --> F[POST /api/v1/auth/login]
  E --> G[Persist token in browser storage]
  B --> H[completeSignIn]
  H --> I[Dismiss dialog and collapse sidebar]
  A --> J[Saved role storage states]
  J --> K[userPages role fixtures]
  K --> L[pages.ts aliases page to adminPage]
Loading

Reviews (18) · Last reviewed commit: "fix(playwright): keep the OM_SESSION coo..."

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs UI UI specific issues labels Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 766 → 766
- 0 added, 0 removed, 5 changed spec-list

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/userPages.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/tokenStorage.ts
  openmetadata-ui/src/main/resources/ui/src/components/MyData/LeftSidebar/LeftSidebar.component.tsx
  openmetadata-ui/src/main/resources/ui/src/components/Settings/Users/UserProfileIcon/UserProfileIcon.component.tsx
  openmetadata-ui/src/main/resources/ui/src/generated/entity/data/table.ts

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

const user = new UserClass(undefined, isolatedUserOptions.isAdmin);
await user.create(apiContext);

const loginPage = await browser.newPage();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Account cleanup can be skipped

Both isolated-user fixtures create the backend account before entering the try/finally that deletes it. If browser.newPage() fails—for example, after a browser crash—the fixture exits without deleting the generated user. Move page creation inside the protected block and make page closing conditional so account deletion still runs when page creation fails. The same issue occurs in freshUserPage.

Comment on lines +126 to +140
await user.create(apiContext);

const loginPage = await browser.newPage();

try {
await installServerLoadReducers(loginPage.context());
await user.signIn(loginPage);
const storageState = await loginPage
.context()
.storageState({ indexedDB: true });

await use({ user, storageState });
} finally {
await loginPage.close();
await user.delete(apiContext);

@gitar-bot gitar-bot Bot Sep 17, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: Account leaks if newPage() throws before try block

In both isolatedUserSession and freshUserPage, the account is created with user.create(apiContext) and then browser.newPage() runs outside the try/finally. If browser.newPage() throws (e.g. under resource pressure), the finally that runs user.delete(apiContext) is never entered, so the just-created account is leaked for the rest of the run — the exact failure these fixtures exist to eliminate. Move the newPage() call inside the try so teardown always runs once the user exists.

Create the page inside the try so user.delete always runs once the account exists (apply the same shape to freshUserPage).:

const apiContext = await getWorkerAdminAPIContext();
const user = new UserClass(undefined, isolatedUserOptions.isAdmin);
await user.create(apiContext);

let loginPage: Page | undefined;
try {
  loginPage = await browser.newPage();
  await installServerLoadReducers(loginPage.context());
  await user.signIn(loginPage);
  const storageState = await loginPage
    .context()
    .storageState({ indexedDB: true });

  await use({ user, storageState });
} finally {
  await loginPage?.close();
  await user.delete(apiContext);
}

Was this helpful? React with 👍 / 👎

// `UserClass.login()` directly instead.
const newAdminPage = await browser.newPage();
await admin.login(newAdminPage);
await admin.signIn(newAdminPage);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will need collate side change for "login" to "signIn"

`e2e/fixtures/pages.ts` and `support/fixtures/userPages.ts` were near-identical
copies of the same role-page fixtures, and had already drifted — one had
`viewOnlyPage`, the other did not. `userPages.ts` now owns every role page and
all the construction logic; `pages.ts` adds only the `page` -> `adminPage` alias,
which is the one behaviour that genuinely differs between them.

Adds the missing sanctioned path for a test that needs its *own* account, which
is why specs kept hand-rolling one. `support/fixtures/isolatedUser.ts` exposes
`isolatedUserPage` (one account per worker, fresh page per test) and
`freshUserPage` (a new account per test). Both create and delete the account in
fixture teardown, so the beforeAll + array + afterAll shape that produces the
merge queue's number-one flake cannot be written by accident.

Adds `UserClass.signIn()`, which establishes the same session as `login()` with
one POST instead of nine UI interactions. `login()` drives the form: navigate to
/signin, wait, fill, Tab, fill, click, await the response, await the redirect,
dismiss the getting-started dialog, collapse the sidebar. The suite does that
~290 times and none of it is what the tests are testing. Both paths funnel
through the same `completeSignIn()` — conditional reads off, dialog dismissed,
sidebar collapsed — so they differ in how the session was established and nothing
else. That matters: the sidebar collapse changes page geometry, so a sign-in path
that skipped it would move every locator in the spec.

The mechanism is assembled from pieces already load-bearing here: the login
request is the one `createAdminApiContext` makes (base64 password, matching the
UI's `btoa`), and `setToken` is the exact inverse of the `getToken` that
`auth.setup.ts` reads back after a real sign-in. `signInViaApi` asserts the app
shell rendered, so a session the app refuses fails there, naming the user,
instead of timing out somewhere unrelated.

`auth.setup.ts` and `performUserLogin` now take that path. Setup drops from 50.4s
to 25.6s and still writes all eight storage states. `RoleFixtureSessions.spec.ts`
asserts each of those eight yields a signed-in page — the contract every lane
depends on, which previously failed far from its cause when broken.
`signInViaApi` posted the login from a standalone `request.newContext()`. The
server sets `OM_SESSION` on that response, so the cookie landed on a throwaway
context and never reached the browser — every storage state `auth.setup.ts`
wrote carried `i18next`, `__session` and `versionFetchTime`, but no session
cookie.

The app does not notice, because it authenticates from the token in IndexedDB.
That is exactly what made this invisible locally: every spec passed, including
the eight-role fixture check. CI does notice — `PW_PRESEEDED_STATE` rotates the
cached auth state through
`.github/scripts/rotate_playwright_auth_state.py`, which replaces that cookie
and raises

    ValueError: Playwright auth state has no OM_SESSION cookie

before a single test runs. It took out 34 of 37 shards in "Setup Openmetadata
Test Environment".

Post through `page.context().request` instead, which shares its cookie jar with
the browser, so `Set-Cookie` is kept.

Route every capture in `auth.setup.ts` through `saveStorageState`, which refuses
to write a state without the cookie. A sign-in path that drops it now fails at
the point that produced it, naming the cause, instead of surfacing as a shard
that dies in environment setup.

Verified from a wiped `playwright/.auth`: all eight states carry OM_SESSION,
setup runs in 26.5s, and RoleFixtureSessions passes 8/8.
* refactor(playwright): sign in through a fixture, not the form

Migrates every spec off `UserClass.login()` and promotes
`openmetadata-playwright/prefer-role-page-fixture` to `error` with no
suppressions.

275 call sites across 83 files become `signIn()`. Both paths funnel through the
same `completeSignIn()`, so the rewrite changes how the session was established
and nothing else — which the type checker confirms: a receiver that was not a
`UserClass` would not compile, and the playwright tsc count is unchanged.

Nine specs keep `login()` because the sign-in flow is what they test —
`Pages/Login.spec.ts`, `Features/OnlineUsers.spec.ts`, `Flow/Tour.spec.ts` and
the `Features/AppMode` specs. Each call carries a justified disable naming its
reason, rather than a blanket entry in a baseline file.

`performUserLogin` is no longer flagged: it signs in through the API and owns its
page, context and teardown, so it is a sanctioned path. The rule targets
*authenticating as* a bespoke user, not *creating* one — `new UserClass()` for an
owner, reviewer or assignee is ordinary test data and is untouched.

`eslint-suppressions.json` is byte-identical to main. The rule was written to be
enforceable only once the corpus was clean, which is what this change makes true.

Validated against a live server: ~320 tests across the migrated specs, the role
fixtures, and the eight storage states, with no failure attributable to the
migration.

* perf(playwright): stop booting the app just to get a storage origin

`signInViaApi` navigated to `/` before writing the token, because IndexedDB and
localStorage are origin-scoped and there is nowhere to write until the page owns
a document on the app's origin. That navigation boots the whole SPA — bundle,
bootstrap requests, render — and is then thrown away by the navigation to
/my-data two lines later.

CI measured the cost once every spec started signing in this way. App boots per
UI scenario, which had been flat at 2.23 across three consecutive main runs and
stayed at 2.23 and 2.24 on the two PRs beneath this one, went to 2.59 here:
12445 boots for 4814 scenarios, roughly 1700 boots spent on nothing.

Storage is scoped to the origin, not to the app, so a route-stubbed blank
document on that origin gives `suppressWelcomeScreen` and `setToken` the same
access for one intercepted request and no boot. The route is a page route, so it
takes precedence over any `**/*` context route a fixture installed, and it is
removed in a `finally` before the one real navigation.

`TokenStorage.spec` gains a case for this, from a cold context rather than the
already-navigated page the describe-level beforeEach provides — deleting the
primer navigation makes it fail on `'serviceWorker' in navigator`, which is the
regression it exists to catch.

* fix(playwright): justify the sign-in disables by what they actually assert

Review on #33219 caught the rule doc claiming something untrue: that the only
justified disables are "the nine specs testing the sign-in flow itself". Nine
files carry a disable, but only `Pages/Login.spec.ts` is testing the form. The
rest were waved through on "the session must be established the way a user
establishes it", which is not a reason — `signIn()` posts to the same
`/api/v1/auth/login`, so every server-side effect of signing in is identical.

Audited all twenty. What actually distinguishes them is narrower and checkable:
`signInViaApi` finishes on `/my-data`, so a spec that asserts *where the app
lands* after sign-in cannot use it. `AppModeAiPersonaLandsAtRoot` asserts the
path is exactly `/` — "no trailing segment, no /my-data" — and the AppMode suite
records `framenavigated` to compare the route sequence. Those thirteen stay, now
saying that instead.

Four did not survive the audit and are migrated:

- `Flow/Tour.spec.ts` claimed only a form sign-in renders the welcome banner.
  The banner is gated on the `loggedInUsers` seed, and `signIn()` takes the same
  `suppressWelcomeScreen: false` opt-out the call already passed.
- `Features/OnlineUsers.spec.ts` (x2) claimed presence is registered by the
  sign-in flow. It is registered by the login POST, which `signIn()` issues, and
  the next line navigates explicitly so the landing route is irrelevant.

Twenty disables across nine files become sixteen across seven.

* fix(playwright): accept the AI shell as a signed-in session

`signInViaApi` waited for `left-sidebar` to decide the injected session had been
accepted. A user whose persona resolves to AI mounts the AI route tree instead,
whose sidebar is `ask-sidebar` — so for that user the helper timed out after 30s
and reported that the app "did not pick it up from app_state.primary; check
utils/tokenStorage.ts", pointing at the one component that was working.

Found while proving the AppMode disables are load-bearing: migrating
`AppModeAiPersonaLandsAtRoot` to `signIn()` fails, but not for the reason the
disable claims — it never reaches the landing-URL assertion because sign-in
itself reports failure first.

Either shell now counts. The AppMode disables stay: `signInViaApi` still
finishes on /my-data, which is exactly what that spec asserts it is not.

Two AI-mode specs that landed upstream meanwhile (`AiAlertPermissions`,
`ObservabilityPermissions`) move to `signIn()` here rather than in the
migration commit, because this fix is what lets them: both sign in a user
under AI mode, so both would have hit the `left-sidebar` wait. The comment in
`ObservabilityPermissions` warning that the AI-mode sign-in page "doesn't
expose the email input the login helper looks for" describes a hazard that
only exists for the form; it goes away with the form.

Verified against a local server on :8585 — auth.setup (8 sign-ins),
RoleFixtureSessions, Tour, OnlineUsers, AppModeAiPersonaLandsAtRoot and
TokenStorage all pass.
@gitar-bot

gitar-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

🟡 Medium risk · Playwright fixtures and many specs now establish sessions through API sign-in.

Consolidates signed-in page construction across userPages.ts and pages.ts, adds isolated-user fixtures with managed account lifecycle, and replaces repeated UI sign-ins with API authentication to reduce auth.setup from 50.4s to 25.6s. Consider moving browser.newPage() inside the try block in both isolatedUserSession and freshUserPage to prevent account leaks if page creation fails.

💡 Edge Case: Account leaks if newPage() throws before try block

📄 openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/isolatedUser.ts:126-140 📄 openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/isolatedUser.ts:162-176

In both isolatedUserSession and freshUserPage, the account is created with user.create(apiContext) and then browser.newPage() runs outside the try/finally. If browser.newPage() throws (e.g. under resource pressure), the finally that runs user.delete(apiContext) is never entered, so the just-created account is leaked for the rest of the run — the exact failure these fixtures exist to eliminate. Move the newPage() call inside the try so teardown always runs once the user exists.

Create the page inside the try so user.delete always runs once the account exists (apply the same shape to freshUserPage).
const apiContext = await getWorkerAdminAPIContext();
const user = new UserClass(undefined, isolatedUserOptions.isAdmin);
await user.create(apiContext);

let loginPage: Page | undefined;
try {
  loginPage = await browser.newPage();
  await installServerLoadReducers(loginPage.context());
  await user.signIn(loginPage);
  const storageState = await loginPage
    .context()
    .storageState({ indexedDB: true });

  await use({ user, storageState });
} finally {
  await loginPage?.close();
  await user.delete(apiContext);
}
🤖 Prompt for agents
Code Review: Consolidates signed-in page construction across `userPages.ts` and `pages.ts`, adds isolated-user fixtures with managed account lifecycle, and replaces repeated UI sign-ins with API authentication to reduce `auth.setup` from 50.4s to 25.6s. Consider moving `browser.newPage()` inside the `try` block in both `isolatedUserSession` and `freshUserPage` to prevent account leaks if page creation fails.

1. 💡 Edge Case: Account leaks if newPage() throws before try block
   Files: openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/isolatedUser.ts:126-140, openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/isolatedUser.ts:162-176

   In both `isolatedUserSession` and `freshUserPage`, the account is created with `user.create(apiContext)` and then `browser.newPage()` runs *outside* the `try`/`finally`. If `browser.newPage()` throws (e.g. under resource pressure), the `finally` that runs `user.delete(apiContext)` is never entered, so the just-created account is leaked for the rest of the run — the exact failure these fixtures exist to eliminate. Move the `newPage()` call inside the `try` so teardown always runs once the user exists.

   Fix (Create the page inside the try so user.delete always runs once the account exists (apply the same shape to freshUserPage).):
   const apiContext = await getWorkerAdminAPIContext();
   const user = new UserClass(undefined, isolatedUserOptions.isAdmin);
   await user.create(apiContext);
   
   let loginPage: Page | undefined;
   try {
     loginPage = await browser.newPage();
     await installServerLoadReducers(loginPage.context());
     await user.signIn(loginPage);
     const storageState = await loginPage
       .context()
       .storageState({ indexedDB: true });
   
     await use({ user, storageState });
   } finally {
     await loginPage?.close();
     await user.delete(apiContext);
   }

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants