refactor(test): share plugin hook registry helper

This commit is contained in:
Peter Steinberger
2026-02-15 14:44:15 +00:00
parent 6ec76af3a6
commit e2c68cb169
4 changed files with 38 additions and 85 deletions

View File

@@ -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);