Skip to content

Commit 9df65f0

Browse files
committed
fix(plugins): surface setup-required install warnings
1 parent 9386ac0 commit 9df65f0

5 files changed

Lines changed: 51 additions & 43 deletions

File tree

‎src/auto-reply/reply/commands-plugins.install.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ describe("handleCommands /plugins install", () => {
749749
it("includes non-blocking ClawHub warnings in successful chat install replies", async () => {
750750
const warning =
751751
'ClawHub trust warning for "@openclaw/[email protected]": scan=pending; reasons=pending.';
752+
const setupWarning =
753+
'Installed plugin "clawhub-demo" without enabling it because it requires configuration first. Configure it, then run `openclaw plugins enable clawhub-demo`.';
752754
const richWarning = `\u001b[33m${warning}\u001b[39m`;
753755
installPluginFromClawHubMock.mockImplementation(async (params: unknown) => {
754756
if (!params || typeof params !== "object" || !("logger" in params)) {
@@ -783,7 +785,12 @@ describe("handleCommands /plugins install", () => {
783785
},
784786
};
785787
});
786-
persistPluginInstallMock.mockResolvedValue({});
788+
persistPluginInstallMock.mockImplementation(
789+
async (params: { persistenceLogger?: { warn?: (message: string) => void } }) => {
790+
params.persistenceLogger?.warn?.(setupWarning);
791+
return { plugins: { entries: { "clawhub-demo": { enabled: false } } } };
792+
},
793+
);
787794

788795
await withTempHome("openclaw-command-plugins-home-", async () => {
789796
const workspaceDir = await workspaceHarness.createWorkspace();
@@ -797,6 +804,7 @@ describe("handleCommands /plugins install", () => {
797804
}
798805
expect(result.reply?.text).toContain('Installed plugin "clawhub-demo"');
799806
expect(result.reply?.text).toContain(warning);
807+
expect(result.reply?.text).toContain(setupWarning);
800808
expect(result.reply?.text).not.toContain("\u001b");
801809
expect(mockFirstObjectArg(installPluginFromClawHubMock).logger).toEqual(
802810
expect.objectContaining({ terminalLinks: false }),

‎src/plugins/install-persistence.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,7 @@ export async function persistPluginInstall(params: {
488488
const runtime = params.runtime ?? defaultRuntime;
489489
// Terminal diagnostics may contain paths/errors; management receives only producer-authored summaries.
490490
const warn = (message: string, managementMessage: string): void => {
491-
if (params.persistenceLogger?.warn) {
492-
params.persistenceLogger.warn(managementMessage);
493-
return;
494-
}
491+
params.persistenceLogger?.warn?.(managementMessage);
495492
runtime.log(theme.warn(message));
496493
};
497494
const installRecords = await tracePluginLifecyclePhaseAsync(

‎src/plugins/install-persistence.warning-sink.test.ts‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ describe("plugin install persistence warning audiences", () => {
6161
expect(warn).toHaveBeenCalledExactlyOnceWith(
6262
'Installed plugin "workboard" without enabling it because it requires configuration first. Configure it, then run `openclaw plugins enable workboard`.',
6363
);
64-
expect(pluginsCliRuntimeLogs).toEqual([
65-
"Installed plugin: workboard",
66-
"Restart the gateway to load plugins.",
67-
]);
64+
expect(pluginsCliRuntimeLogs.join("\n")).toContain("requires configuration first");
65+
expect(pluginsCliRuntimeLogs).toContain("Installed plugin: workboard");
66+
expect(pluginsCliRuntimeLogs).toContain("Restart the gateway to load plugins.");
6867
});
6968

7069
it("preserves owner-authored exclusive-slot warnings verbatim", async () => {
@@ -149,25 +148,20 @@ describe("plugin install persistence warning audiences", () => {
149148

150149
if (audience === "terminal") {
151150
expect(warn).not.toHaveBeenCalled();
152-
expect(pluginsCliRuntimeLogs.join("\n")).toContain(cleanupDetail);
153-
expect(pluginsCliRuntimeLogs.join("\n")).toContain(refreshDetail);
154-
expect(pluginsCliRuntimeLogs.join("\n")).toContain(configuredSource);
155-
expect(pluginsCliRuntimeLogs.join("\n")).toContain(install.installPath);
156-
return;
151+
} else {
152+
const warnings = warn.mock.calls.map(([message]) => String(message));
153+
expect(warnings).toHaveLength(3);
154+
expect(warnings.join("\n")).toContain("previous plugin installation");
155+
expect(warnings.join("\n")).toContain("registry");
156+
expect(warnings.join("\n")).toContain("shadowed");
157+
expect(warnings.join("\n")).not.toContain("/private/");
158+
expect(warnings.join("\n")).not.toContain("PRIVATE_NPM_MARKER");
159+
expect(warnings.join("\n")).not.toContain("PRIVATE_REFRESH_MARKER");
157160
}
158-
159-
const warnings = warn.mock.calls.map(([message]) => String(message));
160-
expect(warnings).toHaveLength(3);
161-
expect(warnings.join("\n")).toContain("previous plugin installation");
162-
expect(warnings.join("\n")).toContain("registry");
163-
expect(warnings.join("\n")).toContain("shadowed");
164-
expect(warnings.join("\n")).not.toContain("/private/");
165-
expect(warnings.join("\n")).not.toContain("PRIVATE_NPM_MARKER");
166-
expect(warnings.join("\n")).not.toContain("PRIVATE_REFRESH_MARKER");
167-
expect(pluginsCliRuntimeLogs).toEqual([
168-
"Installed plugin: workboard",
169-
"Restart the gateway to load plugins.",
170-
]);
161+
expect(pluginsCliRuntimeLogs.join("\n")).toContain(cleanupDetail);
162+
expect(pluginsCliRuntimeLogs.join("\n")).toContain(refreshDetail);
163+
expect(pluginsCliRuntimeLogs.join("\n")).toContain(configuredSource);
164+
expect(pluginsCliRuntimeLogs.join("\n")).toContain(install.installPath);
171165
},
172166
);
173167
});

‎src/plugins/management-service.registry-refresh.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,27 @@ describe("plugin management registry refresh", () => {
240240
);
241241
});
242242

243-
it("does not forward source-install loggers into private persistence warnings", async () => {
243+
it("returns persistence warnings without forwarding them to source-install loggers", async () => {
244244
mockClawHubWorkboardInstall();
245-
mocks.persistInstall.mockResolvedValue({});
245+
const instruction =
246+
'Installed plugin "workboard" without enabling it because it requires configuration first.';
247+
mocks.persistInstall.mockImplementation(
248+
async (params: { persistenceLogger?: { warn?: (message: string) => void } }) => {
249+
params.persistenceLogger?.warn?.(instruction);
250+
return {};
251+
},
252+
);
246253
const logger = { warn: vi.fn() };
247254

248-
await installManagedPluginSource({
255+
const result = await installManagedPluginSource({
249256
request: { source: "clawhub", spec: "clawhub:community/workboard" },
250257
snapshot: installSnapshot,
251258
env: {},
252259
logger,
253260
});
254261

255262
expect(mocks.clawhubInstall).toHaveBeenCalledWith(expect.objectContaining({ logger }));
256-
expect(mocks.persistInstall.mock.calls[0]?.[0]).not.toHaveProperty("persistenceLogger");
257263
expect(logger.warn).not.toHaveBeenCalled();
264+
expect(result).toMatchObject({ ok: true, warnings: [instruction] });
258265
});
259266
});

‎src/plugins/management-service.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,28 +1104,28 @@ async function persistManagedSourceInstall(params: {
11041104
extensionsDir: string;
11051105
invalidateRuntimeCache?: boolean;
11061106
runtime?: RuntimeEnv;
1107-
persistenceLogger?: PluginInstallLogger;
11081107
successMessage?: string;
11091108
cleanupOnPersistenceFailure?: boolean;
1110-
}): Promise<OpenClawConfig> {
1109+
}): Promise<{ config: OpenClawConfig; warnings: string[] }> {
1110+
const warnings: string[] = [];
11111111
const persist = () =>
11121112
persistPluginInstall({
11131113
snapshot: params.snapshot,
11141114
pluginId: params.pluginId,
11151115
install: params.install,
11161116
invalidateRuntimeCache: params.invalidateRuntimeCache,
11171117
runtime: params.runtime,
1118-
...(params.persistenceLogger ? { persistenceLogger: params.persistenceLogger } : {}),
1118+
persistenceLogger: { warn: (message) => warnings.push(message) },
11191119
...(params.successMessage ? { successMessage: params.successMessage } : {}),
11201120
});
11211121
if (!params.cleanupOnPersistenceFailure) {
1122-
return await persist();
1122+
return { config: await persist(), warnings };
11231123
}
11241124
try {
1125-
return await persist();
1125+
return { config: await persist(), warnings };
11261126
} catch (error) {
1127-
const warnings = await cleanupFailedManagedPluginInstall(params);
1128-
return throwPersistenceFailureWithCleanupWarnings(error, warnings);
1127+
const cleanupWarnings = await cleanupFailedManagedPluginInstall(params);
1128+
return throwPersistenceFailureWithCleanupWarnings(error, cleanupWarnings);
11291129
}
11301130
}
11311131

@@ -1135,8 +1135,6 @@ export async function installManagedPluginSource(params: {
11351135
snapshot: ConfigSnapshotForInstallPersist;
11361136
env?: NodeJS.ProcessEnv;
11371137
logger?: PluginInstallLogger & { terminalLinks?: boolean };
1138-
// Source loggers can feed chat replies; management diagnostics require explicit private opt-in.
1139-
persistenceLogger?: PluginInstallLogger;
11401138
safetyOverrides?: InstallSafetyOverrides;
11411139
runtime?: RuntimeEnv;
11421140
invalidateRuntimeCache?: boolean;
@@ -1198,7 +1196,7 @@ export async function installManagedPluginSource(params: {
11981196
request.source === "local" && request.link
11991197
? false
12001198
: (params.cleanupOnPersistenceFailure ?? true);
1201-
const config = await persistManagedSourceInstall({
1199+
const persisted = await persistManagedSourceInstall({
12021200
...params,
12031201
cleanupOnPersistenceFailure,
12041202
env,
@@ -1209,7 +1207,11 @@ export async function installManagedPluginSource(params: {
12091207
extensionsDir,
12101208
successMessage: completed.successMessage,
12111209
});
1212-
return { ...installed, config };
1210+
return {
1211+
...installed,
1212+
config: persisted.config,
1213+
...(persisted.warnings.length > 0 ? { warnings: [...new Set(persisted.warnings)] } : {}),
1214+
};
12131215
};
12141216

12151217
if (request.source === "local") {
@@ -1449,14 +1451,14 @@ export async function installManagedPlugin(params: {
14491451
snapshot,
14501452
env,
14511453
logger: installLogger,
1452-
persistenceLogger: installLogger,
14531454
cleanupOnPersistenceFailure: true,
14541455
invalidateRuntimeCache: false,
14551456
runtime: createSilentRuntime(),
14561457
});
14571458
if (!installed.ok) {
14581459
return throwInstallFailure(installed);
14591460
}
1461+
warnings.push(...(installed.warnings ?? []));
14601462
const workspace = resolvePluginControlPlaneWorkspace({ config: installed.config, env });
14611463
if (workspace.diagnostic) {
14621464
warnings.push(workspace.diagnostic.message);

0 commit comments

Comments
 (0)