Skip to content

developing-today/code / pm-stack tests: dispatch suite flakes on main — server.test.ts module-scope fetch stub leaks into other test files (run 43807605419) #10609

Closed

Description

@dezren39

Failure

Main-branch run 43807605419 (push, head bcb467ece6, workflow pm-stack tests) failed job aggregator + projector + dispatch + python suites + quota exporters at step Test dispatch — 203 pass / 4 fail:

(fail) OpenCodeClient auth file boundary (#7085) > control: a valid auth file resolves and sends the password verbatim
(fail) OpenCodeClient response body boundary (#7085) > a non-JSON 200 body is an OpenCodeError, not a raw SyntaxError
(fail) OpenCodeClient.getSession (#5555) > returns the session object on 200 (envelope unwrapped)
(fail) OpenCodeClient.getSession (#5555) > returns null on 404 — the session does not exist
error: opencode GET /api/session/ses_ok unreachable: unexpected network fetch in test: http://127.0.0.1:45791/api/session/ses_ok

It is a flake, and the defect is test isolation

A manual workflow_dispatch of the same workflow on the same head bcb467ece6 is green: run 43808691940 (dispatched 2026-11-16T05:12Z, success). The dispatch suite also passed on ec68de7f (run 43792350594) with an identical pm-stack/dispatch tree — no dispatch source changed between them.

Root cause: pm-stack/dispatch/test/server.test.ts installs a global fetch override at module scope and never restores it:

// pm-stack/dispatch/test/server.test.ts:16-25
const realFetch = globalThis.fetch;
globalThis.fetch = (async (input: unknown) => {
  if (String(input) === JWKS_URL) { ... }
  throw new Error(`unexpected network fetch in test: ${String(input)}`);
}) as typeof fetch;

realFetch is captured but never restored. Bun executes the dispatch suite's 12 test files in one process, so once server.test.ts has been loaded, every later file that performs a real local-HTTP request (opencode.test.ts drives 127.0.0.1:<port>/api/session*) throws that guard. Whether the suite is red depends purely on file execution order — which is why the same tree goes green and red.

Sibling files already do this correctly (attach_verify.test.ts:148/171/181, auth.test.ts:246/259, github.test.ts:67, queue.test.ts:124 restore realFetch in their cleanup hooks). server.test.ts is the only module-scope stubbing file that never restores.

Fix

  • Restore globalThis.fetch = realFetch in server.test.ts (an afterAll, plus per-test beforeEach/afterEach scoping for the stub) so no state escapes the file.
  • Audit the suite for any other module-scope global mutation that is not restored.
  • Add a guard test that fails when a global fetch override survives a test file (e.g. a small test that asserts globalThis.fetch identity before/after walking the suite), so a future leak cannot silently return.

Related

Activity

  1. added
    kind/ciCI/CD pipelines, workflows, and build automation
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    on Nov 16, 2026
  2. developing-today commented on Nov 16, 2026

    @developing-today
    Contributor
  3. added
    source/ci-watchFiled by the main-ci-failure-fix-trigger (fleet CI watch)
    on Nov 16, 2026
  4. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Agent note — fix opened: #10610 (queue/17411-main-ci-10609, commit 59ce15a; not merged, not closing this issue)

    Root cause confirmed as reported: pm-stack/dispatch/test/server.test.ts replaced globalThis.fetch at module scope and never restored it, so whenever it was evaluated before opencode.test.ts the OpenCodeClient's real http://127.0.0.1:<port>/api/session* calls threw unexpected network fetch in test: .... Reproduced deterministically on Bun 1.4.4 with --randomize (4 failures on seeds 3, 5, 7, 8, 10 of 10), matching run 43807605419.

    Fix: stub installed in beforeAll, realFetch restored in afterAll with an explicit native-fetch assertion; new guard test test/zz_fetch_hygiene.test.ts fails if any global fetch stub survives. Audit of pm-stack/dispatch/test/ found no other unrestored global override.

    Verification (all after the change):

    Leaving the PR unmerged for watcher review.

  5. added a commit that references this issue on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/ciCI/CD pipelines, workflows, and build automationsource/ci-watchFiled by the main-ci-failure-fix-trigger (fleet CI watch)status/needs-triageNot yet triaged; needs a first lookstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions