fix(plugins): preserve live hook registry during gateway runs

This commit is contained in:
Vincent Koc
2026-03-23 01:00:08 -07:00
parent 9105b3723d
commit d22279d2e8
9 changed files with 198 additions and 63 deletions

View File

@@ -0,0 +1,52 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => ({
loadOpenClawPlugins: vi.fn(),
getActivePluginRegistryKey: vi.fn<() => string | null>(),
}));
vi.mock("../plugins/loader.js", () => ({
loadOpenClawPlugins: hoisted.loadOpenClawPlugins,
}));
vi.mock("../plugins/runtime.js", () => ({
getActivePluginRegistryKey: hoisted.getActivePluginRegistryKey,
}));
const { ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js");
describe("ensureRuntimePluginsLoaded", () => {
beforeEach(() => {
hoisted.loadOpenClawPlugins.mockReset();
hoisted.getActivePluginRegistryKey.mockReset();
hoisted.getActivePluginRegistryKey.mockReturnValue(null);
});
it("does not reactivate plugins when a process already has an active registry", () => {
hoisted.getActivePluginRegistryKey.mockReturnValue("gateway-registry");
ensureRuntimePluginsLoaded({
config: {} as never,
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(hoisted.loadOpenClawPlugins).not.toHaveBeenCalled();
});
it("loads runtime plugins when no active registry exists", () => {
ensureRuntimePluginsLoaded({
config: {} as never,
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(hoisted.loadOpenClawPlugins).toHaveBeenCalledWith({
config: {} as never,
workspaceDir: "/tmp/workspace",
runtimeOptions: {
allowGatewaySubagentBinding: true,
},
});
});
});