Repository navigation
fix(browser-extension): repair packaged-worker backfill fixture - #3491
Conversation
…prod code Problem tests/build.test.js's "executes the packaged service worker fixture without foreground tab activation" test was failing on master (polylogue-uegw): backfill.start never issued a page request, and vi.waitFor timed out. Bisected two independent fixture defects, both predating this fix and both already known-and-accepted stale-fixture debt at the time they were introduced (PR #2986's own verification note: "one pre-existing packaged-worker fixture failure reproduced unchanged"): 1. `chrome.tabs.query` was a dead mock (`vi.fn(async () => [])`) that never reflected `ownedTabs`, so `observedProviderTab()` could never find a provider tab. Passive/automatic backfill is intentionally observe-only by design (fix(extension): avoid automatic provider transport tabs, #2974 — "Only explicit queued UI actions may create an extension-owned inactive transport") and is heavily pinned by background.test.js ("never creates a transport tab when passive backfill has no provider page", "defers backfill when no supported provider surface is open", "shares an existing provider surface across concurrent backfill jobs"). The fixture's `tabs.create` assertion (expecting the extension to create its own tab) directly contradicted that intentional, tested contract. 2. `stored` never seeded a receiver pairing (`polylogueReceiverPairing`) and the global fetch mock had no `/v1/status` handler, so requirePairedTrustedReceiver() (fix(extension): require pairing before provider capture, #2983) always threw `receiver_unpaired` for the exact-capture path. background.test.js's successful-capture fixtures all seed this pairing; build.test.js never did. Root-cause evidence An initial attempt to "fix" this by threading allowCreate/requirePairing options through providerPageFetch/providerAccountHandle/ captureProviderConversation in src/background.js did make build.test.js pass, but broke 4 background.test.js tests that explicitly pin the opposite (intentional) production behavior -- proving the defect was in the fixture, not production code. That production change was reverted; this commit only touches the test fixture. Solution - Seed one already-open, operator-owned ChatGPT tab (id 42, matching background.test.js's convention) instead of an empty tab list, and make `chrome.tabs.query` return it dynamically. - Seed `polylogueReceiverPairing` in `stored` and add a `/v1/status` fetch handler, matching how background.test.js's successful-capture fixtures already model a paired receiver. - Replace the incorrect `tabs.create` assertion with `expect(tabs.create).not.toHaveBeenCalled()`, consistent with the "without foreground tab activation" test name (which is about not activating/creating a tab at all, not merely not making it foreground) and with `tabs.update` already being asserted not-called. - Update the `tabs.sendMessage` assertion's tab id from the stale fixture-only id 77 to the pre-seeded tab id 42. No production capture behavior changed; shipped artifacts were never affected by the fixture bug itself, but the two gates the fixture was failing to model (observe-only passive/automatic transport, pairing-gated exact capture) are real, already-shipped, already-tested production invariants that this fixture now correctly exercises instead of accidentally bypassing. Verification - `npx vitest run tests/build.test.js` -- 6/6 passed. - `npx vitest run` (full extension suite) -- 378/378 passed, twice in a row (ruled out tests/background.test.js's one known-flaky timing test, "falls back to the adapter's full-fidelity normalization...", by re-running it in isolation after an isolated failure -- passed clean; unrelated to this change, matches the operator's advance note). - `node scripts/validate-manifest.mjs` -- manifest ok. Ref polylogue-uegw. Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
tests/build.test.js's packaged-service-worker fixture test was failingon master because two of its mocks were stale relative to intentional,
already-shipped, already-tested production behavior. This PR fixes only
the fixture — no production code changed.
Problem
Ref polylogue-uegw.
tests/build.test.js's "executes the packagedservice worker fixture without foreground tab activation" test failed:
vi.waitForat line 274 timed out becausepolylogue.backfill.startnever issued a page request.
Root-cause evidence
Bisected two independent, unrelated fixture defects:
Dead
chrome.tabs.querymock. It wasvi.fn(async () => []),never reflecting the fixture's own
ownedTabsarray, soobservedProviderTab()could never find a provider tab. Passive/automatic backfill is intentionally observe-only by design
(
fix(extension): avoid automatic provider transport tabs, fix(extension): avoid automatic provider transport tabs #2974:"Only explicit queued UI actions may create an extension-owned
inactive transport"), and is heavily pinned by
background.test.js("never creates a transport tab when passive backfill has no
provider page", "defers backfill when no supported provider surface
is open", "shares an existing provider surface across concurrent
backfill jobs"). The fixture's
tabs.createassertion (expectingthe extension to create its own tab) directly contradicted that
tested contract.
No seeded receiver pairing.
storednever setpolylogueReceiverPairing, and the fetch mock had no/v1/statushandler, so
requirePairedTrustedReceiver()(fix(extension): require pairing before provider capture, fix(extension): require pairing before provider capture #2983) always threwreceiver_unpairedfor the exact-capture path.background.test.js's successful-capture fixtures all seed thispairing;
build.test.jsnever did.Both gaps were pre-existing, and were already known: PR #2986's own
verification note from 2026-07-17 says "one pre-existing
packaged-worker fixture failure reproduced unchanged" — this test broke
around the same time #2974/#2983 tightened the passive-capture and
pairing contracts, and was never updated.
Anti-vacuity check (confirms this is a fixture bug, not a production
bug): I first attempted a production-code fix, threading
allowCreate/requirePairingoptions throughproviderPageFetch,providerAccountHandle, andcaptureProviderConversationinsrc/background.jsso backfill could create/use its own tab and skippairing. That DID make
build.test.jspass, but it broke 4background.test.jstests that explicitly pin the opposite behavior("never creates a transport tab when passive backfill has no provider
page", "defers backfill when no supported provider surface is open",
"shares an existing provider surface across concurrent backfill jobs").
That change was reverted (
git checkout -- src/background.js); this PRonly touches the test.
Solution
In
browser-extension/tests/build.test.js:background.test.js's convention) instead of an empty tab list, andmake
chrome.tabs.queryreturn it dynamically.polylogueReceiverPairinginstoredand add a/v1/statusfetch handler, matching how
background.test.js's successful-capturefixtures already model a paired receiver.
tabs.createassertion withexpect(tabs.create).not.toHaveBeenCalled()— consistent with thetest's own name ("without foreground tab activation" is about not
materializing/activating a tab at all, not merely not making it
foreground) and with the adjacent
tabs.updateassertion.tabs.sendMessageassertion's tab id from the stalefixture-only id 77 to the pre-seeded tab id 42.
No production capture behavior changed. Shipped artifacts were never
affected by the fixture bug itself, but the two gates the fixture was
failing to model (observe-only passive/automatic transport,
pairing-gated exact capture) are real, already-shipped invariants this
fixture now correctly exercises instead of accidentally bypassing.
Verification
npx vitest run tests/build.test.js— 6/6 passed.npx vitest run(full extension suite) — 378/378 passed, run twice.tests/background.test.js's one known-flaky timing test ("falls backto the adapter's full-fidelity normalization...") failed once on a
full-suite run and passed clean when re-run in isolation — pre-existing
flake, unrelated to this change, matches the operator's advance note.
node scripts/validate-manifest.mjs— manifest ok.devtools verify --quick— passed (18 steps, 68.7s).Ref polylogue-uegw.