mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
refactor: move slack system events onto channel runtime
This commit is contained in:
@@ -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"));
|
||||
});
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user