Skip to content

fix(test, frontend): bound the workflow-snapshot render's cost under jsdom - #7999

Open
Neilk1021 wants to merge 7 commits into
apache:mainfrom
Neilk1021:fix/flaky-workflow-snapshot-spec
Open

fix(test, frontend): bound the workflow-snapshot render's cost under jsdom#7999
Neilk1021 wants to merge 7 commits into
apache:mainfrom
Neilk1021:fix/flaky-workflow-snapshot-spec

Conversation

@Neilk1021

@Neilk1021 Neilk1021 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

report-generation.service.spec.ts drives the real html2canvas, which clones the whole document
rather than the element it is pointed at. The unit-test builder runs spec files with
isolate: false, so one jsdom document is shared by every spec file in a worker and the clone
drags in whatever DOM the files before it left behind.

On the macOS runner that clone was measured at 12–37s against a 20s test timeout, failing
fails when the editor cannot be rendered while ubuntu and windows passed on the same commit.

Two changes, both test-only:

  • report-generation.service.spec.ts — the snapshot suite parks the document's existing body
    nodes for the duration of the file and restores them after, so the render's cost depends only on
    the DOM these tests build. It spans the file rather than each test because the renders outlive
    the tests that start them (visible in the failing log: clone Setting up the initial project architecture #1 finished during test add the textdb-sandbox project #3).

  • jsdom-svg-polyfill.ts — stops jsdom announcing getComputedStyle(elt, pseudoElt) and
    scrollTo on the virtual console, which vitest forwards to console.error as a full stack trace
    per call. The failing job carried 5,691 of them for six renders. Dropping pseudoElt changes no
    behaviour: jsdom complains and then ignores the argument, returning the element's own declaration
    either way. scrollTo has nothing to move — jsdom has no layout, and the one html2canvas reaches
    for belongs to the throwaway clone iframe, so it is neutered as each contentWindow is handed out.

Any related issues, documentation, discussions?

Closes #8001.

This continues #7886 (closing #7887), which stopped the four image-inlining tests in this file
waiting on the render. The flake moved to the two tests that still await one.

Scope note for reviewers: this bounds the render's cost, it does not remove the dependency on a
real render. The two remaining tests still await html2canvas, so a sufficiently loaded runner
could in principle still be slow — just not by the two orders of magnitude measured here. Taking
#7886's logic to its conclusion (no test in this file waiting on a real render) would need a
stub html2canvas that survives isolate: false, which is a larger change to what those two tests
cover; happy to do that instead if reviewers prefer it.

Unrelated pre-existing noise left alone: a full run still emits ~827 jsdom
HTMLCanvasElement.prototype.getContext traces from JointUIService.getMeasureContext
(joint-ui.service.ts:219). Silencing it would change what measureText returns for the
joint-ui specs, so it is out of scope here.

How was this PR tested?

ng test --watch=false on this branch (base 444fc58284), four full runs: 201 files,
5131 passed / 1 skipped each time, no Not implemented: window.getComputedStyle traces.
Clone time across the file's six renders was 79–353 ms on three warm runs; the test that was
timing out renders in 85–114 ms. The first run on a cold checkout was slower — up to 3.9s for a
clone — which is a reminder that machine load, not document size, is what is left.

The effect of the console noise was measured directly by seeding the document with 500 nodes:
clone time across the six renders went 18.8s → 13.1s with the polyfill change alone (~30%; the
share is larger where console forwarding is slower, as on CI).

yarn --cwd frontend format:ci is clean.

I cannot demonstrate the macOS leg green from here — that needs CI on this branch.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5 [1M context])

…jsdom

`report-generation.service.spec.ts` drives the real html2canvas, which clones the
whole document rather than the element it is pointed at. The unit-test builder runs
spec files with `isolate: false`, so one jsdom document is shared by every spec file
in a worker and the clone drags in whatever DOM the files before it left behind.

On the macOS runner that clone was measured at 12-37s against a 20s test timeout,
failing "fails when the editor cannot be rendered" while ubuntu and windows passed.
The job log carried 5,691 `Not implemented: window.getComputedStyle(elt, pseudoElt)`
stack traces for six renders -- about 950 per clone, so roughly 475 foreign elements
were being cloned each time. The same run locally emits 56.

Two changes, both test-only:

- The snapshot suite parks the document's existing body nodes for the duration of the
  file, so the clone's cost depends only on the DOM these tests build. It spans the
  file rather than each test because the renders outlive the tests that start them.

