mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
test(integration): dedupe messaging, secrets, and plugin test suites
This commit is contained in:
@@ -26,6 +26,27 @@ async function withStateDir<T>(stateDir: string, fn: () => Promise<T>) {
|
||||
);
|
||||
}
|
||||
|
||||
function writePluginPackageManifest(params: {
|
||||
packageDir: string;
|
||||
packageName: string;
|
||||
extensions: string[];
|
||||
}) {
|
||||
fs.writeFileSync(
|
||||
path.join(params.packageDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: params.packageName,
|
||||
openclaw: { extensions: params.extensions },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
function expectEscapesPackageDiagnostic(diagnostics: Array<{ message: string }>) {
|
||||
expect(diagnostics.some((entry) => entry.message.includes("escapes package directory"))).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of tempDirs.splice(0)) {
|
||||
try {
|
||||
@@ -95,14 +116,11 @@ describe("discoverOpenClawPlugins", () => {
|
||||
const globalExt = path.join(stateDir, "extensions", "pack");
|
||||
fs.mkdirSync(path.join(globalExt, "src"), { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "pack",
|
||||
openclaw: { extensions: ["./src/one.ts", "./src/two.ts"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: globalExt,
|
||||
packageName: "pack",
|
||||
extensions: ["./src/one.ts", "./src/two.ts"],
|
||||
});
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "src", "one.ts"),
|
||||
"export default function () {}",
|
||||
@@ -128,14 +146,11 @@ describe("discoverOpenClawPlugins", () => {
|
||||
const globalExt = path.join(stateDir, "extensions", "voice-call-pack");
|
||||
fs.mkdirSync(path.join(globalExt, "src"), { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/voice-call",
|
||||
openclaw: { extensions: ["./src/index.ts"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: globalExt,
|
||||
packageName: "@openclaw/voice-call",
|
||||
extensions: ["./src/index.ts"],
|
||||
});
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "src", "index.ts"),
|
||||
"export default function () {}",
|
||||
@@ -155,14 +170,11 @@ describe("discoverOpenClawPlugins", () => {
|
||||
const packDir = path.join(stateDir, "packs", "demo-plugin-dir");
|
||||
fs.mkdirSync(packDir, { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(packDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/demo-plugin-dir",
|
||||
openclaw: { extensions: ["./index.js"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: packDir,
|
||||
packageName: "@openclaw/demo-plugin-dir",
|
||||
extensions: ["./index.js"],
|
||||
});
|
||||
fs.writeFileSync(path.join(packDir, "index.js"), "module.exports = {}", "utf-8");
|
||||
|
||||
const { candidates } = await withStateDir(stateDir, async () => {
|
||||
@@ -178,14 +190,11 @@ describe("discoverOpenClawPlugins", () => {
|
||||
const outside = path.join(stateDir, "outside.js");
|
||||
fs.mkdirSync(globalExt, { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/escape-pack",
|
||||
openclaw: { extensions: ["../../outside.js"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: globalExt,
|
||||
packageName: "@openclaw/escape-pack",
|
||||
extensions: ["../../outside.js"],
|
||||
});
|
||||
fs.writeFileSync(outside, "export default function () {}", "utf-8");
|
||||
|
||||
const result = await withStateDir(stateDir, async () => {
|
||||
@@ -193,9 +202,7 @@ describe("discoverOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
expect(result.candidates).toHaveLength(0);
|
||||
expect(
|
||||
result.diagnostics.some((diag) => diag.message.includes("escapes package directory")),
|
||||
).toBe(true);
|
||||
expectEscapesPackageDiagnostic(result.diagnostics);
|
||||
});
|
||||
|
||||
it("rejects package extension entries that escape via symlink", async () => {
|
||||
@@ -212,23 +219,18 @@ describe("discoverOpenClawPlugins", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/pack",
|
||||
openclaw: { extensions: ["./linked/escape.ts"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: globalExt,
|
||||
packageName: "@openclaw/pack",
|
||||
extensions: ["./linked/escape.ts"],
|
||||
});
|
||||
|
||||
const { candidates, diagnostics } = await withStateDir(stateDir, async () => {
|
||||
return discoverOpenClawPlugins({});
|
||||
});
|
||||
|
||||
expect(candidates.some((candidate) => candidate.idHint === "pack")).toBe(false);
|
||||
expect(diagnostics.some((entry) => entry.message.includes("escapes package directory"))).toBe(
|
||||
true,
|
||||
);
|
||||
expectEscapesPackageDiagnostic(diagnostics);
|
||||
});
|
||||
|
||||
it("rejects package extension entries that are hardlinked aliases", async () => {
|
||||
@@ -252,23 +254,18 @@ describe("discoverOpenClawPlugins", () => {
|
||||
throw err;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(globalExt, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/pack",
|
||||
openclaw: { extensions: ["./escape.ts"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
writePluginPackageManifest({
|
||||
packageDir: globalExt,
|
||||
packageName: "@openclaw/pack",
|
||||
extensions: ["./escape.ts"],
|
||||
});
|
||||
|
||||
const { candidates, diagnostics } = await withStateDir(stateDir, async () => {
|
||||
return discoverOpenClawPlugins({});
|
||||
});
|
||||
|
||||
expect(candidates.some((candidate) => candidate.idHint === "pack")).toBe(false);
|
||||
expect(diagnostics.some((entry) => entry.message.includes("escapes package directory"))).toBe(
|
||||
true,
|
||||
);
|
||||
expectEscapesPackageDiagnostic(diagnostics);
|
||||
});
|
||||
|
||||
it("ignores package manifests that are hardlinked aliases", async () => {
|
||||
|
||||
@@ -158,6 +158,19 @@ function expectPluginFiles(result: { targetDir: string }, stateDir: string, plug
|
||||
expect(fs.existsSync(path.join(result.targetDir, "dist", "index.js"))).toBe(true);
|
||||
}
|
||||
|
||||
function expectSuccessfulArchiveInstall(params: {
|
||||
result: Awaited<ReturnType<typeof installPluginFromArchive>>;
|
||||
stateDir: string;
|
||||
pluginId: string;
|
||||
}) {
|
||||
expect(params.result.ok).toBe(true);
|
||||
if (!params.result.ok) {
|
||||
return;
|
||||
}
|
||||
expect(params.result.pluginId).toBe(params.pluginId);
|
||||
expectPluginFiles(params.result, params.stateDir, params.pluginId);
|
||||
}
|
||||
|
||||
function setupPluginInstallDirs() {
|
||||
const tmpDir = makeTempDir();
|
||||
const pluginDir = path.join(tmpDir, "plugin-src");
|
||||
@@ -200,6 +213,30 @@ async function installFromDirWithWarnings(params: { pluginDir: string; extension
|
||||
return { result, warnings };
|
||||
}
|
||||
|
||||
function setupManifestInstallFixture(params: { manifestId: string }) {
|
||||
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
|
||||
fs.mkdirSync(path.join(pluginDir, "dist"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/cognee-openclaw",
|
||||
version: "0.0.1",
|
||||
openclaw: { extensions: ["./dist/index.js"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(path.join(pluginDir, "dist", "index.js"), "export {};", "utf-8");
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify({
|
||||
id: params.manifestId,
|
||||
configSchema: { type: "object", properties: {} },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
return { pluginDir, extensionsDir };
|
||||
}
|
||||
|
||||
async function expectArchiveInstallReservedSegmentRejection(params: {
|
||||
packageName: string;
|
||||
outName: string;
|
||||
@@ -281,12 +318,7 @@ describe("installPluginFromArchive", () => {
|
||||
archivePath,
|
||||
extensionsDir,
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) {
|
||||
return;
|
||||
}
|
||||
expect(result.pluginId).toBe("voice-call");
|
||||
expectPluginFiles(result, stateDir, "voice-call");
|
||||
expectSuccessfulArchiveInstall({ result, stateDir, pluginId: "voice-call" });
|
||||
});
|
||||
|
||||
it("rejects installing when plugin already exists", async () => {
|
||||
@@ -324,13 +356,7 @@ describe("installPluginFromArchive", () => {
|
||||
archivePath,
|
||||
extensionsDir,
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) {
|
||||
return;
|
||||
}
|
||||
expect(result.pluginId).toBe("zipper");
|
||||
expectPluginFiles(result, stateDir, "zipper");
|
||||
expectSuccessfulArchiveInstall({ result, stateDir, pluginId: "zipper" });
|
||||
});
|
||||
|
||||
it("allows updates when mode is update", async () => {
|
||||
@@ -515,26 +541,9 @@ describe("installPluginFromDir", () => {
|
||||
});
|
||||
|
||||
it("uses openclaw.plugin.json id as install key when it differs from package name", async () => {
|
||||
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
|
||||
fs.mkdirSync(path.join(pluginDir, "dist"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/cognee-openclaw",
|
||||
version: "0.0.1",
|
||||
openclaw: { extensions: ["./dist/index.js"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(path.join(pluginDir, "dist", "index.js"), "export {};", "utf-8");
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify({
|
||||
id: "memory-cognee",
|
||||
configSchema: { type: "object", properties: {} },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
const { pluginDir, extensionsDir } = setupManifestInstallFixture({
|
||||
manifestId: "memory-cognee",
|
||||
});
|
||||
|
||||
const infoMessages: string[] = [];
|
||||
const res = await installPluginFromDir({
|
||||
@@ -559,26 +568,9 @@ describe("installPluginFromDir", () => {
|
||||
});
|
||||
|
||||
it("normalizes scoped manifest ids to unscoped install keys", async () => {
|
||||
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
|
||||
fs.mkdirSync(path.join(pluginDir, "dist"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "@openclaw/cognee-openclaw",
|
||||
version: "0.0.1",
|
||||
openclaw: { extensions: ["./dist/index.js"] },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(path.join(pluginDir, "dist", "index.js"), "export {};", "utf-8");
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify({
|
||||
id: "@team/memory-cognee",
|
||||
configSchema: { type: "object", properties: {} },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
const { pluginDir, extensionsDir } = setupManifestInstallFixture({
|
||||
manifestId: "@team/memory-cognee",
|
||||
});
|
||||
|
||||
const res = await installPluginFromDir({
|
||||
dirPath: pluginDir,
|
||||
|
||||
@@ -132,6 +132,70 @@ function expectTelegramLoaded(registry: ReturnType<typeof loadOpenClawPlugins>)
|
||||
expect(registry.channels.some((entry) => entry.plugin.id === "telegram")).toBe(true);
|
||||
}
|
||||
|
||||
function useNoBundledPlugins() {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
}
|
||||
|
||||
function loadRegistryFromSinglePlugin(params: {
|
||||
plugin: TempPlugin;
|
||||
pluginConfig?: Record<string, unknown>;
|
||||
includeWorkspaceDir?: boolean;
|
||||
options?: Omit<Parameters<typeof loadOpenClawPlugins>[0], "cache" | "workspaceDir" | "config">;
|
||||
}) {
|
||||
const pluginConfig = params.pluginConfig ?? {};
|
||||
return loadOpenClawPlugins({
|
||||
cache: false,
|
||||
...(params.includeWorkspaceDir === false ? {} : { workspaceDir: params.plugin.dir }),
|
||||
...params.options,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [params.plugin.file] },
|
||||
...pluginConfig,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function createWarningLogger(warnings: string[]) {
|
||||
return {
|
||||
info: () => {},
|
||||
warn: (msg: string) => warnings.push(msg),
|
||||
error: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
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");
|
||||
fs.writeFileSync(outsideEntry, params.sourceBody, "utf-8");
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: params.id,
|
||||
configSchema: EMPTY_PLUGIN_SCHEMA,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
return { pluginDir, outsideEntry, linkedEntry };
|
||||
}
|
||||
|
||||
function createPluginSdkAliasFixture() {
|
||||
const root = makeTempDir();
|
||||
const srcFile = path.join(root, "src", "plugin-sdk", "index.ts");
|
||||
const distFile = path.join(root, "dist", "plugin-sdk", "index.js");
|
||||
fs.mkdirSync(path.dirname(srcFile), { recursive: true });
|
||||
fs.mkdirSync(path.dirname(distFile), { recursive: true });
|
||||
fs.writeFileSync(srcFile, "export {};\n", "utf-8");
|
||||
fs.writeFileSync(distFile, "export {};\n", "utf-8");
|
||||
return { root, srcFile, distFile };
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (prevBundledDir === undefined) {
|
||||
delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
@@ -327,7 +391,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("loads plugins when source and root differ only by realpath alias", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "alias-safe",
|
||||
body: `export default { id: "alias-safe", register() {} };`,
|
||||
@@ -337,14 +401,10 @@ describe("loadOpenClawPlugins", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
allow: ["alias-safe"],
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["alias-safe"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -353,21 +413,17 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("denylist disables plugins even if allowed", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "blocked",
|
||||
body: `export default { id: "blocked", register() {} };`,
|
||||
});
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
allow: ["blocked"],
|
||||
deny: ["blocked"],
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["blocked"],
|
||||
deny: ["blocked"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -376,22 +432,18 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("fails fast on invalid plugin config", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "configurable",
|
||||
body: `export default { id: "configurable", register() {} };`,
|
||||
});
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
entries: {
|
||||
configurable: {
|
||||
config: "nope" as unknown as Record<string, unknown>,
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
entries: {
|
||||
configurable: {
|
||||
config: "nope" as unknown as Record<string, unknown>,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -403,7 +455,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("registers channel plugins", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "channel-demo",
|
||||
body: `export default { id: "channel-demo", register(api) {
|
||||
@@ -428,14 +480,10 @@ describe("loadOpenClawPlugins", () => {
|
||||
} };`,
|
||||
});
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
allow: ["channel-demo"],
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["channel-demo"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -444,7 +492,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("registers http handlers", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "http-demo",
|
||||
body: `export default { id: "http-demo", register(api) {
|
||||
@@ -452,14 +500,10 @@ describe("loadOpenClawPlugins", () => {
|
||||
} };`,
|
||||
});
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
allow: ["http-demo"],
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["http-demo"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -470,7 +514,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("registers http routes", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "http-route-demo",
|
||||
body: `export default { id: "http-route-demo", register(api) {
|
||||
@@ -478,14 +522,10 @@ describe("loadOpenClawPlugins", () => {
|
||||
} };`,
|
||||
});
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir: plugin.dir,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
allow: ["http-route-demo"],
|
||||
},
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["http-route-demo"],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -644,7 +684,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("warns when plugins.allow is empty and non-bundled plugins are discoverable", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "warn-open-allow",
|
||||
body: `export default { id: "warn-open-allow", register() {} };`,
|
||||
@@ -652,11 +692,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
const warnings: string[] = [];
|
||||
loadOpenClawPlugins({
|
||||
cache: false,
|
||||
logger: {
|
||||
info: () => {},
|
||||
warn: (msg) => warnings.push(msg),
|
||||
error: () => {},
|
||||
},
|
||||
logger: createWarningLogger(warnings),
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
@@ -669,7 +705,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("warns when loaded non-bundled plugin has no install/load-path provenance", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
useNoBundledPlugins();
|
||||
const stateDir = makeTempDir();
|
||||
withEnv({ OPENCLAW_STATE_DIR: stateDir, CLAWDBOT_STATE_DIR: undefined }, () => {
|
||||
const globalDir = path.join(stateDir, "extensions", "rogue");
|
||||
@@ -684,11 +720,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
const warnings: string[] = [];
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
logger: {
|
||||
info: () => {},
|
||||
warn: (msg) => warnings.push(msg),
|
||||
error: () => {},
|
||||
},
|
||||
logger: createWarningLogger(warnings),
|
||||
config: {
|
||||
plugins: {
|
||||
allow: ["rogue"],
|
||||
@@ -708,28 +740,12 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("rejects plugin entry files that escape plugin root via symlink", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
const pluginDir = makeTempDir();
|
||||
const outsideDir = makeTempDir();
|
||||
const outsideEntry = path.join(outsideDir, "outside.js");
|
||||
const linkedEntry = path.join(pluginDir, "entry.js");
|
||||
fs.writeFileSync(
|
||||
outsideEntry,
|
||||
'export default { id: "symlinked", register() { throw new Error("should not run"); } };',
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: "symlinked",
|
||||
configSchema: EMPTY_PLUGIN_SCHEMA,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
useNoBundledPlugins();
|
||||
const { outsideEntry, linkedEntry } = createEscapingEntryFixture({
|
||||
id: "symlinked",
|
||||
sourceBody:
|
||||
'export default { id: "symlinked", register() { throw new Error("should not run"); } };',
|
||||
});
|
||||
try {
|
||||
fs.symlinkSync(outsideEntry, linkedEntry);
|
||||
} catch {
|
||||
@@ -755,28 +771,12 @@ describe("loadOpenClawPlugins", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
const pluginDir = makeTempDir();
|
||||
const outsideDir = makeTempDir();
|
||||
const outsideEntry = path.join(outsideDir, "outside.js");
|
||||
const linkedEntry = path.join(pluginDir, "entry.js");
|
||||
fs.writeFileSync(
|
||||
outsideEntry,
|
||||
'export default { id: "hardlinked", register() { throw new Error("should not run"); } };',
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: "hardlinked",
|
||||
configSchema: EMPTY_PLUGIN_SCHEMA,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
useNoBundledPlugins();
|
||||
const { outsideEntry, linkedEntry } = createEscapingEntryFixture({
|
||||
id: "hardlinked",
|
||||
sourceBody:
|
||||
'export default { id: "hardlinked", register() { throw new Error("should not run"); } };',
|
||||
});
|
||||
try {
|
||||
fs.linkSync(outsideEntry, linkedEntry);
|
||||
} catch (err) {
|
||||
@@ -802,13 +802,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("prefers dist plugin-sdk alias when loader runs from dist", () => {
|
||||
const root = makeTempDir();
|
||||
const srcFile = path.join(root, "src", "plugin-sdk", "index.ts");
|
||||
const distFile = path.join(root, "dist", "plugin-sdk", "index.js");
|
||||
fs.mkdirSync(path.dirname(srcFile), { recursive: true });
|
||||
fs.mkdirSync(path.dirname(distFile), { recursive: true });
|
||||
fs.writeFileSync(srcFile, "export {};\n", "utf-8");
|
||||
fs.writeFileSync(distFile, "export {};\n", "utf-8");
|
||||
const { root, distFile } = createPluginSdkAliasFixture();
|
||||
|
||||
const resolved = __testing.resolvePluginSdkAliasFile({
|
||||
srcFile: "index.ts",
|
||||
@@ -819,13 +813,7 @@ describe("loadOpenClawPlugins", () => {
|
||||
});
|
||||
|
||||
it("prefers src plugin-sdk alias when loader runs from src in non-production", () => {
|
||||
const root = makeTempDir();
|
||||
const srcFile = path.join(root, "src", "plugin-sdk", "index.ts");
|
||||
const distFile = path.join(root, "dist", "plugin-sdk", "index.js");
|
||||
fs.mkdirSync(path.dirname(srcFile), { recursive: true });
|
||||
fs.mkdirSync(path.dirname(distFile), { recursive: true });
|
||||
fs.writeFileSync(srcFile, "export {};\n", "utf-8");
|
||||
fs.writeFileSync(distFile, "export {};\n", "utf-8");
|
||||
const { root, srcFile } = createPluginSdkAliasFixture();
|
||||
|
||||
const resolved = withEnv({ NODE_ENV: undefined }, () =>
|
||||
__testing.resolvePluginSdkAliasFile({
|
||||
|
||||
Reference in New Issue
Block a user