@@ -490,6 +490,72 @@ describe("gateway-backed CLI process exit", () => {
490490 } ,
491491 ) ;
492492
493+ it . runIf ( process . platform !== "win32" ) (
494+ "runs gateway status through one OpenClaw entry process" ,
495+ async ( ) => {
496+ const root = tempDirs . make ( "openclaw-gateway-status-entry-process-" ) ;
497+ const stateDir = path . join ( root , "state" ) ;
498+ const configPath = path . join ( stateDir , "openclaw.json" ) ;
499+ const pidLogPath = path . join ( root , "entry-pids" ) ;
500+ const preloadPath = path . join ( root , "track-entry-pid.mjs" ) ;
501+ const token = "configured-token" ;
502+ const gateway = await startGatewayStabilityRpcServer ( token , "issued-device-token" ) ;
503+ await fs . mkdir ( stateDir , { recursive : true } ) ;
504+ await fs . writeFile (
505+ configPath ,
506+ JSON . stringify ( { gateway : { mode : "remote" , remote : { url : gateway . url , token } } } ) ,
507+ ) ;
508+ await fs . writeFile (
509+ preloadPath ,
510+ [
511+ 'import fs from "node:fs";' ,
512+ 'const entry = process.argv[1]?.replaceAll("\\\\", "/");' ,
513+ 'if (entry?.endsWith("/src/entry.ts")) {' ,
514+ " fs.appendFileSync(process.env.OPENCLAW_ENTRY_PID_LOG, `${process.pid}\\n`);" ,
515+ "}" ,
516+ "" ,
517+ ] . join ( "\n" ) ,
518+ ) ;
519+
520+ const result = await runIsolatedGatewayCli ( {
521+ args : [
522+ "gateway" ,
523+ "status" ,
524+ "--url" ,
525+ gateway . url ,
526+ "--token" ,
527+ token ,
528+ "--require-rpc" ,
529+ "--json" ,
530+ "--timeout" ,
531+ "2000" ,
532+ ] ,
533+ root,
534+ stateDir,
535+ configPath,
536+ env : {
537+ NODE_OPTIONS : `--import=${ pathToFileURL ( preloadPath ) . href } ` ,
538+ OPENCLAW_ENTRY_PID_LOG : pidLogPath ,
539+ OPENCLAW_NODE_EXTRA_CA_CERTS_READY : "1" ,
540+ OPENCLAW_NODE_OPTIONS_READY : undefined ,
541+ OPENCLAW_NO_RESPAWN : undefined ,
542+ } ,
543+ } ) ;
544+
545+ expect ( result , result . stderr ) . toMatchObject ( { code : 0 , signal : null , stderr : "" } ) ;
546+ expect ( JSON . parse ( result . stdout ) ) . toMatchObject ( {
547+ rpc : { ok : true , kind : "read" } ,
548+ } ) ;
549+ const entryPids = new Set (
550+ ( await fs . readFile ( pidLogPath , "utf8" ) )
551+ . trim ( )
552+ . split ( / \s + / u)
553+ . map ( ( value ) => Number . parseInt ( value , 10 ) ) ,
554+ ) ;
555+ expect ( entryPids . size ) . toBe ( 1 ) ;
556+ } ,
557+ ) ;
558+
493559 it . each ( [
494560 { label : "list" , args : [ "devices" , "list" , "--timeout" , "250" ] } ,
495561 { label : "join-code" , args : [ "devices" , "join-code" , "--timeout" , "250" ] } ,
0 commit comments