Skip to content

fix(playwright): rebuild describe-scope state in beforeAll - #33216

Closed
chirag-madlani wants to merge 0 commit into
mainfrom
flake/1-beforeall-accumulation
Closed

chirag-madlani wants to merge 0 commit into
mainfrom
flake/1-beforeall-accumulation

Conversation

@chirag-madlani

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

Copy link
Copy Markdown
Collaborator

Stack 1 of 4. Targets main.

The problem

beforeAll is not a per-worker hook. Under fullyParallel Playwright runs it once per group of a file's tests dispatched to a worker, so one worker can run beforeAll → tests → afterAll → beforeAll → tests. An array the hook pushes into still holds entities the intervening afterAll hard-deleted, and a later read resolves to an FQN the backend no longer has. The page renders "<Entity> instance for <fqn> not found" and the next interaction waits out the whole test timeout.

This is not a timing race — it is deterministic whenever the group split lands in the wrong place, which is why it presents as a flake.

Traced on TasksUIFlow.spec.ts across three merge_group runs (before that spec was rewritten on main), where worker 1 ran:

t=383539  beforeAll #1  → POST pipelineServices pw-pipeline-service-7a4794e5
t=428764  afterAll  #1  → DELETE the same service
t=429507  beforeAll #2  → creates a second set; entities.length becomes 8
          test reads an entity deleted 700ms earlier

The error-context snapshot ended with ... not found in every sampled failure.

The change

Rebuild the state at the top of the hook instead of appending, in the eight specs that still have the shape, and add om-playwright/no-accumulating-before-all at error so it cannot come back.

The rule finds exactly these 24 instances on main. All are fixed here rather than snapshotted — eslint-suppressions.json is byte-identical to main.

Verification

  • yarn lint:playwright: 0 errors
  • yarn test:eslint-rules: 126 pass (10 new RuleTester cases)
  • playwright tsc: 165 vs main's 168

🤖 Generated with Claude Code

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with three previously reported non-blocking lint-enforcement gaps remaining.

Findings

  1. P1 Projection poll omits authentication ▶
  2. P2 Titled hooks bypass enforcement ▶
  3. P2 Partial splices count as resets ▶
  4. P2 Unexecuted resets suppress diagnostics ▶
Summary

Resets describe-scoped arrays at the start of beforeAll in eight Playwright specs, preventing subsequent setup runs from retaining entities deleted during teardown.

  • Registers om-playwright/no-accumulating-before-all at error severity.
  • Adds RuleTester coverage for accumulation, reassignment, truncation, and splice resets.
  • Documents the setup-state requirement without expanding the suppressions baseline.
  • No new actionable findings were identified in the rebased PR changes.

Reviews (15) · Last reviewed commit: "fix(playwright): treat length = 0 and sp..."

@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
Comment on lines +95 to +105
if (
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
!node.callee.computed &&
node.callee.object.type === 'Identifier' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'splice' &&
isZero(node.arguments[0])
) {
return node.callee.object.name;
}

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: splice(0, n) treated as full reset regardless of n

resetTarget only checks that splice's first argument is 0, so xs.splice(0, 5) — which removes just five elements and leaves the rest — is accepted as a complete reset and a following push is not flagged. This is a false negative that contradicts the comment's stated intent ("anything that only partially clears ... is deliberately not a reset"). To match that intent, treat splice as a reset only when the second argument is absent or is entities.length, and flag splice(0, <literal>) like splice(1).

Was this helpful? React with 👍 / 👎

Comment on lines +385 to +389
const projected = (await (
await page.request.get(exploreUrl)
).json()) as GraphData;

return projected.edges.length;

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.

P1 Projection poll omits authentication

This spec loads the admin storage state, but page.request.get(exploreUrl) does not inherit the application's bearer header from local storage. The authenticated RDF endpoint therefore returns an error response rather than GraphData, and projected.edges.length fails before the rendering assertions run. Use the authenticated context returned by getApiContext(page) and dispose it afterward, or explicitly preserve the original request's authorization.

