test(slack): narrow event runtime mocks

This commit is contained in:
Peter Steinberger
2026-04-23 11:50:48 +01:00
parent aa95428265
commit b3ebbe5ba0
6 changed files with 56 additions and 65 deletions

View File

@@ -4,18 +4,15 @@ const enqueueSystemEventMock = vi.hoisted(() => vi.fn());
let registerSlackChannelEvents: typeof import("./channels.js").registerSlackChannelEvents;
let createSlackSystemEventTestHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
async function createChannelRuntimeMock() {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
"openclaw/plugin-sdk/infra-runtime",
);
return {
...actual,
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
};
}
vi.mock("openclaw/plugin-sdk/infra-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime.js", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
}));
vi.mock("openclaw/plugin-sdk/infra-runtime.js", () => ({
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
}));
vi.mock("openclaw/plugin-sdk/security-runtime", () => ({
readStoreAllowFromForDmPolicy: async () => [],
}));
type SlackChannelHandler = (args: {
event: Record<string, unknown>;

View File

@@ -17,6 +17,10 @@ vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
}));
vi.mock("openclaw/plugin-sdk/security-runtime", () => ({
readStoreAllowFromForDmPolicy: async () => [],
}));
vi.mock("../../interactive-dispatch.js", () => ({
dispatchSlackPluginInteractiveHandler: (params: {
data: string;

View File

@@ -7,15 +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;
async function createChannelRuntimeMock() {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
"openclaw/plugin-sdk/infra-runtime",
);
return { ...actual, enqueueSystemEvent: memberMocks.enqueue };
}
vi.mock("openclaw/plugin-sdk/infra-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime.js", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
enqueueSystemEvent: (...args: unknown[]) => memberMocks.enqueue(...args),
}));
vi.mock("openclaw/plugin-sdk/infra-runtime.js", () => ({
enqueueSystemEvent: (...args: unknown[]) => memberMocks.enqueue(...args),
}));
vi.mock("openclaw/plugin-sdk/security-runtime", () => ({
readStoreAllowFromForDmPolicy: async () => [],
}));
type MemberHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;

View File

@@ -4,31 +4,24 @@ import {
type SlackSystemEventTestOverrides,
} from "./system-event-test-harness.js";
const messageQueueMock = vi.fn();
const messageAllowMock = vi.fn();
const { messageQueueMock, messageAllowMock } = vi.hoisted(() => ({
messageQueueMock: vi.fn(),
messageAllowMock: vi.fn(),
}));
async function createChannelRuntimeMock() {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
"openclaw/plugin-sdk/infra-runtime",
);
return {
...actual,
enqueueSystemEvent: (...args: unknown[]) => messageQueueMock(...args),
};
}
vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
enqueueSystemEvent: (...args: unknown[]) => messageQueueMock(...args),
}));
vi.mock("openclaw/plugin-sdk/infra-runtime.js", () => ({
enqueueSystemEvent: (...args: unknown[]) => messageQueueMock(...args),
}));
vi.mock("openclaw/plugin-sdk/security-runtime", () => ({
readStoreAllowFromForDmPolicy: async () => [],
}));
vi.mock("openclaw/plugin-sdk/infra-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime.js", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/conversation-runtime", async () => {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/conversation-runtime")>(
"openclaw/plugin-sdk/conversation-runtime",
);
return {
...actual,
readChannelAllowFromStore: (...args: unknown[]) => messageAllowMock(...args),
};
});
vi.mock("openclaw/plugin-sdk/conversation-runtime", () => ({
readChannelAllowFromStore: (...args: unknown[]) => messageAllowMock(...args),
}));
let registerSlackMessageEvents: typeof import("./messages.js").registerSlackMessageEvents;

View File

@@ -5,15 +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;
async function createChannelRuntimeMock() {
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
"openclaw/plugin-sdk/infra-runtime",
);
return { ...actual, enqueueSystemEvent: pinEnqueueMock };
}
vi.mock("openclaw/plugin-sdk/infra-runtime", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime.js", createChannelRuntimeMock);
vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
enqueueSystemEvent: (...args: unknown[]) => pinEnqueueMock(...args),
}));
vi.mock("openclaw/plugin-sdk/infra-runtime.js", () => ({
enqueueSystemEvent: (...args: unknown[]) => pinEnqueueMock(...args),
}));
vi.mock("openclaw/plugin-sdk/security-runtime", () => ({
readStoreAllowFromForDmPolicy: async () => [],
}));
type PinHandler = (args: { event: Record<string, unknown>; body: unknown }) => Promise<void>;

View File

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