Files
openclaw/src/plugins/hooks.test-helpers.ts
Peter Steinberger 98e3f729bc refactor: remove dead plugin loader exports (#105937)
* refactor(plugins): trim activation and contract exports

* test(plugins): restore fixture cleanup

* refactor(plugins): trim install and loader exports

* test(plugins): fully reset loader caches

* refactor(plugins): trim metadata and catalog exports

* test(plugins): preserve catalog trust coverage

* refactor(plugins): trim provider and plugin exports

* refactor(plugins): trim runtime and tool exports

* test(plugins): update dead-export consumers

* test(plugins): remove empty dead-export suites

* refactor(plugins): align exports with split registry

* refactor(plugins): trim drifted loader exports

* style(plugins): format test fixtures

* refactor(scripts): use supported plugin APIs

* refactor(plugins): finish dead export cleanup

* chore(deadcode): refresh export baseline

* test(cli): mock production memory state

* chore(deadcode): sync latest export baseline

* fix(tests): keep plugin fixtures inside core

* chore(deadcode): refresh rebased export baseline

* chore(deadcode): sync current ratchets

* fix(plugins): retain reserved slot invariant

* fix(plugins): preserve dead-export invariants

* test(plugins): use neutral catalog query fixture

* test(plugins): satisfy catalog lint

* test(plugins): preserve integrity drift coverage

* fix(ci): register skill experience live proof
2026-07-13 01:29:33 -07:00

59 lines
1.9 KiB
TypeScript

// Provides shared helpers for plugin hook tests.
import { uniqueStrings } from "@openclaw/normalization-core/string-normalization";
import { createEmptyPluginRegistry } from "./registry-empty.js";
import type { PluginRegistry } from "./registry.js";
import { createPluginRecord } from "./status.test-helpers.js";
import type { PluginHookRegistration } from "./types.js";
export function createMockPluginRegistry(
hooks: Array<{
hookName: string;
handler: (...args: unknown[]) => unknown;
pluginId?: string;
priority?: number;
timeoutMs?: number;
}>,
): PluginRegistry {
const pluginIds =
hooks.length > 0
? uniqueStrings(hooks.map((hook) => hook.pluginId ?? "test-plugin"))
: ["test-plugin"];
return {
...createEmptyPluginRegistry(),
plugins: pluginIds.map((pluginId) =>
createPluginRecord({
id: pluginId,
name: "Test Plugin",
source: "test",
hookCount: hooks.filter((hook) => (hook.pluginId ?? "test-plugin") === pluginId).length,
}),
),
hooks: hooks as never[],
typedHooks: hooks.map((h) => ({
pluginId: h.pluginId ?? "test-plugin",
hookName: h.hookName,
handler: h.handler,
priority: h.priority ?? 0,
...(h.timeoutMs !== undefined ? { timeoutMs: h.timeoutMs } : {}),
source: "test",
})) as PluginRegistry["typedHooks"],
};
}
export function addTestHook(params: {
registry: PluginRegistry;
pluginId: string;
hookName: PluginHookRegistration["hookName"];
handler: PluginHookRegistration["handler"];
priority?: number;
timeoutMs?: number;
}) {
params.registry.typedHooks.push({
pluginId: params.pluginId,
hookName: params.hookName,
handler: params.handler,
priority: params.priority ?? 0,
...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs } : {}),
source: "test",
} as PluginHookRegistration);
}