mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:54:58 +00:00
test(integration): dedupe messaging, secrets, and plugin test suites
This commit is contained in:
@@ -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