11// Plugins CLI list tests cover plugin listing output and installed-state formatting.
22import { 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" ;
48import { createPluginRecord } from "../plugins/status.test-fixtures.js" ;
59import { withEnvAsync } from "../test-utils/env.js" ;
610import {
@@ -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+
3066vi . 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 ( {
0 commit comments