test: isolate legacy plugin-sdk root import check

This commit is contained in:
Peter Steinberger
2026-03-08 16:45:05 +00:00
parent a007bed375
commit c70151e873

View File

@@ -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", () => {