test: share outbound action runner helpers

This commit is contained in:
Peter Steinberger
2026-03-14 00:36:22 +00:00
parent 8de2f7339c
commit 3850ea1e0f
3 changed files with 69 additions and 105 deletions

View File

@@ -1,9 +1,10 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { slackPlugin } from "../../../extensions/slack/src/channel.js"; import {
import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; installMessageActionRunnerTestRegistry,
import type { OpenClawConfig } from "../../config/config.js"; resetMessageActionRunnerTestRegistry,
import { setActivePluginRegistry } from "../../plugins/runtime.js"; slackConfig,
import { createTestRegistry } from "../../test-utils/channel-plugins.js"; telegramConfig,
} from "./message-action-runner.test-helpers.js";
const mocks = vi.hoisted(() => ({ const mocks = vi.hoisted(() => ({
executePollAction: vi.fn(), executePollAction: vi.fn(),
@@ -21,25 +22,8 @@ vi.mock("./outbound-send-service.js", async () => {
import { runMessageAction } from "./message-action-runner.js"; 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: { async function runPollAction(params: {
cfg: OpenClawConfig; cfg: typeof slackConfig;
actionParams: Record<string, unknown>; actionParams: Record<string, unknown>;
toolContext?: Record<string, unknown>; toolContext?: Record<string, unknown>;
}) { }) {
@@ -59,36 +43,9 @@ async function runPollAction(params: {
} }
| undefined; | 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", () => { 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(() => { beforeEach(() => {
const runtime = createPluginRuntime(); installMessageActionRunnerTestRegistry();
setSlackRuntime(runtime);
setTelegramRuntime(runtime);
setActivePluginRegistry(
createTestRegistry([
{
pluginId: "slack",
source: "test",
plugin: slackPlugin,
},
{
pluginId: "telegram",
source: "test",
plugin: telegramPlugin,
},
]),
);
mocks.executePollAction.mockResolvedValue({ mocks.executePollAction.mockResolvedValue({
handledBy: "core", handledBy: "core",
payload: { ok: true }, payload: { ok: true },
@@ -97,7 +54,7 @@ describe("runMessageAction poll handling", () => {
}); });
afterEach(() => { afterEach(() => {
setActivePluginRegistry(createTestRegistry([])); resetMessageActionRunnerTestRegistry();
mocks.executePollAction.mockReset(); mocks.executePollAction.mockReset();
}); });

View File

@@ -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([]));
}

View File

@@ -1,9 +1,10 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { slackPlugin } from "../../../extensions/slack/src/channel.js"; import {
import { telegramPlugin } from "../../../extensions/telegram/src/channel.js"; installMessageActionRunnerTestRegistry,
import type { OpenClawConfig } from "../../config/config.js"; resetMessageActionRunnerTestRegistry,
import { setActivePluginRegistry } from "../../plugins/runtime.js"; slackConfig,
import { createTestRegistry } from "../../test-utils/channel-plugins.js"; telegramConfig,
} from "./message-action-runner.test-helpers.js";
const mocks = vi.hoisted(() => ({ const mocks = vi.hoisted(() => ({
executeSendAction: vi.fn(), executeSendAction: vi.fn(),
@@ -32,25 +33,8 @@ vi.mock("../../config/sessions.js", async () => {
import { runMessageAction } from "./message-action-runner.js"; 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: { async function runThreadingAction(params: {
cfg: OpenClawConfig; cfg: typeof slackConfig;
actionParams: Record<string, unknown>; actionParams: Record<string, unknown>;
toolContext?: Record<string, unknown>; toolContext?: Record<string, unknown>;
}) { }) {
@@ -80,39 +64,13 @@ const defaultTelegramToolContext = {
currentThreadTs: "42", currentThreadTs: "42",
} as const; } 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", () => { 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(() => { beforeEach(() => {
const runtime = createPluginRuntime(); installMessageActionRunnerTestRegistry();
setSlackRuntime(runtime);
setTelegramRuntime(runtime);
setActivePluginRegistry(
createTestRegistry([
{
pluginId: "slack",
source: "test",
plugin: slackPlugin,
},
{
pluginId: "telegram",
source: "test",
plugin: telegramPlugin,
},
]),
);
}); });
afterEach(() => { afterEach(() => {
setActivePluginRegistry(createTestRegistry([])); resetMessageActionRunnerTestRegistry();
mocks.executeSendAction.mockClear(); mocks.executeSendAction.mockClear();
mocks.recordSessionMetaFromInbound.mockClear(); mocks.recordSessionMetaFromInbound.mockClear();
}); });