@@ -83,15 +83,16 @@ const state=process.env.AGENT_DEVICE_STATE_DIR || args[args.indexOf('--state-dir
8383const file=path.join(state,'daemon.json');
8484if(args[0]==='daemon') { const data=JSON.parse(fs.readFileSync(file,'utf8')); fs.writeFileSync(path.join(state,'stopped-agent'),String(data.pid)); try {process.kill(data.pid,'SIGTERM')} catch {} }
8585else if(args[0]==='serve') { const server=http.createServer((req,res)=>{res.statusCode=fs.existsSync(path.join(state,'unhealthy-agent-'+process.pid))?503:200;res.end('ok');}); server.listen(0,'127.0.0.1',()=>{fs.writeFileSync(file,JSON.stringify({httpPort:server.address().port,pid:process.pid,token:'test'}));process.send?.('ready');process.disconnect?.();}); }
86- else { const child=spawn(process.execPath,[process.argv[1],'serve'],{detached:true,stdio:['ignore','ignore','ignore','ipc'],env:process.env});await new Promise((resolve,reject)=>{child.once('message',resolve);child.once('error',reject);});child.unref(); }
86+ else { const child=spawn(process.execPath,[path.join(path.dirname( process.argv[1]),'daemon.mjs') ,'serve'],{detached:true,stdio:['ignore','ignore','ignore','ipc'],env:process.env});await new Promise((resolve,reject)=>{child.once('message',resolve);child.once('error',reject);});child.unref(); }
8787` ,
8888 ) ;
89+ await NodeFSP . copyFile ( agent , NodePath . join ( NodePath . dirname ( agent ) , "daemon.mjs" ) ) ;
8990 const nextHubVersion = DEVICE_HUB_VERSION + "-upgrade" ;
9091 const nextAgentVersion = AGENT_DEVICE_VERSION + "-upgrade" ;
9192 let invocation = 0 ;
9293 const invoke = async (
9394 owner : string ,
94- mode : "start" | "agent-start" | "stop-agent" | "stop" ,
95+ mode : "probe" | " start" | "agent-start" | "stop-agent" | "stop" ,
9596 upgraded = false ,
9697 ) => {
9798 const file = NodePath . join ( home , `${ owner } -${ mode } -${ invocation ++ } .cjs` ) ;
@@ -107,14 +108,19 @@ else { const child=spawn(process.execPath,[process.argv[1],'serve'],{detached:tr
107108 } ) ;
108109 return result . stdout ? JSON . parse ( result . stdout ) : null ;
109110 } ;
111+ const inventory = await invoke ( "one" , "probe" ) ;
112+ expect ( inventory . tools . hub . installedVersions ) . toEqual ( [ DEVICE_HUB_VERSION ] ) ;
113+ expect ( inventory . tools . hub . runningVersion ) . toBeNull ( ) ;
114+ expect ( inventory . tools . agent . installedVersions ) . toEqual ( [ AGENT_DEVICE_VERSION ] ) ;
115+ await expect ( NodeFSP . stat ( NodePath . join ( root , "hosts/one/hub.json" ) ) ) . rejects . toThrow ( ) ;
110116 const template = NodePath . join ( home , "hub-template" ) ;
111117 await NodeFSP . cp ( hubDir , template , { recursive : true } ) ;
112118 await NodeFSP . rm ( NodePath . join ( hubDir , ".install-complete" ) ) ;
113119 const installLock = hubDir + ".lock" ;
114120 await NodeFSP . symlink ( "2147483647:exited-installer" , installLock ) ;
115121 await NodeFSP . writeFile (
116122 NodePath . join ( bin , "npm" ) ,
117- `#!${ process . execPath } \nconst fs=require('node:fs');const args=process.argv.slice(2);fs.cpSync(${ JSON . stringify ( template ) } ,args[args.indexOf('--prefix')+1],{recursive:true});` ,
123+ `#!${ process . execPath } \nconst fs=require('node:fs');const args=process.argv.slice(2);if(args[0]==='--version'){console.log('10.0.0');process.exit(0);} fs.cpSync(${ JSON . stringify ( template ) } ,args[args.indexOf('--prefix')+1],{recursive:true});` ,
118124 { mode : 0o755 } ,
119125 ) ;
120126 await NodeFSP . mkdir ( NodePath . join ( root , "hosts/one" ) , { recursive : true } ) ;
@@ -135,6 +141,9 @@ else { const child=spawn(process.execPath,[process.argv[1],'serve'],{detached:tr
135141 ] ) ;
136142 expect ( concurrentAgent . hubPort ) . toBe ( first . hubPort ) ;
137143 expect ( concurrentAgent . daemonPort ) . toBe ( first . daemonPort ) ;
144+ const running = await invoke ( "one" , "probe" ) ;
145+ expect ( running . tools . hub . runningVersion ) . toBe ( DEVICE_HUB_VERSION ) ;
146+ expect ( running . tools . agent . runningVersion ) . toBe ( AGENT_DEVICE_VERSION ) ;
138147 const second = await invoke ( "two" , "agent-start" ) ;
139148 const reused = await invoke ( "one" , "agent-start" ) ;
140149 expect ( reused . hubPort ) . toBe ( first . hubPort ) ;
0 commit comments