From 98b76d83ea5518631fc9ebcf1645d238114fd2cc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 01:03:03 +0100 Subject: [PATCH] perf(test): trim bundled registry and facade tests --- src/plugin-sdk/facade-runtime.test.ts | 68 ++++++++++----------------- src/plugin-sdk/facade-runtime.ts | 20 ++++++-- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/plugin-sdk/facade-runtime.test.ts b/src/plugin-sdk/facade-runtime.test.ts index da596ea8c4d..9b1a7080b1b 100644 --- a/src/plugin-sdk/facade-runtime.test.ts +++ b/src/plugin-sdk/facade-runtime.test.ts @@ -274,10 +274,7 @@ describe("plugin-sdk facade runtime", () => { }); it("resolves a globally-installed plugin whose rootDir basename matches the dirName", () => { - const emptyBundled = createTempDirSync("openclaw-facade-empty-bundled-"); - - const stateDir = createTempDirSync("openclaw-facade-state-"); - const lineDir = path.join(stateDir, "extensions", "line"); + const lineDir = createTempDirSync("openclaw-facade-global-line-"); fs.mkdirSync(lineDir, { recursive: true }); fs.writeFileSync( path.join(lineDir, "runtime-api.js"), @@ -306,34 +303,26 @@ describe("plugin-sdk facade runtime", () => { "utf8", ); - process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = emptyBundled; - process.env.OPENCLAW_STATE_DIR = stateDir; - - clearPluginDiscoveryCache(); - clearPluginManifestRegistryCache(); - resetFacadeRuntimeStateForTest(); - - setRuntimeConfigSnapshot({ - channels: { - line: { - enabled: true, - }, - }, - }); - expect( - canLoadActivatedBundledPluginPublicSurface({ + __testing.resolveRegistryPluginModuleLocationFromRegistry({ + registry: [ + { + id: "line", + rootDir: lineDir, + channels: ["line"], + }, + ], dirName: "line", artifactBasename: "runtime-api.js", }), - ).toBe(true); + ).toEqual({ + modulePath: path.join(lineDir, "runtime-api.js"), + boundaryRoot: lineDir, + }); }); it("resolves a globally-installed plugin with an encoded scoped rootDir basename", () => { - const emptyBundled = createTempDirSync("openclaw-facade-empty-bundled-"); - - const stateDir = createTempDirSync("openclaw-facade-state-"); - const encodedDir = path.join(stateDir, "extensions", "@openclaw+line"); + const encodedDir = createTempDirSync("openclaw-facade-encoded-line-"); fs.mkdirSync(encodedDir, { recursive: true }); fs.writeFileSync( path.join(encodedDir, "runtime-api.js"), @@ -362,27 +351,22 @@ describe("plugin-sdk facade runtime", () => { "utf8", ); - process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = emptyBundled; - process.env.OPENCLAW_STATE_DIR = stateDir; - - clearPluginDiscoveryCache(); - clearPluginManifestRegistryCache(); - resetFacadeRuntimeStateForTest(); - - setRuntimeConfigSnapshot({ - channels: { - line: { - enabled: true, - }, - }, - }); - expect( - canLoadActivatedBundledPluginPublicSurface({ + __testing.resolveRegistryPluginModuleLocationFromRegistry({ + registry: [ + { + id: "line", + rootDir: encodedDir, + channels: ["line"], + }, + ], dirName: "line", artifactBasename: "runtime-api.js", }), - ).toBe(true); + ).toEqual({ + modulePath: path.join(encodedDir, "runtime-api.js"), + boundaryRoot: encodedDir, + }); }); it("keeps shared runtime-core facades available without plugin activation", () => { diff --git a/src/plugin-sdk/facade-runtime.ts b/src/plugin-sdk/facade-runtime.ts index 01e72808b98..0e8e7768904 100644 --- a/src/plugin-sdk/facade-runtime.ts +++ b/src/plugin-sdk/facade-runtime.ts @@ -115,12 +115,13 @@ function resolveSourceFirstPublicSurfacePath(params: { return null; } -function resolveRegistryPluginModuleLocation(params: { +function resolveRegistryPluginModuleLocationFromRegistry(params: { + registry: readonly Pick[]; dirName: string; artifactBasename: string; }): { modulePath: string; boundaryRoot: string } | null { - const registry = getFacadeManifestRegistry(); - const tiers: Array<(plugin: (typeof registry)[number]) => boolean> = [ + type RegistryRecord = (typeof params.registry)[number]; + const tiers: Array<(plugin: RegistryRecord) => boolean> = [ (plugin) => plugin.id === params.dirName, (plugin) => path.basename(plugin.rootDir) === params.dirName, (plugin) => plugin.channels.includes(params.dirName), @@ -128,7 +129,7 @@ function resolveRegistryPluginModuleLocation(params: { const artifactBasename = params.artifactBasename.replace(/^\.\//u, ""); const sourceBaseName = artifactBasename.replace(/\.js$/u, ""); for (const matchFn of tiers) { - for (const record of registry.filter(matchFn)) { + for (const record of params.registry.filter(matchFn)) { const rootDir = path.resolve(record.rootDir); const builtCandidate = path.join(rootDir, artifactBasename); if (fs.existsSync(builtCandidate)) { @@ -145,6 +146,16 @@ function resolveRegistryPluginModuleLocation(params: { return null; } +function resolveRegistryPluginModuleLocation(params: { + dirName: string; + artifactBasename: string; +}): { modulePath: string; boundaryRoot: string } | null { + return resolveRegistryPluginModuleLocationFromRegistry({ + registry: getFacadeManifestRegistry(), + ...params, + }); +} + function resolveFacadeModuleLocationUncached(params: { dirName: string; artifactBasename: string; @@ -729,6 +740,7 @@ export function resetFacadeRuntimeStateForTest(): void { export const __testing = { evaluateBundledPluginPublicSurfaceAccess, loadFacadeModuleAtLocationSync, + resolveRegistryPluginModuleLocationFromRegistry, throwForBundledPluginPublicSurfaceAccess, resolveActivatedBundledPluginPublicSurfaceAccessOrThrow, resolveFacadeModuleLocation,