Fix plugin update dependency failures and dedupe warnings

This commit is contained in:
Vincent Koc
2026-03-13 11:24:40 -07:00
parent 1d300c416d
commit cc5168b5c3
4 changed files with 89 additions and 1 deletions

View File

@@ -1472,6 +1472,30 @@ describe("loadOpenClawPlugins", () => {
).toBe(true);
});
it("dedupes the open allowlist warning for repeated loads of the same plugin set", () => {
useNoBundledPlugins();
clearPluginLoaderCache();
const plugin = writePlugin({
id: "warn-open-allow-once",
body: `module.exports = { id: "warn-open-allow-once", register() {} };`,
});
const warnings: string[] = [];
const options = {
cache: false,
logger: createWarningLogger(warnings),
config: {
plugins: {
load: { paths: [plugin.file] },
},
},
} as const;
loadOpenClawPlugins(options);
loadOpenClawPlugins(options);
expect(warnings.filter((msg) => msg.includes("plugins.allow is empty"))).toHaveLength(1);
});
it("does not auto-load workspace-discovered plugins unless explicitly trusted", () => {
useNoBundledPlugins();
const workspaceDir = makeTempDir();

View File

@@ -51,9 +51,11 @@ export type PluginLoadOptions = {
const MAX_PLUGIN_REGISTRY_CACHE_ENTRIES = 32;
const registryCache = new Map<string, PluginRegistry>();
const openAllowlistWarningCache = new Set<string>();
export function clearPluginLoaderCache(): void {
registryCache.clear();
openAllowlistWarningCache.clear();
}
const defaultLogger = () => createSubsystemLogger("plugins");
@@ -455,6 +457,7 @@ function warnWhenAllowlistIsOpen(params: {
logger: PluginLogger;
pluginsEnabled: boolean;
allow: string[];
warningCacheKey: string;
discoverablePlugins: Array<{ id: string; source: string; origin: PluginRecord["origin"] }>;
}) {
if (!params.pluginsEnabled) {
@@ -467,11 +470,15 @@ function warnWhenAllowlistIsOpen(params: {
if (nonBundled.length === 0) {
return;
}
if (openAllowlistWarningCache.has(params.warningCacheKey)) {
return;
}
const preview = nonBundled
.slice(0, 6)
.map((entry) => `${entry.id} (${entry.source})`)
.join(", ");
const extra = nonBundled.length > 6 ? ` (+${nonBundled.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.`,
);
@@ -598,6 +605,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
logger,
pluginsEnabled: normalized.enabled,
allow: normalized.allow,
warningCacheKey: cacheKey,
discoverablePlugins: manifestRegistry.plugins.map((plugin) => ({
id: plugin.id,
source: plugin.source,