Files
openclaw/src/plugins/active-runtime-registry.test.ts
DmitryPogodaev 8283c5d6cc perf(plugins): reuse startup runtime registry
Reuse the startup runtime plugin registry across provider/tool helper paths while preserving standalone CLI/MCP fallback loading.

Includes follow-up fixes for migration/provider/tool registry bootstrap and regression coverage for compatible registry reuse.

Co-authored-by: DmitryPogodaev <pogodaev.dm@gmail.com>
2026-05-02 13:44:49 +01:00

89 lines
2.5 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { getLoadedRuntimePluginRegistry } from "./active-runtime-registry.js";
import { __testing, clearPluginLoaderCache } from "./loader.js";
import { createEmptyPluginRegistry } from "./registry-empty.js";
import type { PluginRegistry } from "./registry-types.js";
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "./runtime.js";
afterEach(() => {
clearPluginLoaderCache();
resetPluginRuntimeStateForTest();
});
function createRegistryWithPlugin(pluginId: string): PluginRegistry {
const registry = createEmptyPluginRegistry();
registry.plugins.push({
id: pluginId,
status: "loaded",
} as never);
return registry;
}
describe("getLoadedRuntimePluginRegistry", () => {
it("treats an explicit empty plugin scope as empty", () => {
setActivePluginRegistry(createRegistryWithPlugin("stale"), "stale", "default", "/tmp/ws");
expect(
getLoadedRuntimePluginRegistry({
workspaceDir: "/tmp/ws",
requiredPluginIds: [],
}),
).toBeUndefined();
const emptyRegistry = createEmptyPluginRegistry();
setActivePluginRegistry(emptyRegistry, "empty", "default", "/tmp/ws");
expect(
getLoadedRuntimePluginRegistry({
workspaceDir: "/tmp/ws",
requiredPluginIds: [],
}),
).toBe(emptyRegistry);
});
it("does not reuse workspace-agnostic registries for workspace-specific requests", () => {
setActivePluginRegistry(createRegistryWithPlugin("demo"), "demo");
expect(
getLoadedRuntimePluginRegistry({
workspaceDir: "/tmp/ws",
requiredPluginIds: ["demo"],
}),
).toBeUndefined();
});
it("validates full loader cache compatibility when load options are provided", () => {
const registry = createRegistryWithPlugin("demo");
const loadOptions = {
config: {
plugins: {
allow: ["demo"],
},
},
onlyPluginIds: ["demo"],
workspaceDir: "/tmp/ws",
};
const { cacheKey } = __testing.resolvePluginLoadCacheContext(loadOptions);
setActivePluginRegistry(registry, cacheKey, "default", "/tmp/ws");
expect(
getLoadedRuntimePluginRegistry({
loadOptions,
}),
).toBe(registry);
expect(
getLoadedRuntimePluginRegistry({
loadOptions: {
...loadOptions,
config: {
plugins: {
allow: ["other"],
},
},
},
}),
).toBeUndefined();
});
});