- `jsdom-svg-polyfill.ts` stops jsdom announcing `getComputedStyle(elt, pseudoElt)`
  and `scrollTo` on the virtual console, which vitest forwards to `console.error` as
  a full stack trace per call. Dropping `pseudoElt` changes no behaviour: jsdom
  complains and then ignores it, returning the element's own declaration either way.
  Measured against a seeded 500-node document, the traces alone cost ~30% of clone
  time (18.8s -> 13.1s across the file's six renders).

This continues apache#7886, which stopped the four image-inlining tests waiting on the
render; the flake moved to the two tests that still await one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added fix frontend Changes related to the frontend GUI labels Aug 26, 2026
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Aug 26, 2026
@github-actions
github-actions Bot requested a review from xuang7 August 26, 2026 19:33
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. release/* labels drive the post-merge backport, so add or remove one to change where this fix lands.

Release branch Analysis
release/v1.2 Already labeled — this fix is queued to backport here.

Auto-label run.

@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @mengw15, @kunwp1
    You can notify them by mentioning @mengw15, @kunwp1 in a comment.

@codecov-commenter

codecov-commenter commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.34%. Comparing base (444fc58) to head (6a29d2d).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7999      +/-   ##
============================================
+ Coverage     93.24%   93.34%   +0.09%     
  Complexity     4677     4677              
============================================
  Files          1177     1179       +2     
  Lines         47685    47713      +28     
  Branches       5312     5314       +2     
============================================
+ Hits          44466    44537      +71     
+ Misses         1743     1719      -24     
+ Partials       1476     1457      -19     
Flag Coverage Δ *Carryforward flag
access-control-service 81.00% <ø> (ø) Carriedforward from 2bca660
agent-service 99.32% <ø> (ø) Carriedforward from 2bca660
amber 89.40% <ø> (ø) Carriedforward from 2bca660
computing-unit-managing-service 73.67% <ø> (ø) Carriedforward from 2bca660
config-service 86.73% <ø> (ø) Carriedforward from 2bca660
file-service 86.70% <ø> (ø) Carriedforward from 2bca660
frontend 95.89% <ø> (+0.21%) ⬆️
notebook-migration-service 79.31% <ø> (ø) Carriedforward from 2bca660
pyamber 97.78% <ø> (ø) Carriedforward from 2bca660
workflow-compiling-service 77.19% <ø> (ø) Carriedforward from 2bca660

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aglinxinyuan
aglinxinyuan requested a lite review from Copilot August 26, 2026 21:09

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aglinxinyuan aglinxinyuan left a comment

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.

Ran the suite four times on this branch — matches your numbers, and the shared-document premise holds (194 of 201 runs saw the previous run's document, body peaking at 463 elements). Six comments inline; only the idempotence one is blocking.

Comment thread frontend/src/jsdom-svg-polyfill.ts
Comment thread frontend/src/jsdom-svg-polyfill.ts Outdated
Comment thread frontend/src/jsdom-svg-polyfill.ts Outdated
Neilk1021 and others added 6 commits August 27, 2026 11:38
`setupFiles` is re-evaluated once per spec file, so the two patches added for
html2canvas's `notImplemented` traces wrapped their own wrapper on every
evaluation -- 41 layers deep by the end of a full run. The file already guards
its process-level handlers and its loader hook against the same accumulation.

Mark the installed function and the installed `contentWindow` getter, and skip
the patch when the mark is already there. The mark rides on what was installed
rather than on a `globalThis` flag so that a jsdom window replaced mid-run is
still patched -- a flag would suppress the re-patch and let the traces back in.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Neutering `scrollTo` on this window was dead code. html2canvas's only call
against it is `restoreOwnerScroll`, guarded by `x !== pageXOffset || y !==
pageYOffset`; jsdom has no layout, so both offsets are 0 and the call never
happens. The call that does happen belongs to the clone iframe's window, which
the `contentWindow` patch below already covers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents

Dropping `pseudoElt` wholesale was not behaviour-preserving after all. jsdom
tests the argument against `/^::(?:part|slotted)\(/i` and throws a `TypeError`
before it reaches `notImplemented`, so a shadow-DOM pseudo-element would have
been answered with the element's own declaration instead of the rejection.
Nothing in `src` passes one today; forward those arguments so nothing has to.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
html2canvas clones from `documentElement`, so `<head>` is walked as well --
measured at 185 elements there against the body's 463. Park both, restoring
each node to the parent it came from.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`DocumentCloner.destroy` runs only on the render's success path, so each render
these tests leave failing strands its clone iframe in the body -- three of them
by the time the suite ends. Removing them before the parked nodes go back keeps
the next spec file's renders from cloning them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`beforeAll` / `afterAll` inside this `describe` span the suite, and a render
that outlives them sees the restored DOM either way. Say "suite".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Neilk1021
Neilk1021 requested a review from aglinxinyuan August 27, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix frontend Changes related to the frontend GUI release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: report-generation snapshot render times out on the macOS frontend leg

5 participants