Skip to content

dispatch tests: scope the fetch stub in server.test.ts so the suite is order-independent (#10609) - #10610

Merged
dezren39 merged 1 commit into
mainfrom
queue/17411-main-ci-10609
Nov 16, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/17411-main-ci-10609

Conversation

@dezren39

@dezren39 dezren39 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #10609.

Root cause

pm-stack/dispatch/test/server.test.ts installed its throw-on-network fetch stub at module scope (lines 16-25) and never restored the captured globalThis.fetch. Bun runs the dispatch test files in one process, so whenever server.test.ts was evaluated before opencode.test.ts, the latter's real requests to http://127.0.0.1:<port>/api/session* hit the stub's guard: 4 OpenCodeClient tests failed with unexpected network fetch in test: http://127.0.0.1:<port>/api/session.

CI evidence: run 43807605419 (push, head bcb467e) failed step "Test dispatch" with 203 pass / 4 fail, exactly the OpenCodeClient failures. A workflow_dispatch of the same head (run 43808691940) was green, and run 43792350594 (head ec68de7) was green with an identical pm-stack/dispatch tree (git log ec68de7f..bcb467ece6 -- pm-stack/dispatch is empty). Order-dependent test pollution, not a product bug.

Change

  • test/server.test.ts: the stub is installed in beforeAll and the captured realFetch is restored in afterAll; an explicit assertion in that hook requires the restored value to be the runtime's native fetch (native code), so dropping the restore fails loudly.
  • test/zz_fetch_hygiene.test.ts (new): guard test asserting globalThis.fetch is the runtime's native fetch, so a leaked stub from any test file fails the suite. The zz_ name keeps it after the stubbing files in Bun's default filename order.

Sibling files already restored correctly and were used as the model (attach_verify.test.ts, auth.test.ts, github.test.ts, queue.test.ts); an audit of pm-stack/dispatch/test/ found no other unrestored global override.

Verification

cd pm-stack/dispatch && bun install --frozen-lockfile

# Before the fix: --randomize reproduced the CI failure on 5 of 10 seeds
bun test --randomize --seed=3 test/server.test.ts test/opencode.test.ts   # 25 pass / 4 fail (baseline)

# After the fix: every previously failing seed green
for s in 3 5 7 8 10; do bun test --randomize --seed=$s test/server.test.ts test/opencode.test.ts; done
# -> 29 pass / 0 fail each

# Both explicit orders green
bun test test/server.test.ts test/opencode.test.ts   # 29 pass / 0 fail
bun test test/opencode.test.ts test/server.test.ts   # 29 pass / 0 fail

# Full suite, twice
bun test   # 206 pass / 2 fail, 208 tests / 13 files
bun test   # 206 pass / 2 fail, 208 tests / 13 files

The 2 remaining failures in both full runs are the pre-existing host-network artifact on this laptop (GitHubClient response-shape validation (#7101) > lookup {} ... and > lookup null body ... timing out at 5000ms); they appear identically on the unmodified tree and are unrelated to this change. bun run typecheck is clean.

Not merging and not closing the issue — watcher merges after review.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-16T05:19:10.833710Z
We couldn’t complete this review. Comment @codex review to try again.
59ce15a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@dezren39
dezren39 merged commit e256e36 into main Nov 16, 2026
1 check failed
@dezren39
dezren39 deleted the queue/17411-main-ci-10609 branch November 16, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant