From eb2cd09b72c21f3495f2da311a7369d970082d6f Mon Sep 17 00:00:00 2001 From: Shakker Date: Thu, 2 Apr 2026 09:55:27 +0100 Subject: [PATCH] test: trim facade runtime circular harness cost --- src/plugin-sdk/facade-runtime.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugin-sdk/facade-runtime.test.ts b/src/plugin-sdk/facade-runtime.test.ts index 052b9f6927b..b957c006dfc 100644 --- a/src/plugin-sdk/facade-runtime.test.ts +++ b/src/plugin-sdk/facade-runtime.test.ts @@ -14,6 +14,7 @@ import { const tempDirs: string[] = []; const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR; +const FACADE_RUNTIME_GLOBAL = "__openclawTestLoadBundledPluginPublicSurfaceModuleSync"; function createBundledPluginDir(prefix: string, marker: string): string { const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); @@ -46,9 +47,10 @@ function createCircularPluginDir(prefix: string): string { fs.writeFileSync( path.join(rootDir, "facade.mjs"), [ - `import { loadBundledPluginPublicSurfaceModuleSync } from ${JSON.stringify( - new URL("./facade-runtime.js", import.meta.url).href, - )};`, + `const loadBundledPluginPublicSurfaceModuleSync = globalThis.${FACADE_RUNTIME_GLOBAL};`, + `if (typeof loadBundledPluginPublicSurfaceModuleSync !== "function") {`, + ' throw new Error("missing facade runtime test loader");', + "}", `export const marker = loadBundledPluginPublicSurfaceModuleSync({ dirName: "demo", artifactBasename: "api.js" }).marker;`, "", ].join("\n"), @@ -73,6 +75,7 @@ afterEach(() => { vi.restoreAllMocks(); clearRuntimeConfigSnapshot(); resetFacadeRuntimeStateForTest(); + delete (globalThis as typeof globalThis & Record)[FACADE_RUNTIME_GLOBAL]; if (originalBundledPluginsDir === undefined) { delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR; } else { @@ -123,6 +126,8 @@ describe("plugin-sdk facade runtime", () => { it("breaks circular facade re-entry during module evaluation", () => { const dir = createCircularPluginDir("openclaw-facade-circular-"); process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = dir; + (globalThis as typeof globalThis & Record)[FACADE_RUNTIME_GLOBAL] = + loadBundledPluginPublicSurfaceModuleSync; const loaded = loadBundledPluginPublicSurfaceModuleSync<{ marker: string }>({ dirName: "demo",