openclaw/src/agents/runtime-plugins.test.ts
2026-03-28 00:19:33 -04:00

67 lines
2.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => ({
resolveRuntimePluginRegistry: vi.fn(),
}));
vi.mock("../plugins/loader.js", () => ({
resolveRuntimePluginRegistry: hoisted.resolveRuntimePluginRegistry,
}));
describe("ensureRuntimePluginsLoaded", () => {
beforeEach(() => {
hoisted.resolveRuntimePluginRegistry.mockReset();
hoisted.resolveRuntimePluginRegistry.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.resolveRuntimePluginRegistry.mockReturnValue({});
ensureRuntimePluginsLoaded({
config: {} as never,
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(1);
});
it("resolves runtime plugins through the shared runtime helper", async () => {
const { ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js");
ensureRuntimePluginsLoaded({
config: {} as never,
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledWith({
config: {} as never,
workspaceDir: "/tmp/workspace",
runtimeOptions: {
allowGatewaySubagentBinding: true,
},
});
});
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.resolveRuntimePluginRegistry).toHaveBeenCalledWith({
config: {} as never,
workspaceDir: "/tmp/workspace",
runtimeOptions: {
allowGatewaySubagentBinding: true,
},
});
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(1);
});
});