Skip to content

fix(test): make pairing + network-ingest suites order-independent (config.json + network-ingest cache leaks)#154

Merged
andrescera merged 1 commit into
mainfrom
fix/test-isolation-platform-url
Jul 16, 2026
Merged

fix(test): make pairing + network-ingest suites order-independent (config.json + network-ingest cache leaks)#154
andrescera merged 1 commit into
mainfrom
fix/test-isolation-platform-url

Conversation

@andrescera

Copy link
Copy Markdown
Member

What

Follow-up to #153. After that PR fixed the MOCK_MODE leak (6 of the original 21 CI failures), 15 tests still failed deterministically in the BE unit (bun) + exec-guard + biome job. This PR fixes the two remaining, independent cross-file test-isolation leaks:

  • apps/backend/src/tests/pairing-platform-claim.test.ts — read config.json unconditionally in beforeEach.
  • apps/backend/src/tests/network-ingest-control.test.ts — wrote the module-level network-ingest cache via the real RPC but never reset it in teardown.

13 insertions, 4 deletions, no production code.

Why

bun test runs every file in one shared process, so any global state a file leaves dirty is inherited by whatever file runs next — and the full-suite file order differs between a fresh CI runner and a local box, so both leaks reproduce deterministically in CI but not always locally.

Leak 1 — config.json (14 failures). config.json is gitignored, so it is absent on a fresh CI checkout. pairing-platform-claim.test.ts's beforeEach did readFileSync("config.json") unconditionally; when absent that throws ENOENT, failing every test in the file — including the pure platformClaimErrorForStatus and getPlatformUrl cases, which is exactly the 14-failure set. The cross-file trigger is remote-repair-migration.test.ts, which correctly deletes the config.json it created when the file was absent at its start (restoring prior state) — its sibling comment even notes "Reading it unconditionally throws on a fresh CI checkout." The bug is the unconditional read, not the cleanup. Fix: snapshot only when existsSync, and in afterEach remove it when it was absent at start, else restore the bytes.

Leak 2 — network-ingest cache (1 C7 failure). source-lost-rejection.test.ts's "available:false network source (gateway down) → source_unavailable" reads the module-level cached snapshot in network-ingest.ts. network-ingest-control.test.ts's "mocks" block drives the real network.setIngestEnabled RPC (which writes that cache) but never called resetNetworkIngestState() in teardown — the only one of the five cache-writers that didn't. Its last test leaves rtmp enabled+active, so a later file sees the rtmp source as available:true, and the C7 start returns network_ingest_gateway_inactive instead of source_unavailable. streaming-gateway-gate.test.ts already documents this exact "stale ambient cache leaves service_active:true … under CI test ordering" hazard. Fix: reset the cache in the mocks block's afterEach + afterAll.

How to verify

  • pairing-platform-claim.test.ts alone with config.json removed: 14 pass / 0 fail (was 0/14). remote-repair-migrationpairing-platform-claim with config.json removed: 30 pass / 0 fail.
  • network-ingest-controlsource-lost-rejection (C7): 27 pass / 0 fail; a cache probe after the fix reports rtmp=null (was service_active:true).
  • Full suite with config.json present and absent: 1910 pass / 0 fail both ways.
  • bun tsc --noEmit, bunx biome check: clean. The only other full-suite fails are the pre-existing qw-e-audio-hotplug.test.ts fs.watch flakes (fail identically on the pristine tree; out of scope).

Risks

Minimal — test-only changes that restore/reset global state the suites should never have leaked. No production code, no test skipped or weakened (Rule E). With this merged, the four previously-blocked PRs should have a fully green BE unit job.

Two more cross-file test-isolation leaks surfaced on top of the MOCK_MODE
fix (#153); both fail deterministically only in the full CI suite.

1. pairing-platform-claim.test.ts read config.json unconditionally in
   beforeEach. config.json is gitignored, so on a fresh CI checkout (or
   after remote-repair-migration restores its absent prior state) the
   read throws ENOENT and fails every test in the file — including the
   pure status-code and getPlatformUrl cases. Snapshot it only when it
   exists and restore-or-remove in afterEach, matching the pattern
   remote-repair-migration.test.ts already documents.

2. network-ingest-control.test.ts drove the real setIngestEnabled RPC,
   which writes the module-level network-ingest cache, but never called
   resetNetworkIngestState in teardown (the only cache-writer that
   didn't). A leaked rtmp-active snapshot made source-lost-rejection's
   C7 test see the rtmp source as available, so it returned
   network_ingest_gateway_inactive instead of source_unavailable. Reset
   the cache in the mocks block afterEach + afterAll.

No production code changes; no test skipped or weakened.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a806049d-3e8e-4e89-9df4-a0b3db46c147

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-isolation-platform-url

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.

@andrescera
andrescera merged commit fc38c01 into main Jul 16, 2026
10 checks passed
@andrescera
andrescera deleted the fix/test-isolation-platform-url branch July 16, 2026 21:03
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