@@ -211,6 +211,33 @@ describe("cli json stdout contract", () => {
211211 message : "Use --agent or --all-agents, not both" ,
212212 tty : true ,
213213 } ,
214+ {
215+ name : "routed Gateway health config failure in JSON mode" ,
216+ args : [ "gateway" , "health" , "--port" , "29793" , "--json" ] ,
217+ message : "AUTOQA_ROUTE_CONFIG_READ_FAILURE" ,
218+ configReadFailure : true ,
219+ } ,
220+ {
221+ name : "Gateway health config failure in human mode" ,
222+ args : [ "gateway" , "health" , "--port" , "29793" ] ,
223+ message : "AUTOQA_ROUTE_CONFIG_READ_FAILURE" ,
224+ configReadFailure : true ,
225+ human : true ,
226+ } ,
227+ {
228+ name : "Gateway health config failure through forced Commander" ,
229+ args : [ "gateway" , "health" , "--port" , "29793" , "--json" ] ,
230+ message : "AUTOQA_ROUTE_CONFIG_READ_FAILURE" ,
231+ configReadFailure : true ,
232+ commander : true ,
233+ } ,
234+ {
235+ name : "routed Gateway health config failure with dual TTYs" ,
236+ args : [ "gateway" , "health" , "--port" , "29793" , "--json" ] ,
237+ message : "AUTOQA_ROUTE_CONFIG_READ_FAILURE" ,
238+ configReadFailure : true ,
239+ tty : true ,
240+ } ,
214241 {
215242 name : "specialized explicit Gateway authentication failure" ,
216243 args : [ "gateway" , "call" , "system-presence" , "--url" , "ws://127.0.0.1:29793" , "--json" ] ,
@@ -226,6 +253,18 @@ describe("cli json stdout contract", () => {
226253 [
227254 'import net from "node:net";' ,
228255 `net.Socket.prototype.connect = function () { throw new Error(${ JSON . stringify ( gatewayError ) } ); };` ,
256+ ...( "configReadFailure" in testCase
257+ ? [
258+ 'import fs from "node:fs";' ,
259+ "const originalExistsSync = fs.existsSync;" ,
260+ "fs.existsSync = function (target, ...args) {" ,
261+ ' if (String(target) === process.env.OPENCLAW_CONFIG_PATH && new Error().stack?.includes("readNonObservingHealthConfig")) {' ,
262+ ` throw new Error(${ JSON . stringify ( testCase . message ) } );` ,
263+ " }" ,
264+ " return originalExistsSync.call(this, target, ...args);" ,
265+ "};" ,
266+ ]
267+ : [ ] ) ,
229268 ...( "tty" in testCase
230269 ? [
231270 'Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });' ,
@@ -269,7 +308,11 @@ describe("cli json stdout contract", () => {
269308 ok : false ,
270309 error : { type : "cli_error" , message : testCase . message } ,
271310 } ) ;
272- expect ( result . stderr ) . not . toContain ( testCase . message ) ;
311+ if ( "configReadFailure" in testCase && ! ( "commander" in testCase ) ) {
312+ expect ( result . stderr ) . toContain ( testCase . message ) ;
313+ } else {
314+ expect ( result . stderr ) . not . toContain ( testCase . message ) ;
315+ }
273316 }
274317 if ( "tty" in testCase ) {
275318 expect ( result . stderr ) . toContain ( "\u001B[?25h" ) ;
0 commit comments