mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-28 10:22:32 +00:00
fix(plugins): skip allowlist warning for config paths
This commit is contained in:
@@ -2708,50 +2708,81 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
it("warns about open allowlists for discoverable plugins once per plugin set", () => {
|
||||
it("warns about open allowlists only for auto-discovered plugins", () => {
|
||||
useNoBundledPlugins();
|
||||
clearPluginLoaderCache();
|
||||
const scenarios = [
|
||||
{
|
||||
label: "single load warns",
|
||||
pluginId: "warn-open-allow",
|
||||
label: "explicit config path stays quiet",
|
||||
pluginId: "warn-open-allow-config",
|
||||
loads: 1,
|
||||
expectedWarnings: 1,
|
||||
expectedWarnings: 0,
|
||||
loadRegistry: (warnings: string[]) => {
|
||||
const plugin = writePlugin({
|
||||
id: "warn-open-allow-config",
|
||||
body: `module.exports = { id: "warn-open-allow-config", register() {} };`,
|
||||
});
|
||||
return loadOpenClawPlugins({
|
||||
cache: false,
|
||||
logger: createWarningLogger(warnings),
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "repeated identical loads dedupe warning",
|
||||
pluginId: "warn-open-allow-once",
|
||||
label: "workspace discovery warns once",
|
||||
pluginId: "warn-open-allow-workspace",
|
||||
loads: 2,
|
||||
expectedWarnings: 1,
|
||||
loadRegistry: (() => {
|
||||
const workspaceDir = makeTempDir();
|
||||
const workspaceExtDir = path.join(
|
||||
workspaceDir,
|
||||
".openclaw",
|
||||
"extensions",
|
||||
"warn-open-allow-workspace",
|
||||
);
|
||||
mkdirSafe(workspaceExtDir);
|
||||
writePlugin({
|
||||
id: "warn-open-allow-workspace",
|
||||
body: `module.exports = { id: "warn-open-allow-workspace", register() {} };`,
|
||||
dir: workspaceExtDir,
|
||||
filename: "index.cjs",
|
||||
});
|
||||
return (warnings: string[]) =>
|
||||
loadOpenClawPlugins({
|
||||
cache: false,
|
||||
workspaceDir,
|
||||
logger: createWarningLogger(warnings),
|
||||
config: {
|
||||
plugins: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
})(),
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const scenario of scenarios) {
|
||||
const plugin = writePlugin({
|
||||
id: scenario.pluginId,
|
||||
body: `module.exports = { id: "${scenario.pluginId}", register() {} };`,
|
||||
});
|
||||
const warnings: string[] = [];
|
||||
const options = {
|
||||
cache: false,
|
||||
logger: createWarningLogger(warnings),
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
for (let index = 0; index < scenario.loads; index += 1) {
|
||||
loadOpenClawPlugins(options);
|
||||
scenario.loadRegistry(warnings);
|
||||
}
|
||||
|
||||
const openAllowWarnings = warnings.filter((msg) => msg.includes("plugins.allow is empty"));
|
||||
expect(openAllowWarnings, scenario.label).toHaveLength(scenario.expectedWarnings);
|
||||
expect(
|
||||
openAllowWarnings.some((msg) => msg.includes(scenario.pluginId)),
|
||||
scenario.label,
|
||||
).toBe(true);
|
||||
if (scenario.expectedWarnings > 0) {
|
||||
expect(
|
||||
openAllowWarnings.some((msg) => msg.includes(scenario.pluginId)),
|
||||
scenario.label,
|
||||
).toBe(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -607,18 +607,20 @@ function warnWhenAllowlistIsOpen(params: {
|
||||
if (params.allow.length > 0) {
|
||||
return;
|
||||
}
|
||||
const nonBundled = params.discoverablePlugins.filter((entry) => entry.origin !== "bundled");
|
||||
if (nonBundled.length === 0) {
|
||||
const autoDiscoverable = params.discoverablePlugins.filter(
|
||||
(entry) => entry.origin === "workspace" || entry.origin === "global",
|
||||
);
|
||||
if (autoDiscoverable.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (openAllowlistWarningCache.has(params.warningCacheKey)) {
|
||||
return;
|
||||
}
|
||||
const preview = nonBundled
|
||||
const preview = autoDiscoverable
|
||||
.slice(0, 6)
|
||||
.map((entry) => `${entry.id} (${entry.source})`)
|
||||
.join(", ");
|
||||
const extra = nonBundled.length > 6 ? ` (+${nonBundled.length - 6} more)` : "";
|
||||
const extra = autoDiscoverable.length > 6 ? ` (+${autoDiscoverable.length - 6} more)` : "";
|
||||
openAllowlistWarningCache.add(params.warningCacheKey);
|
||||
params.logger.warn(
|
||||
`[plugins] plugins.allow is empty; discovered non-bundled plugins may auto-load: ${preview}${extra}. Set plugins.allow to explicit trusted ids.`,
|
||||
|
||||
Reference in New Issue
Block a user