From e059934ecc5c9c71250f28355b6cf0ea30f987b1 Mon Sep 17 00:00:00 2001 From: vignesh07 Date: Sun, 8 Mar 2026 14:20:49 -0700 Subject: [PATCH] test(plugins): avoid subprocess in legacy plugin-sdk import test --- src/plugins/loader.test.ts | 48 ++++++++++++++------------------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/plugins/loader.test.ts b/src/plugins/loader.test.ts index cff49aa8a19..d94e19b80f9 100644 --- a/src/plugins/loader.test.ts +++ b/src/plugins/loader.test.ts @@ -1,8 +1,6 @@ -import { execFileSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { pathToFileURL } from "node:url"; import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; import { withEnv } from "../test-utils/env.js"; async function importFreshPluginTestModules() { @@ -1354,37 +1352,25 @@ describe("loadOpenClawPlugins", () => { };`, }); - const loaderModuleUrl = pathToFileURL( - path.join(process.cwd(), "src", "plugins", "loader.ts"), - ).href; - const script = ` - import { loadOpenClawPlugins } from ${JSON.stringify(loaderModuleUrl)}; - const registry = loadOpenClawPlugins({ - cache: false, - workspaceDir: ${JSON.stringify(plugin.dir)}, - config: { - plugins: { - load: { paths: [${JSON.stringify(plugin.file)}] }, - allow: ["legacy-root-import"], - }, - }, - }); - const record = registry.plugins.find((entry) => entry.id === "legacy-root-import"); - if (!record || record.status !== "loaded") { - console.error(record?.error ?? "legacy-root-import missing"); - process.exit(1); - } - `; - - execFileSync(process.execPath, ["--import", "tsx", "--input-type=module", "-e", script], { - cwd: process.cwd(), - env: { - ...process.env, + const registry = withEnv( + { OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins", }, - encoding: "utf-8", - stdio: "pipe", - }); + () => + loadOpenClawPlugins({ + cache: false, + workspaceDir: plugin.dir, + config: { + plugins: { + load: { paths: [plugin.file] }, + allow: ["legacy-root-import"], + }, + }, + }), + ); + + const record = registry.plugins.find((entry) => entry.id === "legacy-root-import"); + expect(record?.status).toBe("loaded"); }); it("prefers dist plugin-sdk alias when loader runs from dist", () => {