Skip to content

Commit 8c5a12c

Browse files
authored
fix(plugins): surface discovery and stale registry diagnostics (#129091)
1 parent 041d48e commit 8c5a12c

2 files changed

Lines changed: 75 additions & 8 deletions

File tree

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,72 @@ describe("plugins cli list", () => {
105105
expect(output).toContain("Disabled plugin description");
106106
});
107107

108+
it.each([
109+
{ label: "default", args: [], visibleError: true },
110+
{ label: "verbose", args: ["--verbose"], visibleError: true },
111+
{ label: "enabled-only", args: ["--enabled"], visibleError: false },
112+
])(
113+
"surfaces plugin discovery and stale-registry diagnostics in the $label list",
114+
async ({ args, visibleError }) => {
115+
const refreshMessage =
116+
"Persisted plugin registry is stale. Run `openclaw plugins registry --refresh`.";
117+
const dependencyError = "Plugin dependency example-package could not be resolved.";
118+
buildPluginRegistrySnapshotReportMock.mockReturnValue({
119+
workspaceDir: "/workspace",
120+
registrySource: "derived",
121+
registryDiagnostics: [
122+
{
123+
level: "info",
124+
code: "persisted-registry-missing",
125+
message: "Persisted plugin registry is missing; using the derived index.",
126+
},
127+
{
128+
level: "warn",
129+
code: "persisted-registry-stale-source",
130+
message: refreshMessage,
131+
},
132+
],
133+
plugins: [
134+
createPluginRecord({ id: "healthy", description: "Healthy plugin" }),
135+
createPluginRecord({
136+
id: "broken",
137+
enabled: visibleError,
138+
status: "error",
139+
error: dependencyError,
140+
}),
141+
],
142+
diagnostics: [
143+
{ level: "warn", message: "Duplicate plugin ID shadows an installed plugin." },
144+
{ level: "error", message: "Plugin manifest could not be loaded." },
145+
{ level: "error", pluginId: "broken", message: dependencyError },
146+
],
147+
});
148+
149+
await runPluginsCommand(["plugins", "list", ...args]);
150+
151+
const output = pluginsCliRuntimeLogs.join("\n");
152+
expect(output).toContain("Warning: Duplicate plugin ID shadows an installed plugin.");
153+
expect(output).toContain("Error: Plugin manifest could not be loaded.");
154+
expect(output).toContain(`Warning: ${refreshMessage}`);
155+
expect(output).not.toContain("Persisted plugin registry is missing");
156+
expect(output.split(dependencyError)).toHaveLength(2);
157+
expect(output.includes(`Error: ${dependencyError}`)).toBe(!visibleError);
158+
},
159+
);
160+
108161
it("includes imported state in JSON output", async () => {
162+
const registryDiagnostics = [
163+
{
164+
level: "info",
165+
code: "persisted-registry-missing",
166+
message: "Persisted plugin registry is missing; using the derived index.",
167+
},
168+
];
169+
const diagnostics = [{ level: "warn", message: "Plugin discovery needs attention." }];
109170
buildPluginRegistrySnapshotReportMock.mockReturnValue({
110171
workspaceDir: "/workspace",
111172
registrySource: "persisted",
112-
registryDiagnostics: [],
173+
registryDiagnostics,
113174
plugins: [
114175
createPluginRecord({
115176
id: "demo",
@@ -118,7 +179,7 @@ describe("plugins cli list", () => {
118179
explicitlyEnabled: true,
119180
}),
120181
],
121-
diagnostics: [],
182+
diagnostics,
122183
});
123184

124185
await runPluginsCommand(["plugins", "list", "--json"]);
@@ -148,13 +209,13 @@ describe("plugins cli list", () => {
148209
};
149210
expect(output.workspaceDir).toBe("/workspace");
150211
expect(output.registry?.source).toBe("persisted");
151-
expect(output.registry?.diagnostics).toEqual([]);
212+
expect(output.registry?.diagnostics).toEqual(registryDiagnostics);
152213
expect(output.plugins).toHaveLength(1);
153214
expect(output.plugins?.[0]?.id).toBe("demo");
154215
expect(output.plugins?.[0]?.imported).toBe(true);
155216
expect(output.plugins?.[0]?.activated).toBe(true);
156217
expect(output.plugins?.[0]?.explicitlyEnabled).toBe(true);
157-
expect(output.diagnostics).toEqual([]);
218+
expect(output.diagnostics).toEqual(diagnostics);
158219
});
159220

160221
it("keeps doctor on a module-loading snapshot", async () => {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ export async function runPluginsListCommand(
7777
theme,
7878
} = await loadHumanListModules();
7979

80-
const workspaceScopeDiagnostic = report.diagnostics.find(
81-
(diagnostic) => diagnostic.code === "workspace-scope-omitted",
80+
const diagnostics = [...report.diagnostics, ...report.registryDiagnostics].filter(
81+
(diagnostic) =>
82+
diagnostic.level !== "info" &&
83+
(diagnostic.level !== "error" ||
84+
!list.some((plugin) => plugin.status === "error" && plugin.error === diagnostic.message)),
8285
);
83-
if (workspaceScopeDiagnostic) {
84-
runtime.log(theme.warn(`Warning: ${workspaceScopeDiagnostic.message}`));
86+
for (const { level, message } of diagnostics) {
87+
const format = level === "error" ? theme.error : theme.warn;
88+
runtime.log(format(`${level === "error" ? "Error" : "Warning"}: ${message}`));
89+
}
90+
if (diagnostics.length > 0) {
8591
runtime.log("");
8692
}
8793

0 commit comments

Comments
 (0)