mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(plugins): avoid subprocess in legacy plugin-sdk import test
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user