diff --git a/extensions/browser/src/browser-tool.test.ts b/extensions/browser/src/browser-tool.test.ts index 7164d3174f0..be941686fc1 100644 --- a/extensions/browser/src/browser-tool.test.ts +++ b/extensions/browser/src/browser-tool.test.ts @@ -108,15 +108,6 @@ vi.mock("./browser/config.js", () => browserConfigMocks); const nodesUtilsMocks = vi.hoisted(() => ({ listNodes: vi.fn(async (..._args: unknown[]): Promise>> => []), })); -vi.mock("../../../src/agents/tools/nodes-utils.js", async () => { - const actual = await vi.importActual( - "../../../src/agents/tools/nodes-utils.js", - ); - return { - ...actual, - listNodes: nodesUtilsMocks.listNodes, - }; -}); const gatewayMocks = vi.hoisted(() => ({ callGatewayTool: vi.fn( @@ -126,7 +117,6 @@ const gatewayMocks = vi.hoisted(() => ({ }), ), })); -vi.mock("../../../src/agents/tools/gateway.js", () => gatewayMocks); const configMocks = vi.hoisted(() => ({ loadConfig: vi.fn< @@ -156,13 +146,15 @@ vi.mock("./browser/session-tab-registry.js", () => sessionTabRegistryMocks); const toolCommonMocks = vi.hoisted(() => ({ imageResultFromFile: vi.fn(), })); -vi.mock("../../../src/agents/tools/common.js", async () => { - const actual = await vi.importActual( - "../../../src/agents/tools/common.js", +vi.mock("openclaw/plugin-sdk/browser-setup-tools", async () => { + const actual = await vi.importActual( + "openclaw/plugin-sdk/browser-setup-tools", ); return { ...actual, + callGatewayTool: gatewayMocks.callGatewayTool, imageResultFromFile: toolCommonMocks.imageResultFromFile, + listNodes: nodesUtilsMocks.listNodes, }; }); diff --git a/extensions/discord/src/monitor/message-handler.preflight.acp-bindings.test.ts b/extensions/discord/src/monitor/message-handler.preflight.acp-bindings.test.ts index 5b1c0a3591a..89119eba68e 100644 --- a/extensions/discord/src/monitor/message-handler.preflight.acp-bindings.test.ts +++ b/extensions/discord/src/monitor/message-handler.preflight.acp-bindings.test.ts @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; const ensureConfiguredBindingRouteReadyMock = vi.hoisted(() => vi.fn()); const resolveConfiguredBindingRouteMock = vi.hoisted(() => vi.fn()); -vi.mock("../../../../src/channels/plugins/binding-routing.js", async () => { +vi.mock("openclaw/plugin-sdk/conversation-runtime", async () => { const { createConfiguredBindingConversationRuntimeModuleMock } = await import("../test-support/configured-binding-runtime.js"); return await createConfiguredBindingConversationRuntimeModuleMock( @@ -13,8 +13,8 @@ vi.mock("../../../../src/channels/plugins/binding-routing.js", async () => { resolveConfiguredBindingRouteMock, }, () => - vi.importActual( - "../../../../src/channels/plugins/binding-routing.js", + vi.importActual( + "openclaw/plugin-sdk/conversation-runtime", ), ); }); diff --git a/extensions/discord/src/send.webhook-activity.test.ts b/extensions/discord/src/send.webhook-activity.test.ts index 01451fc2524..f3d56caa7ff 100644 --- a/extensions/discord/src/send.webhook-activity.test.ts +++ b/extensions/discord/src/send.webhook-activity.test.ts @@ -13,10 +13,10 @@ vi.mock("openclaw/plugin-sdk/plugin-config-runtime", async () => { }; }); -vi.mock("../../../src/infra/channel-activity.js", async () => { - const actual = await vi.importActual( - "../../../src/infra/channel-activity.js", - ); +vi.mock("openclaw/plugin-sdk/channel-activity-runtime", async () => { + const actual = await vi.importActual< + typeof import("openclaw/plugin-sdk/channel-activity-runtime") + >("openclaw/plugin-sdk/channel-activity-runtime"); return { ...actual, recordChannelActivity: (...args: unknown[]) => recordChannelActivityMock(...args), diff --git a/extensions/matrix/src/matrix/client/storage.test.ts b/extensions/matrix/src/matrix/client/storage.test.ts index 54ddea462d3..8132dc8bc5d 100644 --- a/extensions/matrix/src/matrix/client/storage.test.ts +++ b/extensions/matrix/src/matrix/client/storage.test.ts @@ -34,15 +34,6 @@ const maybeCreateMatrixMigrationSnapshotMock = vi.hoisted(() => })), ); -vi.mock("../../../../../src/infra/backup-create.js", async () => { - const actual = await vi.importActual( - "../../../../../src/infra/backup-create.js", - ); - return { - ...actual, - createBackupArchive: (params: unknown) => createBackupArchiveMock(params), - }; -}); vi.mock("./migration-snapshot.runtime.js", () => ({ maybeCreateMatrixMigrationSnapshot: (params: unknown) => maybeCreateMatrixMigrationSnapshotMock(params), diff --git a/extensions/microsoft/speech-provider.test.ts b/extensions/microsoft/speech-provider.test.ts index 14964282a1b..0bda94c8533 100644 --- a/extensions/microsoft/speech-provider.test.ts +++ b/extensions/microsoft/speech-provider.test.ts @@ -2,6 +2,11 @@ import { mkdtempSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; +import { + finalizeDebugProxyCapture, + getDebugProxyCaptureStore, + initializeDebugProxyCapture, +} from "openclaw/plugin-sdk/proxy-capture"; import { afterEach, describe, expect, it, vi } from "vitest"; import { installDebugProxyTestResetHooks } from "../test-support/debug-proxy-env-test-helpers.js"; @@ -81,7 +86,6 @@ describe("listMicrosoftVoices", () => { new Response(JSON.stringify([{ ShortName: "en-US-AvaNeural" }]), { status: 200 }), ) as unknown as typeof globalThis.fetch; - const { getDebugProxyCaptureStore } = await import("../../src/proxy-capture/store.sqlite.js"); const store = getDebugProxyCaptureStore( process.env.OPENCLAW_DEBUG_PROXY_DB_PATH, process.env.OPENCLAW_DEBUG_PROXY_BLOB_DIR, @@ -122,9 +126,6 @@ describe("listMicrosoftVoices", () => { async () => new Response(JSON.stringify([{ ShortName: "en-US-AvaNeural" }]), { status: 200 }), ) as unknown as typeof globalThis.fetch; - const { getDebugProxyCaptureStore } = await import("../../src/proxy-capture/store.sqlite.js"); - const { finalizeDebugProxyCapture, initializeDebugProxyCapture } = - await import("../../src/proxy-capture/runtime.js"); const store = getDebugProxyCaptureStore( process.env.OPENCLAW_DEBUG_PROXY_DB_PATH, process.env.OPENCLAW_DEBUG_PROXY_BLOB_DIR, diff --git a/extensions/msteams/src/block-streaming-config.test.ts b/extensions/msteams/src/block-streaming-config.test.ts index 598f86deb2b..903ccd171ca 100644 --- a/extensions/msteams/src/block-streaming-config.test.ts +++ b/extensions/msteams/src/block-streaming-config.test.ts @@ -1,7 +1,5 @@ import { describe, expect, it } from "vitest"; - -// Import the schema directly to avoid cross-extension import chains -const { MSTeamsConfigSchema } = await import("../../../src/config/zod-schema.providers-core.js"); +import { MSTeamsConfigSchema } from "../config-api.js"; describe("MSTeamsConfigSchema blockStreaming", () => { const baseConfig = { diff --git a/extensions/openai/tts.test.ts b/extensions/openai/tts.test.ts index 98b609b01de..b2779ac6cc1 100644 --- a/extensions/openai/tts.test.ts +++ b/extensions/openai/tts.test.ts @@ -1,6 +1,11 @@ import { mkdtempSync } from "node:fs"; import os from "node:os"; import path from "node:path"; +import { + finalizeDebugProxyCapture, + getDebugProxyCaptureStore, + initializeDebugProxyCapture, +} from "openclaw/plugin-sdk/proxy-capture"; import { describe, expect, it, vi } from "vitest"; import { installDebugProxyTestResetHooks } from "../test-support/debug-proxy-env-test-helpers.js"; import { createStreamingErrorResponse } from "../test-support/streaming-error-response.js"; @@ -255,7 +260,6 @@ describe("openai tts", () => { new Response(Buffer.from("audio-bytes"), { status: 200 }), ) as unknown as typeof globalThis.fetch; - const { getDebugProxyCaptureStore } = await import("../../src/proxy-capture/store.sqlite.js"); const store = getDebugProxyCaptureStore( process.env.OPENCLAW_DEBUG_PROXY_DB_PATH, process.env.OPENCLAW_DEBUG_PROXY_BLOB_DIR, @@ -304,9 +308,7 @@ describe("openai tts", () => { new Response(Buffer.from("audio-bytes"), { status: 200 }), ) as unknown as typeof globalThis.fetch; - const runtime = await import("../../src/proxy-capture/runtime.js"); - const { getDebugProxyCaptureStore } = await import("../../src/proxy-capture/store.sqlite.js"); - runtime.initializeDebugProxyCapture("test"); + initializeDebugProxyCapture("test"); await openaiTTS({ text: "hello", @@ -318,7 +320,7 @@ describe("openai tts", () => { timeoutMs: 5_000, }); await new Promise((resolve) => setTimeout(resolve, 0)); - runtime.finalizeDebugProxyCapture(); + finalizeDebugProxyCapture(); const store = getDebugProxyCaptureStore( process.env.OPENCLAW_DEBUG_PROXY_DB_PATH, diff --git a/extensions/signal/src/monitor/event-handler.inbound-context.test.ts b/extensions/signal/src/monitor/event-handler.inbound-context.test.ts index 6df339b5a76..465efc20001 100644 --- a/extensions/signal/src/monitor/event-handler.inbound-context.test.ts +++ b/extensions/signal/src/monitor/event-handler.inbound-context.test.ts @@ -34,9 +34,9 @@ vi.mock("../send.js", () => ({ sendReadReceiptSignal: sendReadReceiptMock, })); -vi.mock("../../../../src/auto-reply/dispatch.js", async () => { - const actual = await vi.importActual( - "../../../../src/auto-reply/dispatch.js", +vi.mock("openclaw/plugin-sdk/reply-runtime", async () => { + const actual = await vi.importActual( + "openclaw/plugin-sdk/reply-runtime", ); return { ...actual, diff --git a/extensions/slack/src/monitor.tool-result.test.ts b/extensions/slack/src/monitor.tool-result.test.ts index 500c5cca8bd..5a04899a7b0 100644 --- a/extensions/slack/src/monitor.tool-result.test.ts +++ b/extensions/slack/src/monitor.tool-result.test.ts @@ -1,3 +1,6 @@ +import { CURRENT_MESSAGE_MARKER } from "openclaw/plugin-sdk/channel-mention-gating"; +import { resetInboundDedupe } from "openclaw/plugin-sdk/reply-dedupe"; +import { HISTORY_CONTEXT_MARKER } from "openclaw/plugin-sdk/reply-history"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { expectPairingReplyText } from "../../../test/helpers/pairing-reply.js"; import { @@ -13,17 +16,7 @@ import { stopSlackMonitor, } from "./monitor.test-helpers.js"; -const [ - { resetInboundDedupe }, - { HISTORY_CONTEXT_MARKER }, - { CURRENT_MESSAGE_MARKER }, - { monitorSlackProvider }, -] = await Promise.all([ - import("../../../src/auto-reply/reply/inbound-dedupe.js"), - import("../../../src/auto-reply/reply/history.js"), - import("../../../src/auto-reply/reply/mentions.js"), - import("./monitor/provider.js"), -]); +const { monitorSlackProvider } = await import("./monitor/provider.js"); const slackTestState = getSlackTestState(); const { sendMock, replyMock, reactMock, upsertPairingRequestMock } = slackTestState; diff --git a/extensions/telegram/src/bot-message-context.route-test-support.ts b/extensions/telegram/src/bot-message-context.route-test-support.ts index c2c84bf7b26..41be7ee7060 100644 --- a/extensions/telegram/src/bot-message-context.route-test-support.ts +++ b/extensions/telegram/src/bot-message-context.route-test-support.ts @@ -1,3 +1,7 @@ +import { + clearRuntimeConfigSnapshot, + setRuntimeConfigSnapshot, +} from "openclaw/plugin-sdk/config-runtime"; import { vi, type Mock } from "vitest"; import { finalizeTelegramInboundContextForTest } from "./bot-message-context.session-runtime-test-support.js"; @@ -34,13 +38,8 @@ export const telegramRouteTestSessionRuntime = { } satisfies TelegramTestSessionRuntime; export async function loadTelegramMessageContextRouteHarness() { - const [ - { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot }, - { buildTelegramMessageContextForTest }, - ] = await Promise.all([ - import("../../../src/config/config.js"), - import("./bot-message-context.test-harness.js"), - ]); + const { buildTelegramMessageContextForTest } = + await import("./bot-message-context.test-harness.js"); const buildTelegramMessageContextForRouteTest = ( params: BuildTelegramMessageContextForTestParams, ) => diff --git a/extensions/telegram/src/bot-native-commands.registry.test.ts b/extensions/telegram/src/bot-native-commands.registry.test.ts index 286b9ce370b..36e547af2cb 100644 --- a/extensions/telegram/src/bot-native-commands.registry.test.ts +++ b/extensions/telegram/src/bot-native-commands.registry.test.ts @@ -1,9 +1,8 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; +import { clearPluginCommands, registerPluginCommand } from "openclaw/plugin-sdk/plugin-runtime"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; let registerTelegramNativeCommands: typeof import("./bot-native-commands.js").registerTelegramNativeCommands; -let clearPluginCommands: typeof import("../../../src/plugins/commands.js").clearPluginCommands; -let registerPluginCommand: typeof import("../../../src/plugins/commands.js").registerPluginCommand; let setActivePluginRegistry: typeof import("openclaw/plugin-sdk/testing").setActivePluginRegistry; let createCommandBot: typeof import("./bot-native-commands.menu-test-support.js").createCommandBot; let createNativeCommandTestParams: typeof import("./bot-native-commands.menu-test-support.js").createNativeCommandTestParams; @@ -113,8 +112,6 @@ async function registerPairMenu(params: { describe("registerTelegramNativeCommands real plugin registry", () => { beforeAll(async () => { - ({ clearPluginCommands, registerPluginCommand } = - await import("../../../src/plugins/commands.js")); ({ setActivePluginRegistry } = await import("openclaw/plugin-sdk/testing")); ({ registerTelegramNativeCommands } = await import("./bot-native-commands.js")); ({ diff --git a/extensions/telegram/src/bot-native-commands.session-meta.test.ts b/extensions/telegram/src/bot-native-commands.session-meta.test.ts index 3d4bc91da11..c49ad85c60e 100644 --- a/extensions/telegram/src/bot-native-commands.session-meta.test.ts +++ b/extensions/telegram/src/bot-native-commands.session-meta.test.ts @@ -18,7 +18,7 @@ type ResolveConfiguredBindingRouteFn = type EnsureConfiguredBindingRouteReadyFn = typeof import("openclaw/plugin-sdk/conversation-runtime").ensureConfiguredBindingRouteReady; type DispatchReplyWithBufferedBlockDispatcherFn = - typeof import("../../../src/auto-reply/reply/provider-dispatcher.js").dispatchReplyWithBufferedBlockDispatcher; + typeof import("openclaw/plugin-sdk/reply-dispatch-runtime").dispatchReplyWithBufferedBlockDispatcher; type DispatchReplyWithBufferedBlockDispatcherParams = Parameters[0]; type DispatchReplyWithBufferedBlockDispatcherResult = Awaited< @@ -170,14 +170,17 @@ vi.mock("./bot-native-commands.runtime.js", async () => { dispatchReplyWithBufferedBlockDispatcher: replyMocks.dispatchReplyWithBufferedBlockDispatcher, }; }); -vi.mock("../../../src/pairing/pairing-store.js", () => ({ - readChannelAllowFromStore: vi.fn(async () => []), -})); -vi.mock("../../../src/plugins/commands.js", () => ({ - getPluginCommandSpecs: vi.fn(() => []), - matchPluginCommand: vi.fn(() => null), - executePluginCommand: vi.fn(async () => ({ text: "ok" })), -})); +vi.mock("openclaw/plugin-sdk/plugin-runtime", async () => { + const actual = await vi.importActual( + "openclaw/plugin-sdk/plugin-runtime", + ); + return { + ...actual, + getPluginCommandSpecs: vi.fn(() => []), + matchPluginCommand: vi.fn(() => null), + executePluginCommand: vi.fn(async () => ({ text: "ok" })), + }; +}); vi.mock("./bot/delivery.js", () => ({ deliverReplies: deliveryMocks.deliverReplies, })); @@ -237,8 +240,7 @@ function registerAndResolveCommandHandlerBase(params: { const telegramDeps: TelegramNativeCommandDeps = { getRuntimeConfig: vi.fn(() => cfg), readChannelAllowFromStore: vi.fn(async () => []), - dispatchReplyWithBufferedBlockDispatcher: - replyMocks.dispatchReplyWithBufferedBlockDispatcher as TelegramNativeCommandDeps["dispatchReplyWithBufferedBlockDispatcher"], + dispatchReplyWithBufferedBlockDispatcher: replyMocks.dispatchReplyWithBufferedBlockDispatcher, getPluginCommandSpecs: vi.fn(() => []), listSkillCommandsForAgents: vi.fn(() => []), syncTelegramMenuCommands: vi.fn(), diff --git a/extensions/telegram/src/bot-native-commands.skills-allowlist.test.ts b/extensions/telegram/src/bot-native-commands.skills-allowlist.test.ts index 7e5bfd7a776..ff3204b7a3b 100644 --- a/extensions/telegram/src/bot-native-commands.skills-allowlist.test.ts +++ b/extensions/telegram/src/bot-native-commands.skills-allowlist.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; +import { listSkillCommandsForAgents as listActualSkillCommandsForAgents } from "openclaw/plugin-sdk/skill-commands-runtime"; import { afterEach, describe, expect, it, vi } from "vitest"; import { registerTelegramNativeCommands } from "./bot-native-commands.js"; import { @@ -58,10 +59,9 @@ describe("registerTelegramNativeCommands skill allowlist integration", () => { }, ], }; - const actualSkillCommands = await import("../../../src/auto-reply/skill-commands.js"); listSkillCommandsForAgents.mockImplementation( ({ cfg, agentIds }: { cfg: OpenClawConfig; agentIds?: string[] }) => - actualSkillCommands.listSkillCommandsForAgents({ cfg, agentIds }), + listActualSkillCommandsForAgents({ cfg, agentIds }), ); registerTelegramNativeCommands({ diff --git a/extensions/telegram/src/bot.command-menu.test.ts b/extensions/telegram/src/bot.command-menu.test.ts index 4430a7ee0f5..2f0ee2b11fd 100644 --- a/extensions/telegram/src/bot.command-menu.test.ts +++ b/extensions/telegram/src/bot.command-menu.test.ts @@ -1,3 +1,7 @@ +import { + listNativeCommandSpecs, + listNativeCommandSpecsForConfig, +} from "openclaw/plugin-sdk/native-command-registry"; import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../runtime-api.js"; @@ -9,8 +13,6 @@ const { telegramBotRuntimeForTest, } = await import("./bot.create-telegram-bot.test-harness.js"); -let listNativeCommandSpecs: typeof import("../../../src/auto-reply/commands-registry.js").listNativeCommandSpecs; -let listNativeCommandSpecsForConfig: typeof import("../../../src/auto-reply/commands-registry.js").listNativeCommandSpecsForConfig; let normalizeTelegramCommandName: typeof import("./command-config.js").normalizeTelegramCommandName; let createTelegramBotBase: typeof import("./bot-core.js").createTelegramBotCore; let setTelegramBotRuntimeForTest: typeof import("./bot-core.js").setTelegramBotRuntimeForTest; @@ -46,8 +48,6 @@ function resolveSkillCommands(config: Parameters { beforeAll(async () => { - ({ listNativeCommandSpecs, listNativeCommandSpecsForConfig } = - await import("../../../src/auto-reply/commands-registry.js")); ({ normalizeTelegramCommandName } = await import("./command-config.js")); ({ createTelegramBotCore: createTelegramBotBase, setTelegramBotRuntimeForTest } = await import("./bot-core.js")); diff --git a/extensions/telegram/src/bot.test.ts b/extensions/telegram/src/bot.test.ts index 78cc4e78ef9..672abae3d7a 100644 --- a/extensions/telegram/src/bot.test.ts +++ b/extensions/telegram/src/bot.test.ts @@ -4,6 +4,7 @@ import { clearPluginInteractiveHandlers, registerPluginInteractiveHandler, } from "openclaw/plugin-sdk/plugin-runtime"; +import { loadSessionStore } from "openclaw/plugin-sdk/session-store-runtime"; import { mockPinnedHostnameResolution } from "openclaw/plugin-sdk/testing"; import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { TelegramInteractiveHandlerContext } from "./interactive-dispatch.js"; @@ -30,7 +31,6 @@ const { wasSentByBot, } = await import("./bot.create-telegram-bot.test-harness.js"); -let loadSessionStore: typeof import("../../../src/config/sessions.js").loadSessionStore; let createTelegramBotBase: typeof import("./bot-core.js").createTelegramBotCore; let setTelegramBotRuntimeForTest: typeof import("./bot-core.js").setTelegramBotRuntimeForTest; let createTelegramBot: ( @@ -82,7 +82,6 @@ async function loadInboundContextContract() { const ORIGINAL_TZ = process.env.TZ; describe("createTelegramBot", () => { beforeAll(async () => { - ({ loadSessionStore } = await import("../../../src/config/sessions.js")); ({ createTelegramBotCore: createTelegramBotBase, setTelegramBotRuntimeForTest } = await import("./bot-core.js")); }); diff --git a/extensions/telegram/src/fetch.test.ts b/extensions/telegram/src/fetch.test.ts index ace61c184cd..4c04ba7a22b 100644 --- a/extensions/telegram/src/fetch.test.ts +++ b/extensions/telegram/src/fetch.test.ts @@ -1,3 +1,4 @@ +import { resolveFetch } from "openclaw/plugin-sdk/fetch-runtime"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; const setDefaultResultOrder = vi.hoisted(() => vi.fn()); @@ -96,7 +97,6 @@ vi.mock("openclaw/plugin-sdk/runtime-env", () => ({ isWSL2Sync: () => false, })); -let resolveFetch: typeof import("../../../src/infra/fetch.js").resolveFetch; let resolveTelegramFetch: typeof import("./fetch.js").resolveTelegramFetch; let resolveTelegramTransport: typeof import("./fetch.js").resolveTelegramTransport; @@ -105,7 +105,6 @@ type TelegramDispatcherPolicy = NonNullable< >[number]["dispatcherPolicy"]; beforeAll(async () => { - ({ resolveFetch } = await import("../../../src/infra/fetch.js")); ({ resolveTelegramFetch, resolveTelegramTransport } = await import("./fetch.js")); });