Skip to content

fix(browser-extension): repair packaged-worker backfill fixture - #3491

Merged
Sinity merged 1 commit into
masterfrom
fix/browser-extension/build-fixture-backfill-start
Jul 31, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/browser-extension/build-fixture-backfill-start

Conversation

@Sinity

@Sinity Sinity commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

tests/build.test.js's packaged-service-worker fixture test was failing
on 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 packaged
service worker fixture without foreground tab activation" test failed:
vi.waitFor at line 274 timed out because polylogue.backfill.start
never issued a page request.

Root-cause evidence

Bisected two independent, unrelated fixture defects:

  1. Dead chrome.tabs.query mock. It was vi.fn(async () => []),
    never reflecting the fixture's own ownedTabs array, so
    observedProviderTab() 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.create assertion (expecting
    the extension to create its own tab) directly contradicted that
    tested contract.

  2. No seeded receiver pairing. stored never set
    polylogueReceiverPairing, and the fetch mock had no /v1/status
    handler, so requirePairedTrustedReceiver() (fix(extension): require pairing before provider capture, 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.

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/requirePairing options through providerPageFetch,
providerAccountHandle, and captureProviderConversation in
src/background.js so backfill could create/use its own tab and skip
pairing. That DID make build.test.js pass, but it broke 4
background.test.js tests 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 PR
only touches the test.

Solution

In browser-extension/tests/build.test.js:

  • 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
    test'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.update assertion.
  • 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 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 back
    to 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.
  • pre-push devtools verify --quick — passed (18 steps, 68.7s).

Ref polylogue-uegw.

…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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 36 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 83a463ba-f158-4afc-bdde-0440d575f605

📥 Commits

Reviewing files that changed from the base of the PR and between 90d4df6 and 770dcbe.

📒 Files selected for processing (1)
  • browser-extension/tests/build.test.js

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.

❤️ Share

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

@Sinity
Sinity merged commit 1bd8555 into master Jul 31, 2026
3 checks passed
@Sinity
Sinity deleted the fix/browser-extension/build-fixture-backfill-start branch July 31, 2026 22:34
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