From 06de515b6c42816b62ec752e1c221cab67b38501 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 26 Mar 2026 11:22:53 +0530 Subject: [PATCH] fix(plugins): skip allowlist warning for config paths --- src/plugins/loader.test.ts | 79 ++++++++++++++++++++++++++------------ src/plugins/loader.ts | 10 +++-- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/plugins/loader.test.ts b/src/plugins/loader.test.ts index 9a7b4fc420c..3153229b69f 100644 --- a/src/plugins/loader.test.ts +++ b/src/plugins/loader.test.ts @@ -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); + } } }); diff --git a/src/plugins/loader.ts b/src/plugins/loader.ts index 1472cd2cfee..8994121350c 100644 --- a/src/plugins/loader.ts +++ b/src/plugins/loader.ts @@ -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.`,