Skip to content

fix(embed): close every it() page in a try/finally (PR 2/2, #389) - #411

Closed
omridevk wants to merge 2 commits into
mainfrom
fix/389-page-lifecycle-sweep
Closed

omridevk wants to merge 2 commits into
mainfrom
fix/389-page-lifecycle-sweep

Conversation

@omridevk

Copy link
Copy Markdown
Contributor

Summary

  • Mechanical sweep of packages/embed/test/*.it.test.ts: every it() that acquires one or more Playwright pages and only closed them as the last happy-path statement now wraps the body in try { ... } finally { await page.close() } (multi-page tests close each page in the finally). This matches the pattern already used in connection-pool.it.test.ts and transport-selection.it.test.ts (untouched — already correct).
  • An assertion failure previously left the page open in the file's shared browser, compounding memory pressure across the suite (audit on Flaky: grab-reference.browser.test.tsx dies with 'Browser connection was closed' + extension teardown unhandled (CI shard-4) #389, finding 4).
  • apps/conciv/test/transport-standalone.it.test.ts already used try/finally per test — left untouched, per the audit.

Left alone (and why)

  • embed.it.test.ts: 'a reload restores the panel open on the same view' and 'a reload after closing the panel boots shut' — each closes the first page mid-body as the literal reload/close simulation, then opens a second page to assert restored state. That mid-body close is test semantics, not incidental cleanup, so these two are left unwrapped per the "leave alone and note it" instruction.
  • page-dispatch-boot.it.test.ts and page-dispatch-parity.it.test.ts — their pages are created in beforeAll and closed in afterAll, shared across all it()s in the describe block, not per-test acquisitions.

Test plan

  • pnpm turbo run build --filter=@conciv/embed (green)
  • packages/embed/test/embed.it.test.ts — 18/18 passed
  • packages/embed/test/rebind.it.test.ts — 4/4 passed
  • packages/embed/test/composer-trigger-menu.it.test.ts — 5/5 passed
  • pnpm turbo run typecheck --filter=@conciv/embed --filter=@conciv/app (green)
  • oxfmt --check / oxlint on all 16 touched files (clean; formatting auto-fixed two files pre-commit)
  • fallow audit --changed-since origin/main --format json → verdict pass, 0 introduced findings

Refs #389, #409

🤖 Generated with Claude Code

Playwright pages acquired inside an it() body and closed only as the
last happy-path statement leak a live tab into the file's shared
browser on assertion failure, compounding memory pressure across the
suite (audit on #389, finding 4). Wrap every page acquisition without
existing try/finally protection, following the pattern already used
in connection-pool.it.test.ts and transport-selection.it.test.ts.

Left alone: the two reload-simulation tests in embed.it.test.ts
("a reload restores the panel open on the same view" and "a reload
after closing the panel boots shut") where page.close() mid-body is
the reload trigger itself, not incidental cleanup; and the shared
beforeAll/afterAll pages in page-dispatch-boot.it.test.ts and
page-dispatch-parity.it.test.ts, which are not per-test.

PR 2 of 2 for #389, under epic #409.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@omridevk, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3960d4c5-6ad2-4b30-8440-2b5c404d5e5d

📥 Commits

Reviewing files that changed from the base of the PR and between 3b58542 and 23ad96c.

📒 Files selected for processing (16)
  • packages/embed/test/composer-rich-input.it.test.ts
  • packages/embed/test/composer-trigger-menu.it.test.ts
  • packages/embed/test/create-conciv.it.test.ts
  • packages/embed/test/draft-selection.it.test.ts
  • packages/embed/test/embed.it.test.ts
  • packages/embed/test/model-selector.it.test.ts
  • packages/embed/test/native-live-region.it.test.ts
  • packages/embed/test/native-widget.it.test.ts
  • packages/embed/test/navigation-hold.it.test.ts
  • packages/embed/test/page-plane.it.test.ts
  • packages/embed/test/panel-focus.it.test.ts
  • packages/embed/test/rebind.it.test.ts
  • packages/embed/test/recording-attachment.it.test.ts
  • packages/embed/test/reload-continuity.it.test.ts
  • packages/embed/test/rpc-fault.it.test.ts
  • packages/embed/test/rpc-observer.it.test.ts
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/389-page-lifecycle-sweep

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

…ths too

The two reload-simulation tests kept a bare-body page for `first`
(closed mid-body as the reload trigger) and `second` (closed only as
the last statement). Either leaks on an assertion failure before its
close: page.close() is idempotent, so wrapping each phase in its own
try/finally closes on failure without changing happy-path behavior —
the mid-body first.close() stays in place as the reload trigger.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@omridevk

Copy link
Copy Markdown
Contributor Author

Superseded by the runner migration: the embed integration suite is moving off vitest onto @playwright/test, which owns page lifecycle via fixtures and kills this leak class by construction rather than patching it test-by-test. Not merging. See the follow-up PR for #389 that supersedes this one.

@omridevk omridevk closed this Aug 10, 2026
omridevk added a commit that referenced this pull request Aug 10, 2026
…/e2e — the runner owns page lifecycle (#389) (#415)

* test(embed): move integration tests onto @playwright/test under tests/e2e — the runner owns page lifecycle (#389)

Failed assertions in the old hand-rolled `chromium.launch()`/`browser.newPage()`
vitest suite leaked live Chromium pages: nothing guaranteed a close on a failure
path, and those leaks pressured CI shard-4 and stranded sibling vitest browser
sessions. Kill the leak class by construction: @playwright/test owns the
browser/context/page lifecycle end to end via its built-in fixtures, so a
failed assertion can no longer skip a close.

Splits packages/embed's test suite by kind:
- tests/e2e/ — the 22 real browser-driven integration tests (*.it.test.ts),
  now run by `playwright test`. Kit boots stay per-file via
  test.beforeAll/test.afterAll; per-test pages come from the page/context
  fixtures; multi-page tests use context.newPage(); the two reload-simulation
  tests in embed.it.test.ts keep their intentional mid-body page.close().
- tests/unit/ — the 4 build/bundle assertion tests plus proxy-upgrade (an
  integration test against a real HTTP/WS server that never opens a browser
  page), still run by vitest.
- tests/helpers/ — boot.ts, host.ts, proxy.ts: shared, non-playwright helpers
  used by both tiers.
- tests/e2e/helpers/ — the playwright-only helpers (suite.ts and
  probe-suite.ts no longer own a browser at all).
- tests/fixtures/, tests/dist/, tests/globals.d.ts moved alongside.

Supersedes the closed #411 try/finally hand-wrapping attempt and epic #409.
Rebased onto #410 (port-drift navigation.set deadline fix) after it merged.

Also fixes a latent gap in the banned-vocabulary allowlist: the renamed
native-bridge.ts helper was never covered under its old path either, so add
the new path to NATIVE_AND_REACT_BRIDGE_PATHS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(embed): budget per-test timeouts and make e2e teardown never throw

Sum the sequential wait budgets (expect timeouts, observer completed
timeouts, and the shared helper waits they call into) for every
packages/embed/tests/e2e/*.it.test.ts test and set test.setTimeout on
any test whose sum clears the ~45s default, so slow CI runs don't trip
the global 60s playwright timeout.

Move teardown robustness into the shared helpers instead of wrapping
every test.afterAll in try/finally at the call site: bootEmbedKit's
returned cleanup, serveHost's returned close, proxyTo's returned
close, and startProbeServer's returned close now catch and log rather
than throw, so a failure in one step never skips the rest of a
multi-step afterAll.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(embed): close dedicated panel-focus hosts on teardown, propagate close errors

panel-focus.it.test.ts left dedicated hosts open on a failed assertion since
close() only ran on the happy path; move cleanup to a module-level afterEach
that owns every host openPanelOverFocusedHostButton creates. Also make
listenLocal's close callback reject on a server.close error instead of
silently discarding it, so serveHost.close's existing catch/log wrapper can
actually log cleanup failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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