mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:20:43 +00:00
test(plugins): materialize runtime deps fixtures
This commit is contained in:
@@ -244,14 +244,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const pluginInstallRoot = resolveBundledRuntimeDependencyInstallRoot(pluginRoot, { env });
|
||||
fs.mkdirSync(path.join(pluginInstallRoot, "node_modules", `${pluginId}-runtime`), {
|
||||
recursive: true,
|
||||
});
|
||||
fs.writeFileSync(
|
||||
path.join(pluginInstallRoot, "node_modules", `${pluginId}-runtime`, "package.json"),
|
||||
JSON.stringify({ name: `${pluginId}-runtime`, version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(pluginInstallRoot, `${pluginId}-runtime`, "1.0.0");
|
||||
}
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["alpha-runtime@1.0.0", "beta-runtime@1.0.0"]);
|
||||
|
||||
@@ -323,12 +316,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const installRoot = resolveBundledRuntimeDependencyInstallRoot(pluginRoot, { env });
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "alpha-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "alpha-runtime", "package.json"),
|
||||
JSON.stringify({ name: "alpha-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "alpha-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["alpha-runtime@1.0.0"]);
|
||||
|
||||
const realReaddirSync = fs.readdirSync.bind(fs);
|
||||
@@ -389,12 +377,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "qqbot-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "qqbot-runtime", "package.json"),
|
||||
JSON.stringify({ name: "qqbot-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "qqbot-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["qqbot-runtime@1.0.0"]);
|
||||
|
||||
const prepared = prepareBundledPluginRuntimeRoot({
|
||||
@@ -473,12 +456,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const installRoot = resolveBundledRuntimeDependencyInstallRoot(runtimePluginRoot, { env });
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "qqbot-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "qqbot-runtime", "package.json"),
|
||||
JSON.stringify({ name: "qqbot-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "qqbot-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["qqbot-runtime@1.0.0"]);
|
||||
|
||||
const prepared = prepareBundledPluginRuntimeRoot({
|
||||
@@ -539,12 +517,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const installRoot = resolveBundledRuntimeDependencyInstallRoot(runtimePluginRoot, { env });
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "qqbot-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "qqbot-runtime", "package.json"),
|
||||
JSON.stringify({ name: "qqbot-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "qqbot-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["qqbot-runtime@1.0.0"]);
|
||||
|
||||
const lockPath = path.join(installRoot, ".openclaw-runtime-mirror.lock");
|
||||
@@ -602,12 +575,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const installRoot = resolveBundledRuntimeDependencyInstallRoot(pluginRoot, { env });
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "whatsapp-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "whatsapp-runtime", "package.json"),
|
||||
JSON.stringify({ name: "whatsapp-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "whatsapp-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["whatsapp-runtime@1.0.0"]);
|
||||
|
||||
const prepared = prepareBundledPluginRuntimeRoot({
|
||||
@@ -759,12 +727,7 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
||||
"utf8",
|
||||
);
|
||||
const installRoot = resolveBundledRuntimeDependencyInstallRoot(pluginRoot, { env });
|
||||
fs.mkdirSync(path.join(installRoot, "node_modules", "whatsapp-runtime"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(installRoot, "node_modules", "whatsapp-runtime", "package.json"),
|
||||
JSON.stringify({ name: "whatsapp-runtime", version: "1.0.0", type: "module" }),
|
||||
"utf8",
|
||||
);
|
||||
writeInstalledRuntimeDepPackage(installRoot, "whatsapp-runtime", "1.0.0");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["whatsapp-runtime@1.0.0"]);
|
||||
|
||||
const prepared = prepareBundledPluginRuntimeRoot({
|
||||
|
||||
@@ -5,6 +5,7 @@ import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveBundledRuntimeDependencyInstallRoot } from "./bundled-runtime-deps-roots.js";
|
||||
import { clearBundledRuntimeDependencyNodePaths } from "./bundled-runtime-deps.js";
|
||||
import { writeGeneratedRuntimeDepsManifest } from "./test-helpers/bundled-runtime-deps-fixtures.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
@@ -79,6 +80,7 @@ function createPackagedPublicArtifactWithStagedRuntimeDep(): {
|
||||
"utf8",
|
||||
);
|
||||
fs.writeFileSync(path.join(depRoot, "index.js"), 'export const marker = "staged";\n', "utf8");
|
||||
writeGeneratedRuntimeDepsManifest(installRoot, ["public-artifact-runtime-dep@1.0.0"]);
|
||||
|
||||
return {
|
||||
bundledPluginsDir: path.join(packageRoot, "dist", "extensions"),
|
||||
@@ -94,6 +96,7 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.resetModules();
|
||||
vi.doUnmock("jiti");
|
||||
vi.doUnmock("./native-module-require.js");
|
||||
vi.doUnmock("node:module");
|
||||
clearBundledRuntimeDependencyNodePaths();
|
||||
if (originalBundledPluginsDir === undefined) {
|
||||
@@ -114,6 +117,11 @@ describe("bundled plugin public surface loader", () => {
|
||||
vi.doMock("jiti", () => ({
|
||||
createJiti,
|
||||
}));
|
||||
vi.doMock("./native-module-require.js", () => ({
|
||||
isJavaScriptModulePath: (modulePath: string) =>
|
||||
modulePath.endsWith(".js") || modulePath.endsWith(".mjs") || modulePath.endsWith(".cjs"),
|
||||
tryNativeRequireJavaScriptModule: () => ({ ok: false }),
|
||||
}));
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
vi.resetModules();
|
||||
|
||||
@@ -193,6 +201,11 @@ describe("bundled plugin public surface loader", () => {
|
||||
vi.doMock("jiti", () => ({
|
||||
createJiti,
|
||||
}));
|
||||
vi.doMock("./native-module-require.js", () => ({
|
||||
isJavaScriptModulePath: (modulePath: string) =>
|
||||
modulePath.endsWith(".js") || modulePath.endsWith(".mjs") || modulePath.endsWith(".cjs"),
|
||||
tryNativeRequireJavaScriptModule: () => ({ ok: false }),
|
||||
}));
|
||||
vi.resetModules();
|
||||
|
||||
const publicSurfaceLoader = await importFreshModule<
|
||||
|
||||
Reference in New Issue
Block a user