@@ -474,6 +474,74 @@ describe("cli json stdout contract", () => {
474474 ) ;
475475 } ) ;
476476
477+ it . each ( [
478+ {
479+ name : "the search query is missing" ,
480+ args : [ "plugins" , "search" , "--json" ] ,
481+ message : "Usage: openclaw plugins search <query>" ,
482+ } ,
483+ {
484+ name : "ClawHub transport fails" ,
485+ args : [ "plugins" , "search" , "fixture" , "--json" ] ,
486+ message : "offline fixture" ,
487+ } ,
488+ ] ) ( "returns one canonical JSON document when plugins $name" , async ( testCase ) => {
489+ await withTempHome (
490+ async ( tempHome ) => {
491+ const preload = `data:text/javascript,${ encodeURIComponent (
492+ 'globalThis.fetch = async () => { throw new Error("offline fixture"); };' ,
493+ ) } `;
494+ const result = runBuiltCli ( tempHome , testCase . args , {
495+ NODE_OPTIONS : `--import=${ preload } ` ,
496+ OPENCLAW_STATE_DIR : path . join ( tempHome , "isolated-state" ) ,
497+ OPENCLAW_CONFIG_PATH : path . join ( tempHome , "missing-openclaw.json" ) ,
498+ CLAWHUB_CONFIG_PATH : path . join ( tempHome , "missing-clawhub.json" ) ,
499+ CLAWHUB_TOKEN : "" ,
500+ CLAWHUB_AUTH_TOKEN : "" ,
501+ } ) ;
502+
503+ expect ( result . status , result . stderr ) . toBe ( 1 ) ;
504+ expect ( result . stdout , result . stderr ) . not . toBe ( "" ) ;
505+ expect ( result . stdout ) . not . toMatch ( / [ \u001B \u0007 ] / u) ;
506+ expect ( JSON . parse ( result . stdout ) ) . toEqual ( {
507+ ok : false ,
508+ error : {
509+ type : "cli_error" ,
510+ message : testCase . message ,
511+ } ,
512+ } ) ;
513+ expect ( result . stderr ) . toContain ( testCase . message ) ;
514+ } ,
515+ { prefix : "openclaw-plugins-json-failure-e2e-" } ,
516+ ) ;
517+ } ) ;
518+
519+ it ( "keeps plugins search JSON failures clean through dual-TTY finalization" , async ( ) => {
520+ await withTempHome (
521+ async ( tempHome ) => {
522+ const preload = `data:text/javascript,${ encodeURIComponent (
523+ 'Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true }); Object.defineProperty(process.stderr, "isTTY", { value: true, configurable: true });' ,
524+ ) } `;
525+ const result = runBuiltCli ( tempHome , [ "plugins" , "search" , "--json" ] , {
526+ NODE_OPTIONS : `--import=${ preload } ` ,
527+ } ) ;
528+
529+ expect ( result . status , result . stderr ) . toBe ( 1 ) ;
530+ expect ( JSON . parse ( result . stdout ) ) . toEqual ( {
531+ ok : false ,
532+ error : {
533+ type : "cli_error" ,
534+ message : "Usage: openclaw plugins search <query>" ,
535+ } ,
536+ } ) ;
537+ expect ( result . stdout ) . not . toMatch ( / [ \u001B \u0007 ] / u) ;
538+ expect ( result . stderr ) . toContain ( "Usage: openclaw plugins search <query>" ) ;
539+ expect ( result . stderr ) . toContain ( "\u001B[?25h" ) ;
540+ } ,
541+ { prefix : "openclaw-plugins-json-tty-failure-e2e-" } ,
542+ ) ;
543+ } ) ;
544+
477545 it . each ( [
478546 {
479547 name : "search with a leaf JSON flag" ,
0 commit comments