Skip to content

fix(recorder): attach rpc observer before navigation in lazy-capture test - #359

Merged
omridevk merged 1 commit into
mainfrom
fix/355-recorder-observer-attach
Aug 9, 2026
Merged

fix(recorder): attach rpc observer before navigation in lazy-capture test#359
omridevk merged 1 commit into
mainfrom
fix/355-recorder-observer-attach

Conversation

@omridevk

@omridevk omridevk commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

lazy-capture.it.test.ts called observeRpc(page) inside the test body, after getExtensionTestApi had already navigated the page. Playwright's page.on('websocket') only fires for sockets created after the listener attaches, so the observer had no guaranteed claim on the shared rpc socket. Switched to rpcObserverFor(page), which returns the observer openObservedPage installs before page.goto — the same one-line change the whiteboard drag-batching test took in #349. Dropped the trailing observer.dispose(): the observer is now the page-scoped shared one and must outlive the test (whiteboard does the same).

Mechanism: the luck hypothesis was wrong, but it is luck

Probed with a temporary socketCount() log, comparing the late observer against the pre-attached one on the same page:

SOCKET_COUNT_PROBE late 1 preattached 1 lateFlushes 2 preattachedFlushes 2

Both observers report one socket and the same flush calls. So there is no ReconnectingWebSocket second socket — the page opens exactly one rpc socket over its whole life. The real mechanism is that the socket is opened lazily, after page.goto(waitUntil: 'domcontentloaded') resolves and after the test body's first statements run. The late attach caught it by pure timing margin. That is still luck: it is a race between the extension client's connect and the first line of the test, and it flips to expected 0 to be greater than 1 the day connect gets faster. The probe log was removed before commit.

Proof

  • Recorder suite: TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1 pnpm turbo run test --concurrency=1 --filter=@conciv/extension-recorder122/122 tests passed.
  • lazy-capture.it.test.ts run 3x standalone — 2/2 tests passed on every run.
  • typecheck / lint / format:check green. fallow audit --changed-since main verdict pass, zero introduced.

Pre-existing flake spotted, not fixed here (out of scope)

Independently of this change, useRecorderTestApi's afterAll(() => api.dispose()) intermittently exceeds vitest's 30s hookTimeout, failing the file while every test in it passes:

Error: Hook timed out in 30000ms.
 ❯ useRecorderTestApi test/helpers/test-api.ts:14:3

Observed on the untouched panel-stream.it.test.ts during the suite gate, and on a pre-fix probe run of lazy-capture before any behavioral edit — so it predates this PR. Worth its own issue against packages/extension-testkit teardown.

Closes #355

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Updated recorder integration coverage for lazy capture lifecycle behavior.
    • Simplified RPC observation cleanup in the test setup.

…test (closes #355)

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

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 449eff0b-6290-4cf8-a1a9-3035a38b2040

📥 Commits

Reviewing files that changed from the base of the PR and between c6aa92c and 1f85d59.

📒 Files selected for processing (1)
  • packages/extensions/recorder/test/lazy-capture.it.test.ts

📝 Walkthrough

Walkthrough

The lazy-capture integration test now uses rpcObserverFor(page) and removes explicit observer disposal.

Changes

Recorder lazy-capture test

Layer / File(s) Summary
Update RPC observer lifecycle
packages/extensions/recorder/test/lazy-capture.it.test.ts
The test replaces observeRpc with rpcObserverFor(page) and removes the explicit observer.dispose() call.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

  • #339 — The changes use the same RPC observer migration in lazy-capture.it.test.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the recorder test fix and the required observer timing change.
Linked Issues check ✅ Passed The changes satisfy issue #355 by using the page-scoped observer before navigation and removing incompatible disposal.
Out of Scope Changes check ✅ Passed The changes are limited to the recorder test and directly support the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/355-recorder-observer-attach

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

@omridevk
omridevk merged commit 719069d into main Aug 9, 2026
25 checks passed
@omridevk
omridevk deleted the fix/355-recorder-observer-attach branch August 9, 2026 07:12
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.

recorder lazy-capture test late-attaches its rpc observer — passes by luck, not design

1 participant