Comment on lines +51 to +58
const hookBodyOf = (node) => {
const [callback] = node.arguments;

return callback &&
(callback.type === 'ArrowFunctionExpression' ||
callback.type === 'FunctionExpression')
? callback
: undefined;

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 Titled hooks bypass enforcement

hookBodyOf only examines the first argument, so test.beforeAll('setup', async () => { entities.push(entity); }) receives no diagnostic. Named hooks are already common in this suite, leaving that existing setup pattern outside the new enforcement. Select the callback for both supported overloads and add an invalid RuleTester case with a title.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +101 to +104
node.callee.property.name === 'splice' &&
isZero(node.arguments[0])
) {
return node.callee.object.name;

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 Partial splices count as resets

The check ignores deleteCount, so entities.splice(0, 0) and entities.splice(0, 1) both suppress diagnostics for later pushes despite retaining old entries. This leaves partial clears undetected even though the rule explicitly intends to reject them. Restrict accepted splice resets to forms that remove the entire array, and add invalid cases for zero and partial delete counts.

Comment on lines +119 to +121
if (target !== undefined && !resetsBefore.has(target)) {
resetsBefore.set(target, node.range[0]);
}

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 Unexecuted resets suppress diagnostics

The traversal records resets by variable name and source position, even inside conditional branches or uncalled nested functions. For example, if (condition) { entities = []; } before entities.push(entity) suppresses the diagnostic when the condition is false. A reset of a shadowed local can also suppress a push into the outer array. Only count resets that execute before the push for the same binding, and add cases covering these paths.

@gitar-bot

gitar-bot Bot commented Sep 21, 2026

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

🟡 Medium risk · Rebuilds Playwright test fixtures and adds an error-level lint rule.

Fixes the beforeAll accumulation flake by rebuilding describe-scope state instead of appending, adds an ESLint rule to prevent regression, and updates eight affected specs. Consider tightening the splice(0, n) detection to flag partial clears like splice(0, 5) that leave remaining elements, treating it as a reset only when the second argument is absent or equals entities.length.

💡 Edge Case: splice(0, n) treated as full reset regardless of n

📄 openmetadata-ui/src/main/resources/ui/playwright/eslint-rules/no-accumulating-before-all.mjs:95-105

resetTarget only checks that splice's first argument is 0, so xs.splice(0, 5) — which removes just five elements and leaves the rest — is accepted as a complete reset and a following push is not flagged. This is a false negative that contradicts the comment's stated intent ("anything that only partially clears ... is deliberately not a reset"). To match that intent, treat splice as a reset only when the second argument is absent or is entities.length, and flag splice(0, <literal>) like splice(1).

✅ 1 closed
✅ Edge Case: Rule flags arrays reset via .length = 0 before a push

📄 openmetadata-ui/src/main/resources/ui/playwright/eslint-rules/no-accumulating-before-all.mjs:62-76 📄 openmetadata-ui/src/main/resources/ui/playwright/eslint-rules/no-accumulating-before-all.mjs:147-157
collectResets only records whole-object reassignments (node.left.type === 'Identifier', e.g. entities = []), so a hook that clears an array with entities.length = 0 and then pushes into it is a legitimate reset but is still reported as accumulating. The rule's own valid fixtures accept entities.length = 0 alone, yet pairing it with a subsequent .push() — a correct, non-leaking pattern — trips the error-level rule and would block the code. Consider treating <name>.length = 0 (and .splice(0)) as a reset in collectResets, or document that only = [] counts as a reset.

🤖 Prompt for agents
Code Review: Fixes the `beforeAll` accumulation flake by rebuilding describe-scope state instead of appending, adds an ESLint rule to prevent regression, and updates eight affected specs. Consider tightening the `splice(0, n)` detection to flag partial clears like `splice(0, 5)` that leave remaining elements, treating it as a reset only when the second argument is absent or equals `entities.length`.

1. 💡 Edge Case: splice(0, n) treated as full reset regardless of n
   Files: openmetadata-ui/src/main/resources/ui/playwright/eslint-rules/no-accumulating-before-all.mjs:95-105

   resetTarget only checks that splice's first argument is 0, so `xs.splice(0, 5)` — which removes just five elements and leaves the rest — is accepted as a complete reset and a following push is not flagged. This is a false negative that contradicts the comment's stated intent ("anything that only partially clears ... is deliberately not a reset"). To match that intent, treat splice as a reset only when the second argument is absent or is `entities.length`, and flag `splice(0, <literal>)` like `splice(1)`.

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