mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
test: share plugin sdk facade fixtures
This commit is contained in:
@@ -8,7 +8,11 @@ import {
|
||||
setFacadeLoaderJitiFactoryForTest,
|
||||
} from "./facade-loader.js";
|
||||
import { listImportedBundledPluginFacadeIds as listImportedFacadeRuntimeIds } from "./facade-runtime.js";
|
||||
import { createPluginSdkTestHarness } from "./test-helpers.js";
|
||||
import {
|
||||
createBundledPluginPublicSurfaceFixture,
|
||||
createPluginSdkTestHarness,
|
||||
createThrowingBundledPluginPublicSurfaceFixture,
|
||||
} from "./test-helpers.js";
|
||||
|
||||
const { createTempDirSync } = createPluginSdkTestHarness();
|
||||
const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
@@ -16,25 +20,11 @@ const FACADE_LOADER_GLOBAL = "__openclawTestLoadBundledPluginPublicSurfaceModule
|
||||
type FacadeLoaderJitiFactory = NonNullable<Parameters<typeof setFacadeLoaderJitiFactoryForTest>[0]>;
|
||||
|
||||
function createBundledPluginDir(prefix: string, marker: string): string {
|
||||
const rootDir = createTempDirSync(prefix);
|
||||
fs.mkdirSync(path.join(rootDir, "demo"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(rootDir, "demo", "api.js"),
|
||||
`export const marker = ${JSON.stringify(marker)};\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
return createBundledPluginPublicSurfaceFixture({ createTempDirSync, marker, prefix });
|
||||
}
|
||||
|
||||
function createThrowingPluginDir(prefix: string): string {
|
||||
const rootDir = createTempDirSync(prefix);
|
||||
fs.mkdirSync(path.join(rootDir, "bad"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(rootDir, "bad", "api.js"),
|
||||
`throw new Error("plugin load failure");\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
return createThrowingBundledPluginPublicSurfaceFixture({ createTempDirSync, prefix });
|
||||
}
|
||||
|
||||
function createCircularPluginDir(prefix: string): string {
|
||||
|
||||
@@ -12,32 +12,22 @@ import {
|
||||
loadBundledPluginPublicSurfaceModuleSync,
|
||||
resetFacadeRuntimeStateForTest,
|
||||
} from "./facade-runtime.js";
|
||||
import { createPluginSdkTestHarness } from "./test-helpers.js";
|
||||
import {
|
||||
createBundledPluginPublicSurfaceFixture,
|
||||
createPluginSdkTestHarness,
|
||||
createThrowingBundledPluginPublicSurfaceFixture,
|
||||
} from "./test-helpers.js";
|
||||
|
||||
const { createTempDirSync } = createPluginSdkTestHarness();
|
||||
const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
|
||||
function createBundledPluginDir(prefix: string, marker: string): string {
|
||||
const rootDir = createTempDirSync(prefix);
|
||||
fs.mkdirSync(path.join(rootDir, "demo"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(rootDir, "demo", "api.js"),
|
||||
`export const marker = ${JSON.stringify(marker)};\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
return createBundledPluginPublicSurfaceFixture({ createTempDirSync, marker, prefix });
|
||||
}
|
||||
|
||||
function createThrowingPluginDir(prefix: string): string {
|
||||
const rootDir = createTempDirSync(prefix);
|
||||
fs.mkdirSync(path.join(rootDir, "bad"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(rootDir, "bad", "api.js"),
|
||||
`throw new Error("plugin load failure");\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
return createThrowingBundledPluginPublicSurfaceFixture({ createTempDirSync, prefix });
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mkdirSync, type RmOptions } from "node:fs";
|
||||
import { mkdirSync, writeFileSync, type RmOptions } from "node:fs";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -44,3 +44,32 @@ export function createPluginSdkTestHarness(options?: { cleanup?: RmOptions }) {
|
||||
createTempDirSync,
|
||||
};
|
||||
}
|
||||
|
||||
export function createBundledPluginPublicSurfaceFixture(params: {
|
||||
createTempDirSync: (prefix: string) => string;
|
||||
marker: string;
|
||||
prefix: string;
|
||||
}) {
|
||||
const rootDir = params.createTempDirSync(params.prefix);
|
||||
mkdirSync(path.join(rootDir, "demo"), { recursive: true });
|
||||
writeFileSync(
|
||||
path.join(rootDir, "demo", "api.js"),
|
||||
`export const marker = ${JSON.stringify(params.marker)};\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
export function createThrowingBundledPluginPublicSurfaceFixture(params: {
|
||||
createTempDirSync: (prefix: string) => string;
|
||||
prefix: string;
|
||||
}) {
|
||||
const rootDir = params.createTempDirSync(params.prefix);
|
||||
mkdirSync(path.join(rootDir, "bad"), { recursive: true });
|
||||
writeFileSync(
|
||||
path.join(rootDir, "bad", "api.js"),
|
||||
`throw new Error("plugin load failure");\n`,
|
||||
"utf8",
|
||||
);
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user