refactor: move slack system events onto channel runtime

This commit is contained in:
Peter Steinberger
2026-03-28 03:36:04 +00:00
parent 7918524229
commit d83e3afc56
10 changed files with 49 additions and 20 deletions

View File

@@ -4,13 +4,18 @@ const enqueueSystemEventMock = vi.hoisted(() => vi.fn());
let registerSlackChannelEvents: typeof import("./channels.js").registerSlackChannelEvents;
let createSlackSystemEventTestHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
async function createChannelRuntimeMock(
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/channel-runtime")>,
) {
const actual = await importOriginal();
return {
...actual,
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
};
});
}
vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock);
type SlackChannelHandler = (args: {
event: Record<string, unknown>;
@@ -33,6 +38,7 @@ function createChannelContext(params?: {
describe("registerSlackChannelEvents", () => {
beforeAll(async () => {
vi.resetModules();
({ registerSlackChannelEvents } = await import("./channels.js"));
({ createSlackSystemEventTestHarness } = await import("./system-event-test-harness.js"));
});

View File

@@ -1,7 +1,7 @@
import type { SlackEventMiddlewareArgs } from "@slack/bolt";
import { resolveChannelConfigWrites } from "openclaw/plugin-sdk/channel-config-writes";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime";
import { loadConfig, writeConfigFile } from "openclaw/plugin-sdk/config-runtime";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime";
import { danger, warn } from "openclaw/plugin-sdk/runtime-env";
import { migrateSlackChannelConfig } from "../../channel-migration.js";
import { resolveSlackChannelLabel } from "../channel-config.js";

View File

@@ -7,10 +7,15 @@ let registerSlackMemberEvents: typeof import("./members.js").registerSlackMember
let initSlackHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
type MemberOverrides = import("./system-event-test-harness.js").SlackSystemEventTestOverrides;
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
async function createChannelRuntimeMock(
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/channel-runtime")>,
) {
const actual = await importOriginal();
return { ...actual, enqueueSystemEvent: memberMocks.enqueue };
});
}
vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock);
type MemberHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;
@@ -66,6 +71,7 @@ async function runMemberCase(args: MemberCaseArgs = {}): Promise<void> {
describe("registerSlackMemberEvents", () => {
beforeAll(async () => {
vi.resetModules();
({ registerSlackMemberEvents } = await import("./members.js"));
({ createSlackSystemEventTestHarness: initSlackHarness } =
await import("./system-event-test-harness.js"));

View File

@@ -1,5 +1,5 @@
import type { SlackEventMiddlewareArgs } from "@slack/bolt";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime";
import { danger } from "openclaw/plugin-sdk/runtime-env";
import type { SlackMonitorContext } from "../context.js";
import type { SlackMemberChannelEvent } from "../types.js";

View File

@@ -7,13 +7,18 @@ import {
const messageQueueMock = vi.fn();
const messageAllowMock = vi.fn();
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
async function createChannelRuntimeMock(
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/channel-runtime")>,
) {
const actual = await importOriginal();
return {
...actual,
enqueueSystemEvent: (...args: unknown[]) => messageQueueMock(...args),
};
});
}
vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/conversation-runtime")>();
@@ -53,6 +58,7 @@ function resetMessageMocks(): void {
}
beforeAll(async () => {
vi.resetModules();
({ registerSlackMessageEvents } = await import("./messages.js"));
});

View File

@@ -1,5 +1,5 @@
import type { SlackEventMiddlewareArgs } from "@slack/bolt";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime";
import { danger } from "openclaw/plugin-sdk/runtime-env";
import type { SlackAppMentionEvent, SlackMessageEvent } from "../../types.js";
import { normalizeSlackChannelType } from "../channel-type.js";

View File

@@ -5,10 +5,15 @@ let registerSlackPinEvents: typeof import("./pins.js").registerSlackPinEvents;
let buildPinHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
type PinOverrides = import("./system-event-test-harness.js").SlackSystemEventTestOverrides;
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
async function createChannelRuntimeMock(
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/channel-runtime")>,
) {
const actual = await importOriginal();
return { ...actual, enqueueSystemEvent: pinEnqueueMock };
});
}
vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock);
type PinHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;
@@ -70,6 +75,7 @@ async function runPinCase(input: PinCase = {}): Promise<void> {
describe("registerSlackPinEvents", () => {
beforeAll(async () => {
vi.resetModules();
({ registerSlackPinEvents } = await import("./pins.js"));
({ createSlackSystemEventTestHarness: buildPinHarness } =
await import("./system-event-test-harness.js"));

View File

@@ -1,5 +1,5 @@
import type { SlackEventMiddlewareArgs } from "@slack/bolt";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime";
import { danger } from "openclaw/plugin-sdk/runtime-env";
import type { SlackMonitorContext } from "../context.js";
import type { SlackPinEvent } from "../types.js";

View File

@@ -6,13 +6,18 @@ let createSlackSystemEventTestHarness: typeof import("./system-event-test-harnes
type SlackSystemEventTestOverrides =
import("./system-event-test-harness.js").SlackSystemEventTestOverrides;
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
async function createChannelRuntimeMock(
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/channel-runtime")>,
) {
const actual = await importOriginal();
return {
...actual,
enqueueSystemEvent: (...args: unknown[]) => reactionQueueMock(...args),
};
});
}
vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock);
type ReactionHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;

View File

@@ -1,5 +1,5 @@
import type { SlackEventMiddlewareArgs } from "@slack/bolt";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime";
import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime";
import { danger } from "openclaw/plugin-sdk/runtime-env";
import type { SlackMonitorContext } from "../context.js";
import type { SlackReactionEvent } from "../types.js";