From c70151e873aaa4b6549968b80e092bd1872be0af Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 8 Mar 2026 16:45:05 +0000 Subject: [PATCH] test: isolate legacy plugin-sdk root import check --- src/plugins/loader.test.ts | 45 ++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/plugins/loader.test.ts b/src/plugins/loader.test.ts index 0af3cc281f0..58f44bce962 100644 --- a/src/plugins/loader.test.ts +++ b/src/plugins/loader.test.ts @@ -1,10 +1,15 @@ +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() { vi.resetModules(); + vi.unmock("node:fs"); + vi.unmock("node:fs/promises"); + vi.unmock("node:module"); vi.unmock("./hook-runner-global.js"); vi.unmock("./hooks.js"); vi.unmock("./loader.js"); @@ -1337,7 +1342,7 @@ describe("loadOpenClawPlugins", () => { expect(record?.status).toBe("loaded"); }); - it("supports legacy plugins importing monolithic plugin-sdk root", () => { + it("supports legacy plugins importing monolithic plugin-sdk root", async () => { useNoBundledPlugins(); const plugin = writePlugin({ id: "legacy-root-import", @@ -1349,15 +1354,37 @@ describe("loadOpenClawPlugins", () => { };`, }); - const registry = loadRegistryFromSinglePlugin({ - plugin, - pluginConfig: { - allow: ["legacy-root-import"], - }, - }); + 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); + } + `; - const record = registry.plugins.find((entry) => entry.id === "legacy-root-import"); - expect({ status: record?.status, error: record?.error }).toMatchObject({ status: "loaded" }); + execFileSync(process.execPath, ["--import", "tsx", "--input-type=module", "-e", script], { + cwd: process.cwd(), + env: { + ...process.env, + OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins", + }, + encoding: "utf-8", + stdio: "pipe", + }); }); it("prefers dist plugin-sdk alias when loader runs from dist", () => {