File size: 1,336 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import type { PluginRegistry } from "./registry.js";
import type { PluginHookAgentContext, PluginHookRegistration } from "./types.js";
export function createMockPluginRegistry(
hooks: Array<{ hookName: string; handler: (...args: unknown[]) => unknown }>,
): PluginRegistry {
return {
hooks: hooks as never[],
typedHooks: hooks.map((h) => ({
pluginId: "test-plugin",
hookName: h.hookName,
handler: h.handler,
priority: 0,
source: "test",
})),
tools: [],
httpRoutes: [],
channelRegistrations: [],
gatewayHandlers: {},
cliRegistrars: [],
services: [],
providers: [],
commands: [],
} as unknown as PluginRegistry;
}
export const TEST_PLUGIN_AGENT_CTX: PluginHookAgentContext = {
agentId: "test-agent",
sessionKey: "test-session",
sessionId: "test-session-id",
workspaceDir: "/tmp/openclaw-test",
messageProvider: "test",
};
export function addTestHook(params: {
registry: PluginRegistry;
pluginId: string;
hookName: PluginHookRegistration["hookName"];
handler: PluginHookRegistration["handler"];
priority?: number;
}) {
params.registry.typedHooks.push({
pluginId: params.pluginId,
hookName: params.hookName,
handler: params.handler,
priority: params.priority ?? 0,
source: "test",
} as PluginHookRegistration);
}
|