mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-25 08:52:12 +00:00
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { createEmptyPluginRegistry } from "../plugins/registry.js";
|
|
|
|
const loadOpenClawPluginsMock = vi.hoisted(() => vi.fn());
|
|
const getActivePluginRegistryMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("../agents/agent-scope.js", () => ({
|
|
resolveAgentWorkspaceDir: () => "/tmp/workspace",
|
|
resolveDefaultAgentId: () => "default-agent",
|
|
}));
|
|
|
|
vi.mock("../config/config.js", () => ({
|
|
loadConfig: () => ({}),
|
|
}));
|
|
|
|
vi.mock("../logging.js", () => ({
|
|
createSubsystemLogger: () => ({
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
debug: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../plugins/loader.js", () => ({
|
|
loadOpenClawPlugins: loadOpenClawPluginsMock,
|
|
}));
|
|
|
|
vi.mock("../plugins/runtime.js", () => ({
|
|
getActivePluginRegistry: getActivePluginRegistryMock,
|
|
}));
|
|
|
|
describe("ensurePluginRegistryLoaded", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.resetModules();
|
|
});
|
|
|
|
it("skips plugin loading when a provider-only registry is already active", async () => {
|
|
const registry = createEmptyPluginRegistry();
|
|
registry.providers.push({
|
|
pluginId: "provider-demo",
|
|
source: "test",
|
|
provider: {
|
|
id: "provider-demo",
|
|
label: "Provider Demo",
|
|
auth: [],
|
|
},
|
|
});
|
|
getActivePluginRegistryMock.mockReturnValue(registry);
|
|
|
|
const { ensurePluginRegistryLoaded } = await import("./plugin-registry.js");
|
|
ensurePluginRegistryLoaded();
|
|
|
|
expect(loadOpenClawPluginsMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("loads plugins once when the active registry is empty", async () => {
|
|
getActivePluginRegistryMock.mockReturnValue(createEmptyPluginRegistry());
|
|
|
|
const { ensurePluginRegistryLoaded } = await import("./plugin-registry.js");
|
|
ensurePluginRegistryLoaded();
|
|
ensurePluginRegistryLoaded();
|
|
|
|
expect(loadOpenClawPluginsMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|