test(perf): standardize loader fixtures to cjs

This commit is contained in:
Peter Steinberger
2026-03-02 13:43:48 +00:00
parent 097ad88f9d
commit 60b8d645de

View File

@@ -51,7 +51,7 @@ function writePlugin(params: {
filename?: string;
}): TempPlugin {
const dir = params.dir ?? makeTempDir();
const filename = params.filename ?? `${params.id}.js`;
const filename = params.filename ?? `${params.id}.cjs`;
const file = path.join(dir, filename);
fs.writeFileSync(file, params.body, "utf-8");
fs.writeFileSync(
@@ -193,8 +193,8 @@ function createWarningLogger(warnings: string[]) {
function createEscapingEntryFixture(params: { id: string; sourceBody: string }) {
const pluginDir = makeTempDir();
const outsideDir = makeTempDir();
const outsideEntry = path.join(outsideDir, "outside.js");
const linkedEntry = path.join(pluginDir, "entry.js");
const outsideEntry = path.join(outsideDir, "outside.cjs");
const linkedEntry = path.join(pluginDir, "entry.cjs");
fs.writeFileSync(outsideEntry, params.sourceBody, "utf-8");
fs.writeFileSync(
path.join(pluginDir, "openclaw.plugin.json"),
@@ -246,9 +246,9 @@ describe("loadOpenClawPlugins", () => {
const bundledDir = makeTempDir();
writePlugin({
id: "bundled",
body: `export default { id: "bundled", register() {} };`,
body: `module.exports = { id: "bundled", register() {} };`,
dir: bundledDir,
filename: "bundled.js",
filename: "bundled.cjs",
});
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
@@ -387,7 +387,8 @@ describe("loadOpenClawPlugins", () => {
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
const plugin = writePlugin({
id: "cache-hook-runner",
body: `export default { id: "cache-hook-runner", register() {} };`,
filename: "cache-hook-runner.cjs",
body: `module.exports = { id: "cache-hook-runner", register() {} };`,
});
const options = {
@@ -417,7 +418,8 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "alias-safe",
body: `export default { id: "alias-safe", register() {} };`,
filename: "alias-safe.cjs",
body: `module.exports = { id: "alias-safe", register() {} };`,
});
const realRoot = fs.realpathSync(plugin.dir);
if (realRoot === plugin.dir) {
@@ -439,7 +441,7 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "blocked",
body: `export default { id: "blocked", register() {} };`,
body: `module.exports = { id: "blocked", register() {} };`,
});
const registry = loadRegistryFromSinglePlugin({
@@ -458,7 +460,8 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "configurable",
body: `export default { id: "configurable", register() {} };`,
filename: "configurable.cjs",
body: `module.exports = { id: "configurable", register() {} };`,
});
const registry = loadRegistryFromSinglePlugin({
@@ -481,7 +484,8 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "channel-demo",
body: `export default { id: "channel-demo", register(api) {
filename: "channel-demo.cjs",
body: `module.exports = { id: "channel-demo", register(api) {
api.registerChannel({
plugin: {
id: "demo",
@@ -518,7 +522,8 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "http-demo",
body: `export default { id: "http-demo", register(api) {
filename: "http-demo.cjs",
body: `module.exports = { id: "http-demo", register(api) {
api.registerHttpHandler(async () => false);
} };`,
});
@@ -540,7 +545,8 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "http-route-demo",
body: `export default { id: "http-route-demo", register(api) {
filename: "http-route-demo.cjs",
body: `module.exports = { id: "http-route-demo", register(api) {
api.registerHttpRoute({ path: "/demo", handler: async (_req, res) => { res.statusCode = 200; res.end("ok"); } });
} };`,
});
@@ -563,7 +569,7 @@ describe("loadOpenClawPlugins", () => {
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
const plugin = writePlugin({
id: "config-disable",
body: `export default { id: "config-disable", register() {} };`,
body: `module.exports = { id: "config-disable", register() {} };`,
});
const registry = loadOpenClawPlugins({
@@ -586,11 +592,11 @@ describe("loadOpenClawPlugins", () => {
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
const memoryA = writePlugin({
id: "memory-a",
body: `export default { id: "memory-a", kind: "memory", register() {} };`,
body: `module.exports = { id: "memory-a", kind: "memory", register() {} };`,
});
const memoryB = writePlugin({
id: "memory-b",
body: `export default { id: "memory-b", kind: "memory", register() {} };`,
body: `module.exports = { id: "memory-b", kind: "memory", register() {} };`,
});
const registry = loadOpenClawPlugins({
@@ -613,7 +619,7 @@ describe("loadOpenClawPlugins", () => {
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
const memory = writePlugin({
id: "memory-off",
body: `export default { id: "memory-off", kind: "memory", register() {} };`,
body: `module.exports = { id: "memory-off", kind: "memory", register() {} };`,
});
const registry = loadOpenClawPlugins({
@@ -634,15 +640,15 @@ describe("loadOpenClawPlugins", () => {
const bundledDir = makeTempDir();
writePlugin({
id: "shadow",
body: `export default { id: "shadow", register() {} };`,
body: `module.exports = { id: "shadow", register() {} };`,
dir: bundledDir,
filename: "shadow.js",
filename: "shadow.cjs",
});
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
const override = writePlugin({
id: "shadow",
body: `export default { id: "shadow", register() {} };`,
body: `module.exports = { id: "shadow", register() {} };`,
});
const registry = loadOpenClawPlugins({
@@ -668,9 +674,9 @@ describe("loadOpenClawPlugins", () => {
const bundledDir = makeTempDir();
writePlugin({
id: "feishu",
body: `export default { id: "feishu", register() {} };`,
body: `module.exports = { id: "feishu", register() {} };`,
dir: bundledDir,
filename: "index.js",
filename: "index.cjs",
});
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
@@ -680,9 +686,9 @@ describe("loadOpenClawPlugins", () => {
fs.mkdirSync(globalDir, { recursive: true });
writePlugin({
id: "feishu",
body: `export default { id: "feishu", register() {} };`,
body: `module.exports = { id: "feishu", register() {} };`,
dir: globalDir,
filename: "index.js",
filename: "index.cjs",
});
const registry = loadOpenClawPlugins({
@@ -710,7 +716,7 @@ describe("loadOpenClawPlugins", () => {
useNoBundledPlugins();
const plugin = writePlugin({
id: "warn-open-allow",
body: `export default { id: "warn-open-allow", register() {} };`,
body: `module.exports = { id: "warn-open-allow", register() {} };`,
});
const warnings: string[] = [];
loadOpenClawPlugins({
@@ -735,9 +741,9 @@ describe("loadOpenClawPlugins", () => {
fs.mkdirSync(globalDir, { recursive: true });
writePlugin({
id: "rogue",
body: `export default { id: "rogue", register() {} };`,
body: `module.exports = { id: "rogue", register() {} };`,
dir: globalDir,
filename: "index.js",
filename: "index.cjs",
});
const warnings: string[] = [];
@@ -767,7 +773,7 @@ describe("loadOpenClawPlugins", () => {
const { outsideEntry, linkedEntry } = createEscapingEntryFixture({
id: "symlinked",
sourceBody:
'export default { id: "symlinked", register() { throw new Error("should not run"); } };',
'module.exports = { id: "symlinked", register() { throw new Error("should not run"); } };',
});
try {
fs.symlinkSync(outsideEntry, linkedEntry);
@@ -798,7 +804,7 @@ describe("loadOpenClawPlugins", () => {
const { outsideEntry, linkedEntry } = createEscapingEntryFixture({
id: "hardlinked",
sourceBody:
'export default { id: "hardlinked", register() { throw new Error("should not run"); } };',
'module.exports = { id: "hardlinked", register() { throw new Error("should not run"); } };',
});
try {
fs.linkSync(outsideEntry, linkedEntry);