From ef81d34320701d35a1713357ddea7d35ef783974 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 2 Oct 2026 23:13:06 +0800 Subject: [PATCH] tests: a usage test's offline fetch is put back when its file is done, so the next file doesn't inherit it bun test runs every file in one process, and three usage tests left globalThis.fetch on a fake of theirs: zcode's (offline, set in a beforeEach, never restored), kiro's and workbuddy's (offline, set at import, never restored). A file run after them got that fake: - minimax's tests (27/27 alone) failed 19 after zcode's usage test: the plugin's requests to the local fake MiniMax went to zcode's offline and threw "no network in tests". - qoder's cn.test.mjs takes globalThis.fetch as the real one when it loads; after kiro's or workbuddy's usage test that was offline, so every request meant for its Bun.serve stand-in threw. The CN sign-in, which polls on through errors, timed out at 10 s and kept polling, and the job-token test timed out too, so a full bun test never finished. Each of the three now keeps the fetch it found and puts it back in afterAll. Test-only; no package version changes. HOME=$(mktemp -d) bun test: 341 pass, 0 fail across 42 files (8.5 s); bun scripts/check.mjs passes. --- packages/kiro/usage.test.mjs | 9 +++++++-- packages/workbuddy/usage.test.mjs | 9 +++++++-- packages/zcode/usage.test.mjs | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/kiro/usage.test.mjs b/packages/kiro/usage.test.mjs index 8ec3ced..291d917 100644 --- a/packages/kiro/usage.test.mjs +++ b/packages/kiro/usage.test.mjs @@ -1,6 +1,6 @@ // auth.usage tells what magpie's built-in Kiro usage told for the same // answer (internal/provider/kiro_test.go TestKiroLimits). -import { test, expect, beforeAll, afterEach } from "bun:test" +import { test, expect, afterAll, beforeAll, afterEach } from "bun:test" import { homedir, tmpdir } from "node:os" import { realpathSync } from "node:fs" @@ -11,9 +11,14 @@ beforeAll(async () => { if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run with HOME=$(mktemp -d) bun test") ;({ KiroAuthPlugin: plugin, _internal } = await import("./index.mjs")) }) -// nothing leaves the machine +// nothing leaves the machine; the fetch this file found is put back when +// it is done, so the next test file (bun runs them all in one process) +// doesn't inherit offline: qoder's cn.test.mjs, taking it as the real +// fetch, sent its stand-in's requests nowhere and its sign-in polled on const offline = async () => { throw new Error("no network in tests") } +const real = globalThis.fetch globalThis.fetch = offline +afterAll(() => (globalThis.fetch = real)) afterEach(() => (globalThis.fetch = offline)) const PROFILE = "arn:aws:codewhisperer:us-east-1:111111111111:profile/TEST" diff --git a/packages/workbuddy/usage.test.mjs b/packages/workbuddy/usage.test.mjs index 0ce3ec0..efb519e 100644 --- a/packages/workbuddy/usage.test.mjs +++ b/packages/workbuddy/usage.test.mjs @@ -1,6 +1,6 @@ // auth.usage tells what magpie's built-in WorkBuddy usage told for the same // answers (internal/provider/workbuddy_test.go, workbuddy_ai_test.go). -import { test, expect, beforeAll, afterEach } from "bun:test" +import { test, expect, afterAll, beforeAll, afterEach } from "bun:test" import { mkdirSync, writeFileSync, readFileSync } from "node:fs" import { homedir, tmpdir } from "node:os" import { realpathSync } from "node:fs" @@ -14,9 +14,14 @@ beforeAll(async () => { home = homedir() ;({ WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin, _internal } = await import("./index.mjs")) }) -// nothing leaves the machine +// nothing leaves the machine; the fetch this file found is put back when +// it is done, so the next test file (bun runs them all in one process) +// doesn't inherit offline: qoder's cn.test.mjs, taking it as the real +// fetch, sent its stand-in's requests nowhere and its sign-in polled on const offline = async () => { throw new Error("no network in tests") } +const real = globalThis.fetch globalThis.fetch = offline +afterAll(() => (globalThis.fetch = real)) afterEach(() => { globalThis.fetch = offline _internal.desktopHeld.clear() diff --git a/packages/zcode/usage.test.mjs b/packages/zcode/usage.test.mjs index e63b4a2..44443b3 100644 --- a/packages/zcode/usage.test.mjs +++ b/packages/zcode/usage.test.mjs @@ -1,7 +1,7 @@ // auth.usage tells what magpie's built-in ZCode usage told for the same // answers (internal/provider/zcode_test.go TestZCodeAccounts, // zcode_start_test.go TestZCodeStartPlanOwnAccount, zcode_team_test.go). -import { test, expect, beforeAll, beforeEach } from "bun:test" +import { test, expect, afterAll, beforeAll, beforeEach } from "bun:test" import { homedir, tmpdir } from "node:os" import { realpathSync } from "node:fs" @@ -12,8 +12,12 @@ beforeAll(async () => { if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run with HOME=$(mktemp -d) bun test") ;({ ZCodeAuthPlugin, _internal } = await import("./index.mjs")) }) -// nothing leaves the machine +// nothing leaves the machine; the fetch this file found is put back when +// it is done, so the next test file (bun runs them all in one process) +// doesn't inherit offline or a fake of this file's const offline = async () => { throw new Error("no network in tests") } +const real = globalThis.fetch +afterAll(() => (globalThis.fetch = real)) beforeEach(() => { globalThis.fetch = offline _internal.routes.clear()