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()