diff --git a/src/auto-reply/commands-registry.test.ts b/src/auto-reply/commands-registry.test.ts index 4d91ea90f80..653c06eed32 100644 --- a/src/auto-reply/commands-registry.test.ts +++ b/src/auto-reply/commands-registry.test.ts @@ -1,43 +1,26 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { setActivePluginRegistry } from "../plugins/runtime.js"; import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; +import { + buildCommandText, + buildCommandTextFromArgs, + findCommandByNativeName, + getCommandDetection, + listChatCommands, + listChatCommandsForConfig, + listNativeCommandSpecs, + listNativeCommandSpecsForConfig, + normalizeCommandBody, + parseCommandArgs, + resolveCommandArgChoices, + resolveCommandArgMenu, + serializeCommandArgs, + shouldHandleTextCommands, +} from "./commands-registry.js"; import type { ChatCommandDefinition } from "./commands-registry.types.js"; -let setActivePluginRegistry: typeof import("../plugins/runtime.js").setActivePluginRegistry; -let buildCommandText: typeof import("./commands-registry.js").buildCommandText; -let buildCommandTextFromArgs: typeof import("./commands-registry.js").buildCommandTextFromArgs; -let findCommandByNativeName: typeof import("./commands-registry.js").findCommandByNativeName; -let getCommandDetection: typeof import("./commands-registry.js").getCommandDetection; -let listChatCommands: typeof import("./commands-registry.js").listChatCommands; -let listChatCommandsForConfig: typeof import("./commands-registry.js").listChatCommandsForConfig; -let listNativeCommandSpecs: typeof import("./commands-registry.js").listNativeCommandSpecs; -let listNativeCommandSpecsForConfig: typeof import("./commands-registry.js").listNativeCommandSpecsForConfig; -let normalizeCommandBody: typeof import("./commands-registry.js").normalizeCommandBody; -let parseCommandArgs: typeof import("./commands-registry.js").parseCommandArgs; -let resolveCommandArgChoices: typeof import("./commands-registry.js").resolveCommandArgChoices; -let resolveCommandArgMenu: typeof import("./commands-registry.js").resolveCommandArgMenu; -let serializeCommandArgs: typeof import("./commands-registry.js").serializeCommandArgs; -let shouldHandleTextCommands: typeof import("./commands-registry.js").shouldHandleTextCommands; - -beforeEach(async () => { - vi.resetModules(); +beforeEach(() => { vi.doUnmock("../channels/plugins/index.js"); - ({ setActivePluginRegistry } = await import("../plugins/runtime.js")); - ({ - buildCommandText, - buildCommandTextFromArgs, - findCommandByNativeName, - getCommandDetection, - listChatCommands, - listChatCommandsForConfig, - listNativeCommandSpecs, - listNativeCommandSpecsForConfig, - normalizeCommandBody, - parseCommandArgs, - resolveCommandArgChoices, - resolveCommandArgMenu, - serializeCommandArgs, - shouldHandleTextCommands, - } = await import("./commands-registry.js")); setActivePluginRegistry(createTestRegistry([])); }); diff --git a/src/auto-reply/reply/session-hooks-context.test.ts b/src/auto-reply/reply/session-hooks-context.test.ts index c7fe1ce5dcb..dc13e136757 100644 --- a/src/auto-reply/reply/session-hooks-context.test.ts +++ b/src/auto-reply/reply/session-hooks-context.test.ts @@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../../config/config.js"; import type { SessionEntry } from "../../config/sessions.js"; import type { HookRunner } from "../../plugins/hooks.js"; +import { initSessionState } from "./session.js"; const hookRunnerMocks = vi.hoisted(() => ({ hasHooks: vi.fn(), @@ -12,7 +13,14 @@ const hookRunnerMocks = vi.hoisted(() => ({ runSessionEnd: vi.fn(), })); -let initSessionState: typeof import("./session.js").initSessionState; +vi.mock("../../plugins/hook-runner-global.js", () => ({ + getGlobalHookRunner: () => + ({ + hasHooks: hookRunnerMocks.hasHooks, + runSessionStart: hookRunnerMocks.runSessionStart, + runSessionEnd: hookRunnerMocks.runSessionEnd, + }) as unknown as HookRunner, +})); async function createStorePath(prefix: string): Promise { const root = await fs.mkdtemp(path.join(os.tmpdir(), `${prefix}-`)); @@ -46,16 +54,7 @@ async function writeTranscript( } describe("session hook context wiring", () => { - beforeEach(async () => { - vi.resetModules(); - vi.doMock("../../plugins/hook-runner-global.js", () => ({ - getGlobalHookRunner: () => - ({ - hasHooks: hookRunnerMocks.hasHooks, - runSessionStart: hookRunnerMocks.runSessionStart, - runSessionEnd: hookRunnerMocks.runSessionEnd, - }) as unknown as HookRunner, - })); + beforeEach(() => { hookRunnerMocks.hasHooks.mockReset(); hookRunnerMocks.runSessionStart.mockReset(); hookRunnerMocks.runSessionEnd.mockReset(); @@ -64,7 +63,6 @@ describe("session hook context wiring", () => { hookRunnerMocks.hasHooks.mockImplementation( (hookName) => hookName === "session_start" || hookName === "session_end", ); - ({ initSessionState } = await import("./session.js")); }); afterEach(() => {