From 3850ea1e0f3810d329e3150ed4fc1232ec1d81b3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Mar 2026 00:36:22 +0000 Subject: [PATCH] test: share outbound action runner helpers --- .../message-action-runner.poll.test.ts | 63 +++---------------- .../message-action-runner.test-helpers.ts | 49 +++++++++++++++ .../message-action-runner.threading.test.ts | 62 +++--------------- 3 files changed, 69 insertions(+), 105 deletions(-) create mode 100644 src/infra/outbound/message-action-runner.test-helpers.ts diff --git a/src/infra/outbound/message-action-runner.poll.test.ts b/src/infra/outbound/message-action-runner.poll.test.ts index 43c7489c6fd..895e47605ce 100644 --- a/src/infra/outbound/message-action-runner.poll.test.ts +++ b/src/infra/outbound/message-action-runner.poll.test.ts @@ -1,9 +1,10 @@ -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { slackPlugin } from "../../../extensions/slack/src/channel.js"; -import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; -import type { OpenClawConfig } from "../../config/config.js"; -import { setActivePluginRegistry } from "../../plugins/runtime.js"; -import { createTestRegistry } from "../../test-utils/channel-plugins.js"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { + installMessageActionRunnerTestRegistry, + resetMessageActionRunnerTestRegistry, + slackConfig, + telegramConfig, +} from "./message-action-runner.test-helpers.js"; const mocks = vi.hoisted(() => ({ executePollAction: vi.fn(), @@ -21,25 +22,8 @@ vi.mock("./outbound-send-service.js", async () => { import { runMessageAction } from "./message-action-runner.js"; -const slackConfig = { - channels: { - slack: { - botToken: "xoxb-test", - appToken: "xapp-test", - }, - }, -} as OpenClawConfig; - -const telegramConfig = { - channels: { - telegram: { - botToken: "telegram-test", - }, - }, -} as OpenClawConfig; - async function runPollAction(params: { - cfg: OpenClawConfig; + cfg: typeof slackConfig; actionParams: Record; toolContext?: Record; }) { @@ -59,36 +43,9 @@ async function runPollAction(params: { } | undefined; } - -let createPluginRuntime: typeof import("../../plugins/runtime/index.js").createPluginRuntime; -let setSlackRuntime: typeof import("../../../extensions/slack/src/runtime.js").setSlackRuntime; -let setTelegramRuntime: typeof import("../../../extensions/telegram/src/runtime.js").setTelegramRuntime; - describe("runMessageAction poll handling", () => { - beforeAll(async () => { - ({ createPluginRuntime } = await import("../../plugins/runtime/index.js")); - ({ setSlackRuntime } = await import("../../../extensions/slack/src/runtime.js")); - ({ setTelegramRuntime } = await import("../../../extensions/telegram/src/runtime.js")); - }); - beforeEach(() => { - const runtime = createPluginRuntime(); - setSlackRuntime(runtime); - setTelegramRuntime(runtime); - setActivePluginRegistry( - createTestRegistry([ - { - pluginId: "slack", - source: "test", - plugin: slackPlugin, - }, - { - pluginId: "telegram", - source: "test", - plugin: telegramPlugin, - }, - ]), - ); + installMessageActionRunnerTestRegistry(); mocks.executePollAction.mockResolvedValue({ handledBy: "core", payload: { ok: true }, @@ -97,7 +54,7 @@ describe("runMessageAction poll handling", () => { }); afterEach(() => { - setActivePluginRegistry(createTestRegistry([])); + resetMessageActionRunnerTestRegistry(); mocks.executePollAction.mockReset(); }); diff --git a/src/infra/outbound/message-action-runner.test-helpers.ts b/src/infra/outbound/message-action-runner.test-helpers.ts new file mode 100644 index 00000000000..8ca1ea6a822 --- /dev/null +++ b/src/infra/outbound/message-action-runner.test-helpers.ts @@ -0,0 +1,49 @@ +import { slackPlugin } from "../../../extensions/slack/src/channel.js"; +import { setSlackRuntime } from "../../../extensions/slack/src/runtime.js"; +import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; +import { setTelegramRuntime } from "../../../extensions/telegram/src/runtime.js"; +import type { OpenClawConfig } from "../../config/config.js"; +import { setActivePluginRegistry } from "../../plugins/runtime.js"; +import { createPluginRuntime } from "../../plugins/runtime/index.js"; +import { createTestRegistry } from "../../test-utils/channel-plugins.js"; + +export const slackConfig = { + channels: { + slack: { + botToken: "xoxb-test", + appToken: "xapp-test", + }, + }, +} as OpenClawConfig; + +export const telegramConfig = { + channels: { + telegram: { + botToken: "telegram-test", + }, + }, +} as OpenClawConfig; + +export function installMessageActionRunnerTestRegistry() { + const runtime = createPluginRuntime(); + setSlackRuntime(runtime); + setTelegramRuntime(runtime); + setActivePluginRegistry( + createTestRegistry([ + { + pluginId: "slack", + source: "test", + plugin: slackPlugin, + }, + { + pluginId: "telegram", + source: "test", + plugin: telegramPlugin, + }, + ]), + ); +} + +export function resetMessageActionRunnerTestRegistry() { + setActivePluginRegistry(createTestRegistry([])); +} diff --git a/src/infra/outbound/message-action-runner.threading.test.ts b/src/infra/outbound/message-action-runner.threading.test.ts index b668aea14b5..42d898b145a 100644 --- a/src/infra/outbound/message-action-runner.threading.test.ts +++ b/src/infra/outbound/message-action-runner.threading.test.ts @@ -1,9 +1,10 @@ -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { slackPlugin } from "../../../extensions/slack/src/channel.js"; -import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; -import type { OpenClawConfig } from "../../config/config.js"; -import { setActivePluginRegistry } from "../../plugins/runtime.js"; -import { createTestRegistry } from "../../test-utils/channel-plugins.js"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { + installMessageActionRunnerTestRegistry, + resetMessageActionRunnerTestRegistry, + slackConfig, + telegramConfig, +} from "./message-action-runner.test-helpers.js"; const mocks = vi.hoisted(() => ({ executeSendAction: vi.fn(), @@ -32,25 +33,8 @@ vi.mock("../../config/sessions.js", async () => { import { runMessageAction } from "./message-action-runner.js"; -const slackConfig = { - channels: { - slack: { - botToken: "xoxb-test", - appToken: "xapp-test", - }, - }, -} as OpenClawConfig; - -const telegramConfig = { - channels: { - telegram: { - botToken: "telegram-test", - }, - }, -} as OpenClawConfig; - async function runThreadingAction(params: { - cfg: OpenClawConfig; + cfg: typeof slackConfig; actionParams: Record; toolContext?: Record; }) { @@ -80,39 +64,13 @@ const defaultTelegramToolContext = { currentThreadTs: "42", } as const; -let createPluginRuntime: typeof import("../../plugins/runtime/index.js").createPluginRuntime; -let setSlackRuntime: typeof import("../../../extensions/slack/src/runtime.js").setSlackRuntime; -let setTelegramRuntime: typeof import("../../../extensions/telegram/src/runtime.js").setTelegramRuntime; - describe("runMessageAction threading auto-injection", () => { - beforeAll(async () => { - ({ createPluginRuntime } = await import("../../plugins/runtime/index.js")); - ({ setSlackRuntime } = await import("../../../extensions/slack/src/runtime.js")); - ({ setTelegramRuntime } = await import("../../../extensions/telegram/src/runtime.js")); - }); - beforeEach(() => { - const runtime = createPluginRuntime(); - setSlackRuntime(runtime); - setTelegramRuntime(runtime); - setActivePluginRegistry( - createTestRegistry([ - { - pluginId: "slack", - source: "test", - plugin: slackPlugin, - }, - { - pluginId: "telegram", - source: "test", - plugin: telegramPlugin, - }, - ]), - ); + installMessageActionRunnerTestRegistry(); }); afterEach(() => { - setActivePluginRegistry(createTestRegistry([])); + resetMessageActionRunnerTestRegistry(); mocks.executeSendAction.mockClear(); mocks.recordSessionMetaFromInbound.mockClear(); });