Skip to content

Commit 7963af0

Browse files
author
Peter Steinberger
committed
fix(cli): surface validated plugin doctor warnings
1 parent c1cbcf0 commit 7963af0

2 files changed

Lines changed: 161 additions & 22 deletions

File tree

‎src/cli/plugins-cli.list.test.ts‎

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Plugins CLI list tests cover plugin listing output and installed-state formatting.
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3-
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import type {
4+
ConfigFileSnapshot,
5+
ConfigValidationIssue,
6+
OpenClawConfig,
7+
} from "../config/types.openclaw.js";
48
import { createPluginRecord } from "../plugins/status.test-fixtures.js";
59
import { withEnvAsync } from "../test-utils/env.js";
610
import {
@@ -10,6 +14,7 @@ import {
1014
buildPluginSnapshotReport,
1115
inspectPluginRegistry,
1216
loadConfig,
17+
loadPluginManifestRegistry,
1318
readConfigFileSnapshot,
1419
resetPluginsCliTestState,
1520
refreshPluginRegistry,
@@ -27,6 +32,37 @@ const cleanDoctorMessage =
2732
"Plugin discovery, module loading, compatibility, and configuration checks passed. " +
2833
'Run "openclaw health" to check the running Gateway, including runtime quarantines and fallbacks.';
2934

35+
async function mockPluginDoctorValidationWarnings(warnings: ConfigValidationIssue[]) {
36+
const config: OpenClawConfig = {
37+
plugins: {
38+
allow: ["imessage", "memory-core"],
39+
entries: { google: { config: { apiKey: "test-google-key" } } },
40+
},
41+
};
42+
loadConfig.mockReturnValue(config);
43+
const snapshot = (await readConfigFileSnapshot()) as ConfigFileSnapshot;
44+
readConfigFileSnapshot.mockResolvedValueOnce({ ...snapshot, valid: true, warnings });
45+
loadPluginManifestRegistry.mockReturnValue({
46+
plugins: ["google", "imessage", "memory-core"].map((id) => ({
47+
id,
48+
channels: [],
49+
providers: [],
50+
cliBackends: [],
51+
skills: [],
52+
hooks: [],
53+
origin: "bundled",
54+
rootDir: `/plugins/${id}`,
55+
source: `/plugins/${id}`,
56+
manifestPath: `/plugins/${id}/openclaw.plugin.json`,
57+
})),
58+
diagnostics: [],
59+
});
60+
buildPluginDiagnosticsReport.mockReturnValue({
61+
plugins: [createPluginRecord({ id: "google", enabled: false, status: "disabled" })],
62+
diagnostics: [],
63+
});
64+
}
65+
3066
vi.mock("../skills/workshop/tool-policy-diagnostic.js", () => ({
3167
detectSkillWorkshopToolPolicyDiagnostic: workshopMocks.detectToolPolicyDiagnostic,
3268
}));
@@ -101,6 +137,110 @@ describe("plugins cli list", () => {
101137
expect(runtimeLogs).toContain(cleanDoctorMessage);
102138
});
103139

140+
it.each([
141+
{ format: "human", args: [] },
142+
{ format: "JSON", args: ["--json"] },
143+
])(
144+
"reports validated disabled-plugin configuration warnings in $format output",
145+
async ({ args }) => {
146+
await mockPluginDoctorValidationWarnings([
147+
{
148+
path: "plugins.entries.google",
149+
message: "plugin disabled (not in allowlist) but config is present",
150+
},
151+
]);
152+
153+
await runPluginsCommand(["plugins", "doctor", ...args]);
154+
155+
const warning =
156+
"- plugins.entries.google: plugin disabled (not in allowlist) but config is present";
157+
if (args.includes("--json")) {
158+
const output = JSON.parse(runtimeLogs[0] ?? "null") as {
159+
ok: boolean;
160+
configurationWarnings: string[];
161+
};
162+
expect(output.ok).toBe(false);
163+
expect(output.configurationWarnings).toEqual([warning]);
164+
return;
165+
}
166+
expect(runtimeLogs.join("\n")).toContain(warning);
167+
expect(runtimeLogs).not.toContain(cleanDoctorMessage);
168+
},
169+
);
170+
171+
it("deduplicates plugin validation warnings while ignoring other config owners", async () => {
172+
const googleWarning = {
173+
path: "plugins.entries.google",
174+
message: "plugin disabled (not in allowlist) but config is present",
175+
};
176+
await mockPluginDoctorValidationWarnings([
177+
{ path: "gateway.auth", message: "owned by gateway doctor" },
178+
{ path: "plugins", message: "root plugin warning" },
179+
googleWarning,
180+
googleWarning,
181+
{ path: "pluginsOther.entries.google", message: "not a plugin-owned path" },
182+
]);
183+
184+
await runPluginsCommand(["plugins", "doctor", "--json"]);
185+
186+
const output = JSON.parse(runtimeLogs[0] ?? "null") as {
187+
ok: boolean;
188+
configurationWarnings: string[];
189+
};
190+
expect(output.ok).toBe(false);
191+
expect(output.configurationWarnings).toEqual([
192+
"- plugins: root plugin warning",
193+
"- plugins.entries.google: plugin disabled (not in allowlist) but config is present",
194+
]);
195+
});
196+
197+
it.each([
198+
{ format: "human", args: [] },
199+
{ format: "JSON", args: ["--json"] },
200+
])("ignores unrelated validation warnings in $format doctor output", async ({ args }) => {
201+
await mockPluginDoctorValidationWarnings([
202+
{ path: "gateway.auth", message: "owned by gateway doctor" },
203+
]);
204+
205+
await runPluginsCommand(["plugins", "doctor", ...args]);
206+
207+
if (args.includes("--json")) {
208+
expect(JSON.parse(runtimeLogs[0] ?? "null")).toMatchObject({
209+
ok: true,
210+
configurationWarnings: [],
211+
});
212+
return;
213+
}
214+
expect(runtimeLogs).toContain(cleanDoctorMessage);
215+
});
216+
217+
it.each([
218+
{ format: "human", args: [] },
219+
{ format: "JSON", args: ["--json"] },
220+
])("sanitizes plugin warning terminal controls in $format doctor output", async ({ args }) => {
221+
await mockPluginDoctorValidationWarnings([
222+
{
223+
path: "plugins.\nentries.google\u001b[31m",
224+
message: "bad\r\n\tvalue\u001b[0m\u0007",
225+
},
226+
]);
227+
228+
await runPluginsCommand(["plugins", "doctor", ...args]);
229+
230+
const warning = "- plugins.\\nentries.google: bad\\r\\n\\tvalue";
231+
if (args.includes("--json")) {
232+
expect(JSON.parse(runtimeLogs[0] ?? "null")).toMatchObject({
233+
ok: false,
234+
configurationWarnings: [warning],
235+
});
236+
return;
237+
}
238+
const output = runtimeLogs.join("\n");
239+
expect(output).toContain(warning);
240+
expect(output).not.toContain("\u0007");
241+
expect(output).not.toContain("\u001b");
242+
});
243+
104244
it("emits one sanitized JSON doctor report without human decoration", async () => {
105245
const homeDir = "/tmp/openclaw-plugin-doctor-home";
106246
buildPluginDiagnosticsReport.mockReturnValue({

‎src/cli/plugins-cli.runtime.ts‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
readConfigFileSnapshot,
1313
replaceConfigFile,
1414
} from "../config/config.js";
15+
import { formatConfigIssueLines } from "../config/issue-format.js";
1516
import type { OpenClawConfig } from "../config/types.openclaw.js";
1617
import { emitDiagnosticsTimelineEvent } from "../infra/diagnostics-timeline.js";
1718
import { withPluginLifecycleLease } from "../plugins/plugin-lifecycle-lease.js";
@@ -141,7 +142,6 @@ function formatDisabledRuntimePluginGuidance(params: {
141142

142143
function collectConfiguredRuntimePluginWarnings(params: {
143144
cfg: OpenClawConfig;
144-
env: NodeJS.ProcessEnv;
145145
plugins: readonly { enabled?: boolean; id: string; status?: string }[];
146146
}): string[] {
147147
const enabledPluginIds = new Set(
@@ -369,34 +369,33 @@ export async function runPluginsDoctorCommand(opts: PluginDoctorOptions = {}): P
369369
} = await import("../commands/doctor/shared/stale-plugin-config.js");
370370
const cfg = getRuntimeConfig();
371371
const configSnapshot = await readConfigFileSnapshot().catch(() => null);
372-
const sourceCfg = (configSnapshot?.sourceConfig ?? configSnapshot?.config ?? cfg) as
373-
| OpenClawConfig
374-
| undefined;
372+
const sourceCfg = configSnapshot?.sourceConfig ?? configSnapshot?.config ?? cfg;
375373
const report = buildPluginDiagnosticsReport({ config: cfg, effectiveOnly: true });
376374
const errors = report.plugins.filter((p) => p.status === "error");
377375
const diags = report.diagnostics.filter((entry) => !isConfigSelectedShadowDiagnostic(entry));
378376
const shadowed = report.diagnostics.filter((entry) =>
379377
isErroredConfigSelectedShadowDiagnostic({ entry, plugins: report.plugins }),
380378
);
381379
const compatibility = buildPluginCompatibilityNotices({ report });
382-
const stalePluginConfigHits = scanStalePluginConfig(sourceCfg ?? cfg, process.env);
383-
const stalePluginConfigWarnings = collectStalePluginConfigWarnings({
384-
hits: stalePluginConfigHits,
385-
doctorFixCommand: "openclaw doctor --fix",
386-
autoRepairBlocked: isStalePluginAutoRepairBlocked(sourceCfg ?? cfg, process.env),
387-
});
388-
const configuredRuntimePluginWarnings = collectConfiguredRuntimePluginWarnings({
389-
cfg: sourceCfg ?? cfg,
390-
env: process.env,
391-
plugins: report.plugins,
392-
});
380+
const pluginConfigWarnings = new Set([
381+
...formatConfigIssueLines(
382+
(configSnapshot?.warnings ?? []).filter(
383+
({ path }) => path === "plugins" || path.startsWith("plugins."),
384+
),
385+
),
386+
...collectStalePluginConfigWarnings({
387+
hits: scanStalePluginConfig(sourceCfg, process.env),
388+
doctorFixCommand: "openclaw doctor --fix",
389+
autoRepairBlocked: isStalePluginAutoRepairBlocked(sourceCfg, process.env),
390+
}),
391+
...collectConfiguredRuntimePluginWarnings({ cfg: sourceCfg, plugins: report.plugins }),
392+
]);
393393
const hasInstallTreeIssues =
394394
errors.length > 0 || diags.length > 0 || shadowed.length > 0 || compatibility.length > 0;
395-
const pluginConfigWarnings = [...stalePluginConfigWarnings, ...configuredRuntimePluginWarnings];
396395

397396
if (opts.json) {
398397
defaultRuntime.writeJson({
399-
ok: !hasInstallTreeIssues && pluginConfigWarnings.length === 0,
398+
ok: !hasInstallTreeIssues && pluginConfigWarnings.size === 0,
400399
pluginErrors: errors.map((entry) => ({
401400
id: entry.id,
402401
...(entry.failurePhase ? { failurePhase: entry.failurePhase } : {}),
@@ -437,12 +436,12 @@ export async function runPluginsDoctorCommand(opts: PluginDoctorOptions = {}): P
437436
...notice,
438437
message: shortenHomeInString(notice.message),
439438
})),
440-
configurationWarnings: pluginConfigWarnings.map(shortenHomeInString),
439+
configurationWarnings: Array.from(pluginConfigWarnings, shortenHomeInString),
441440
});
442441
return;
443442
}
444443

445-
if (!hasInstallTreeIssues && pluginConfigWarnings.length === 0) {
444+
if (!hasInstallTreeIssues && pluginConfigWarnings.size === 0) {
446445
defaultRuntime.log(
447446
"Plugin discovery, module loading, compatibility, and configuration checks passed. " +
448447
'Run "openclaw health" to check the running Gateway, including runtime quarantines and fallbacks.',
@@ -503,14 +502,14 @@ export async function runPluginsDoctorCommand(opts: PluginDoctorOptions = {}): P
503502
lines.push(`- ${formatPluginCompatibilityNotice(notice)} [${marker}]`);
504503
}
505504
}
506-
if (pluginConfigWarnings.length > 0) {
505+
if (pluginConfigWarnings.size > 0) {
507506
if (lines.length > 0) {
508507
lines.push("");
509508
}
510509
lines.push(theme.warn("Plugin configuration:"));
511510
lines.push(...pluginConfigWarnings);
512511
}
513-
if (!hasInstallTreeIssues && pluginConfigWarnings.length > 0) {
512+
if (!hasInstallTreeIssues && pluginConfigWarnings.size > 0) {
514513
if (lines.length > 0) {
515514
lines.push("");
516515
}

0 commit comments

Comments
 (0)