Skip to content

test(web): replace slow failing waitFor polls with cheap state checks - #526

Merged
imshashank merged 2 commits into
mainfrom
test/slow-waitfor-polls
Oct 6, 2026
Merged

imshashank merged 2 commits into
mainfrom
test/slow-waitfor-polls

Conversation

@imshashank

@imshashank imshashank commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

Full web suite runs locally have been timing out on tests that pass alone. The cause is a failing jest-dom assertion whose message pretty-prints a happy-dom element. Bun walks the element's document and React fiber references, so one failure message costs seconds of synchronous CPU in a large process. That blocks whatever test is running next.

How the sites were found

Instead of reviewing every waitFor by hand, I temporarily instrumented @testing-library/dom's waitFor and the jest-dom matchers during full web suite runs (not committed). This logged every poll that failed, with its call site and how long it took.

  • Across 2989 tests, exactly one failing poll was expensive: doc-import.test.tsx:52, a 4.8 s message. Every other failing poll in the suite cost 5 ms or less.
  • A separate full run, at load 53, failed on onboarding-flow.test.tsx:76 with a 66 MB, roughly 35 s failure dump. That is the same mechanism through a findByRole then toBeVisible race.
  • The filter-bar, team-settings-panel and analytics page tests never fail a poll on current main. Their negative waits already hold on the first check, so waitForElementToBeRemoved would throw there ("already removed"). They are left unchanged.

Changes

  • doc-import.test.tsx: waitFor(() => expect(button).not.toBeDisabled()) now polls the button's disabled property. Same condition, and a failed poll reports a boolean instead of the element.
  • onboarding-flow.test.tsx: the AI tool step mounts inside a motion wrapper that enters from opacity 0. findByRole resolves on mount, so the old toBeVisible passed only when the first animation frame had already run. A probe across 15 runs found opacity between 0.04 and 0.43 at the moment the heading was found. The test now waits until no ancestor is fully transparent (a numeric check), then asserts the unchanged toBeVisible.

Strictness

  • Breaking the component so the import button never re-enables fails both doc-import tests (Expected: false, Received: true).
  • Pinning the onboarding step at opacity 0 fails the new test in 1.3 s with 8 KB of output. The old test failed too, but printed 66 MB.

Per-test durations

doc-import > refuses a file too large to be a doc, before it reads it

before after
full web suite 6.133 s, 4.825 s, 5.864 s 0.018 s, 0.018 s, 0.013 s
file alone 0.269 s, 0.144 s, 0.375 s 0.044 s, 0.024 s, 0.029 s

The other tests in doc-import.test.tsx stay under 0.1 s both before and after.

onboarding-flow > moves from teammates to the AI tool step and labels it in the progress bar

before after
full web suite 0.282 s, 0.220 s, then a 55.5 s failure under load 0.510 s, 0.207 s, 0.223 s
file alone 0.216 s, 0.247 s, 0.230 s 0.246 s, 0.216 s, 0.279 s

Verification

  • Full web suite three times on this branch with the package's 20 s timeout, at load averages of 65 to 68: 2989 pass, 0 fail each time (293 s, 463 s, 298 s).
  • bun run verify: exit 0. Lint, comment policy, dependency and Bun import checks, and typecheck pass in every package. Tests: web 2989, services 931, db 318, core 1102, shared 361, mcp-server 218, realtime-server 120, realtime 45, realtime-client 15, with 0 failures. This machine needed environment fixes for verify, and none of them change the repository:
    • MinIO was started for the object storage tests.
    • The @orbit/db tests run against DATABASE_URL, so that run pointed it at a fresh database with the current schema pushed, as CI does. The local dev database was left untouched.
    • Several unrelated Postgres containers run on this host, so the backup tests' pg_dump shim chose the wrong one. For the run, pg_dump and pg_restore on PATH were wrappers that do the same thing, pinned to orbit-postgres.
  • CI: all checks pass. CodeRabbit found no actionable comments. Greptile could not review because its trial has ended.
  • Two independent read-only reviews, one for strictness and one for missed sites, found no defects and no other affected call sites. The second ran its own instrumented full suite: no element-printing matcher failed anywhere.

The import button waits used jest-dom's not.toBeDisabled inside waitFor.
Its first poll fails while the import is in flight, and building that
failure message pretty-prints the happy-dom button with its React fiber
references. In a full web suite run one such message took 4.8 seconds
of synchronous CPU, which made the too-large file test take about 6
seconds and pushed it toward the timeout under load.

Wait on the button's disabled property instead. A failed poll now
reports a boolean, and the test still fails if the button never
re-enables.
…ibility

The AI tool step mounts inside a motion wrapper that enters from opacity
0. findByRole resolves as soon as the heading mounts, so toBeVisible
only passed when the first animation frame had already run. Under load
it lost that race, and jest-dom's failure message pretty-printed the
heading with its document and React fiber references: 66 MB of output
and about 35 seconds of synchronous CPU in a full suite run, which
stalled the process for whatever tests came next.

Wait until no ancestor is fully transparent, reporting a number on each
failed poll, then keep the original toBeVisible assertion.
@imshashank
imshashank requested a review from pulkitxm as a code owner October 6, 2026 08:01

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI labels Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Noveum/orbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa5d5016-54be-45ec-b1d1-82f293c6695e
📥 Commits

Reviewing files that changed from the base of the PR and between 0a24d57 and a4df262.

📒 Files selected for processing (2)
  • apps/web/tests/features/docs/doc-import.test.tsx
  • apps/web/tests/features/onboarding/onboarding-flow.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The document import tests now wait for the Import button to become enabled after two error paths. The onboarding test calculates accumulated opacity and waits for the AI-tool-step heading to become visible.

Changes

Document Import Tests

Layer / File(s) Summary
Wait for the Import button state
apps/web/tests/features/docs/doc-import.test.tsx
The oversized-file and document-creation-error tests wait for the Import button’s disabled property to become false.

Onboarding Tests

Layer / File(s) Summary
Wait for accumulated heading opacity
apps/web/tests/features/onboarding/onboarding-flow.test.tsx
A helper multiplies computed opacity values from the heading through its ancestors. The AI-tool-step test waits for the result to exceed zero before checking visibility.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested reviewers: pulkitxm

Merge Risk: ⚪ Minimal · up to a4df2

These changes only adjust test synchronization around existing import recovery and the onboarding transition; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: replacing expensive waitFor assertions with cheaper state checks in web tests.
Description check ✅ Passed The description explains the affected tests, the reason for the changes, and the reported verification results.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
orbit Ready Ready Preview Oct 6, 2026 8:13am UTC

Request Review

@imshashank
imshashank merged commit d1e0429 into main Oct 6, 2026
16 checks passed
@imshashank
imshashank deleted the test/slow-waitfor-polls branch October 6, 2026 17:59

This branch was successfully deployed

1 active deployment
Preview — a4df262f Deployed Oct 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant