mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:58:26 +00:00
refactor(test): share plugin hook registry helper
This commit is contained in:
@@ -6,37 +6,13 @@
|
||||
* and validating the integration pattern.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { PluginRegistry } from "./registry.js";
|
||||
import { createHookRunner } from "./hooks.js";
|
||||
|
||||
function createMockRegistry(
|
||||
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: [],
|
||||
httpHandlers: [],
|
||||
httpRoutes: [],
|
||||
channelRegistrations: [],
|
||||
gatewayHandlers: {},
|
||||
cliRegistrars: [],
|
||||
services: [],
|
||||
providers: [],
|
||||
commands: [],
|
||||
} as unknown as PluginRegistry;
|
||||
}
|
||||
import { createMockPluginRegistry } from "./hooks.test-helpers.js";
|
||||
|
||||
describe("gateway hook runner methods", () => {
|
||||
it("runGatewayStart invokes registered gateway_start hooks", async () => {
|
||||
const handler = vi.fn();
|
||||
const registry = createMockRegistry([{ hookName: "gateway_start", handler }]);
|
||||
const registry = createMockPluginRegistry([{ hookName: "gateway_start", handler }]);
|
||||
const runner = createHookRunner(registry);
|
||||
|
||||
await runner.runGatewayStart({ port: 18789 }, { port: 18789 });
|
||||
@@ -46,7 +22,7 @@ describe("gateway hook runner methods", () => {
|
||||
|
||||
it("runGatewayStop invokes registered gateway_stop hooks", async () => {
|
||||
const handler = vi.fn();
|
||||
const registry = createMockRegistry([{ hookName: "gateway_stop", handler }]);
|
||||
const registry = createMockPluginRegistry([{ hookName: "gateway_stop", handler }]);
|
||||
const runner = createHookRunner(registry);
|
||||
|
||||
await runner.runGatewayStop({ reason: "test shutdown" }, { port: 18789 });
|
||||
@@ -55,7 +31,7 @@ describe("gateway hook runner methods", () => {
|
||||
});
|
||||
|
||||
it("hasHooks returns true for registered gateway hooks", () => {
|
||||
const registry = createMockRegistry([{ hookName: "gateway_start", handler: vi.fn() }]);
|
||||
const registry = createMockPluginRegistry([{ hookName: "gateway_start", handler: vi.fn() }]);
|
||||
const runner = createHookRunner(registry);
|
||||
|
||||
expect(runner.hasHooks("gateway_start")).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user