diff --git a/src/hooks/anthropic-context-window-limit-recovery/aggressive-truncation-strategy.test.ts b/src/hooks/anthropic-context-window-limit-recovery/aggressive-truncation-strategy.test.ts index 804fbf46c..7116ed437 100644 --- a/src/hooks/anthropic-context-window-limit-recovery/aggressive-truncation-strategy.test.ts +++ b/src/hooks/anthropic-context-window-limit-recovery/aggressive-truncation-strategy.test.ts @@ -1,5 +1,5 @@ /// -import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test" +import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from "bun:test" import type { AutoCompactState } from "./types" @@ -38,6 +38,10 @@ mock.module("../../features/hook-message-injector", () => ({ import { _resetForTesting as resetSessionState, updateSessionAgent } from "../../features/claude-code-session-state/state" import { runAggressiveTruncationStrategy } from "./aggressive-truncation-strategy" +afterAll(() => { + mock.restore() +}) + type FakeClient = { session: { promptAsync: (input: PromptAsyncCall) => Promise diff --git a/src/hooks/anthropic-context-window-limit-recovery/storage.test.ts b/src/hooks/anthropic-context-window-limit-recovery/storage.test.ts index e649a1bbf..c38cf7c4d 100644 --- a/src/hooks/anthropic-context-window-limit-recovery/storage.test.ts +++ b/src/hooks/anthropic-context-window-limit-recovery/storage.test.ts @@ -18,8 +18,8 @@ mock.module("./tool-result-storage", () => ({ truncateToolResult, })) -async function importFreshStorage(): Promise { - return import(`./storage?test=${Date.now()}-${Math.random()}`) +async function importFreshStorage(): Promise { + return import(`./target-token-truncation?test=${Date.now()}-${Math.random()}`) } afterAll(() => { diff --git a/src/hooks/atlas/background-task-retry.test.ts b/src/hooks/atlas/background-task-retry.test.ts index 3df7194a0..0ac0e1e16 100644 --- a/src/hooks/atlas/background-task-retry.test.ts +++ b/src/hooks/atlas/background-task-retry.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test" +import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from "bun:test" import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" @@ -16,6 +16,10 @@ mock.module("../../shared/opencode-storage-detection", () => ({ resetSqliteBackendCache: () => {}, })) +afterAll(() => { + mock.restore() +}) + type LongTimerCallback = (...args: unknown[]) => void | Promise describe("atlas background task retry", () => { diff --git a/src/hooks/auto-update-checker/hook.test.ts b/src/hooks/auto-update-checker/hook.test.ts index a6cacd54d..0047dfbce 100644 --- a/src/hooks/auto-update-checker/hook.test.ts +++ b/src/hooks/auto-update-checker/hook.test.ts @@ -1,5 +1,5 @@ import type { PluginInput } from "@opencode-ai/plugin" -import { describe, expect, mock, test } from "bun:test" +import { afterAll, describe, expect, mock, test } from "bun:test" type CreateAutoUpdateCheckerHook = typeof import("./hook").createAutoUpdateCheckerHook type HookOptions = Parameters[1] @@ -34,6 +34,10 @@ mock.module("./hook/deferred-startup-check", () => ({ scheduleDeferredStartupCheck: scheduleDeferredStartupCheckMock, })) +afterAll(() => { + mock.restore() +}) + const createPluginInput = (): PluginInput => ({ client: {} as PluginInput["client"], directory: "/tmp/project", @@ -41,6 +45,7 @@ const createPluginInput = (): PluginInput => ({ worktree: "/tmp/project", serverUrl: new URL("https://example.com"), $: {} as PluginInput["$"], + experimental_workspace: { register: () => {} }, } satisfies PluginInput) const createDeps = (overrides: Partial = {}) => { diff --git a/src/hooks/claude-code-hooks/dispatch-hook.test.ts b/src/hooks/claude-code-hooks/dispatch-hook.test.ts index b8c0bda53..74140a955 100644 --- a/src/hooks/claude-code-hooks/dispatch-hook.test.ts +++ b/src/hooks/claude-code-hooks/dispatch-hook.test.ts @@ -1,4 +1,4 @@ -const { afterEach, beforeEach, describe, expect, mock, test } = require("bun:test") +const { afterAll, afterEach, beforeEach, describe, expect, mock, test } = require("bun:test") const capturedOptions: Array> = [] @@ -19,6 +19,10 @@ mock.module("./execute-http-hook", () => ({ const { dispatchHook } = await import("./dispatch-hook") +afterAll(() => { + mock.restore() +}) + describe("dispatchHook", () => { beforeEach(() => { mockExecuteHookCommand.mockClear() diff --git a/src/hooks/legacy-plugin-toast/auto-migrate.test.ts b/src/hooks/legacy-plugin-toast/auto-migrate.test.ts index 1ef64e108..dacb9f3ed 100644 --- a/src/hooks/legacy-plugin-toast/auto-migrate.test.ts +++ b/src/hooks/legacy-plugin-toast/auto-migrate.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test" +import { afterAll, afterEach, beforeEach, describe, expect, it, mock } from "bun:test" import { mkdirSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" @@ -14,6 +14,10 @@ mock.module("./plugin-entry-migrator.ts", () => ({ const autoMigrateModulePromise = import("./auto-migrate") +afterAll(() => { + mock.restore() +}) + describe("autoMigrateLegacyPluginEntry", () => { let testConfigDir = "" diff --git a/src/hooks/zauc-mocks-hook/hook.test.ts b/src/hooks/zauc-mocks-hook/hook.test.ts index de0e4d3d2..64360ddf3 100644 --- a/src/hooks/zauc-mocks-hook/hook.test.ts +++ b/src/hooks/zauc-mocks-hook/hook.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test" +import { afterAll, afterEach, beforeEach, describe, expect, it, mock } from "bun:test" let scheduledDeferredCheck: (() => void) | null = null mock.module("../auto-update-checker/hook/deferred-startup-check", () => ({ @@ -9,6 +9,10 @@ mock.module("../auto-update-checker/hook/deferred-startup-check", () => ({ const { createAutoUpdateCheckerHook } = await import("../auto-update-checker/hook") +afterAll(() => { + mock.restore() +}) + const mockShowConfigErrorsIfAny = mock(async () => {}) const mockShowModelCacheWarningIfNeeded = mock(async () => {}) const mockUpdateAndShowConnectedProvidersCacheStatus = mock(async () => {}) diff --git a/src/plugin-handlers/hook-config-handler.test.ts b/src/plugin-handlers/hook-config-handler.test.ts index 1c9085e0a..340fd5f72 100644 --- a/src/plugin-handlers/hook-config-handler.test.ts +++ b/src/plugin-handlers/hook-config-handler.test.ts @@ -1,4 +1,4 @@ -const { afterEach, beforeEach, describe, expect, mock, test } = require("bun:test") +const { afterAll, afterEach, beforeEach, describe, expect, mock, test } = require("bun:test") const mockSetPluginHooksConfigs = mock(() => {}) @@ -8,6 +8,10 @@ mock.module("../hooks/claude-code-hooks/config", () => ({ const { applyHookConfig } = await import("./hook-config-handler") +afterAll(() => { + mock.restore() +}) + describe("applyHookConfig", () => { beforeEach(() => { mockSetPluginHooksConfigs.mockClear()