Plugins: add runtime registry compatibility helper

This commit is contained in:
Gustavo Madeira Santana
2026-03-28 00:06:52 -04:00
parent 4beb231fd8
commit fd0aac297c
4 changed files with 176 additions and 48 deletions

View File

@@ -2,28 +2,25 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => ({
loadOpenClawPlugins: vi.fn(),
getActivePluginRegistryKey: vi.fn<() => string | null>(),
getCompatibleActivePluginRegistry: vi.fn(),
}));
vi.mock("../plugins/loader.js", () => ({
loadOpenClawPlugins: hoisted.loadOpenClawPlugins,
}));
vi.mock("../plugins/runtime.js", () => ({
getActivePluginRegistryKey: hoisted.getActivePluginRegistryKey,
getCompatibleActivePluginRegistry: hoisted.getCompatibleActivePluginRegistry,
}));
describe("ensureRuntimePluginsLoaded", () => {
beforeEach(() => {
hoisted.loadOpenClawPlugins.mockReset();
hoisted.getActivePluginRegistryKey.mockReset();
hoisted.getActivePluginRegistryKey.mockReturnValue(null);
hoisted.getCompatibleActivePluginRegistry.mockReset();
hoisted.getCompatibleActivePluginRegistry.mockReturnValue(undefined);
vi.resetModules();
});
it("does not reactivate plugins when a process already has an active registry", async () => {
const { ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js");
hoisted.getActivePluginRegistryKey.mockReturnValue("gateway-registry");
hoisted.getCompatibleActivePluginRegistry.mockReturnValue({});
ensureRuntimePluginsLoaded({
config: {} as never,
@@ -34,7 +31,7 @@ describe("ensureRuntimePluginsLoaded", () => {
expect(hoisted.loadOpenClawPlugins).not.toHaveBeenCalled();
});
it("loads runtime plugins when no active registry exists", async () => {
it("loads runtime plugins when no compatible active registry exists", async () => {
const { ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js");
ensureRuntimePluginsLoaded({
@@ -51,4 +48,23 @@ describe("ensureRuntimePluginsLoaded", () => {
},
});
});
it("reloads when the current active registry is incompatible with the request", async () => {
const { ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js");
ensureRuntimePluginsLoaded({
config: {} as never,
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(hoisted.getCompatibleActivePluginRegistry).toHaveBeenCalledWith({
config: {} as never,
workspaceDir: "/tmp/workspace",
runtimeOptions: {
allowGatewaySubagentBinding: true,
},
});
expect(hoisted.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
});
});