test: trim facade runtime circular harness cost

This commit is contained in:
Shakker
2026-04-02 09:55:27 +01:00
committed by Peter Steinberger
parent 3cce39cae2
commit eb2cd09b72

View File

@@ -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<string, unknown>)[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<string, unknown>)[FACADE_RUNTIME_GLOBAL] =
loadBundledPluginPublicSurfaceModuleSync;
const loaded = loadBundledPluginPublicSurfaceModuleSync<{ marker: string }>({
dirName: "demo",