@@ -73,7 +73,7 @@ describe("remote helper lifecycle", () => {
7373 hub ,
7474 `import http from 'node:http'; import fs from 'node:fs';
7575if(fs.existsSync('fail-start-once')) {fs.unlinkSync('fail-start-once');process.exit(1);}
76- const args=process.argv.slice(2); http.createServer((req,res)=>{res.statusCode=fs.existsSync('unhealthy-'+process.pid)?503:200;res.end('ok');}).listen(Number(args[args.indexOf('--port')+1]),'127.0.0.1');` ,
76+ const args=process.argv.slice(2); fs.writeFileSync('hub-args.json',JSON.stringify(args)); http.createServer((req,res)=>{res.statusCode=fs.existsSync('unhealthy-'+process.pid)?503:200;res.end('ok');}).listen(Number(args[args.indexOf('--port')+1]),'127.0.0.1');` ,
7777 ) ;
7878 await NodeFSP . writeFile (
7979 agent ,
@@ -89,6 +89,12 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
8989 await NodeFSP . copyFile ( agent , NodePath . join ( NodePath . dirname ( agent ) , "daemon.mjs" ) ) ;
9090 const nextHubVersion = DEVICE_HUB_VERSION + "-upgrade" ;
9191 const nextAgentVersion = AGENT_DEVICE_VERSION + "-upgrade" ;
92+ // Each owner stands in for a host on a different platform.
93+ const hostPlatforms : Record < string , NodeJS . Platform > = { one : "linux" , two : "darwin" } ;
94+ const hubArgs = async ( owner : string ) : Promise < ReadonlyArray < string > > =>
95+ JSON . parse (
96+ await NodeFSP . readFile ( NodePath . join ( root , `hosts/${ owner } /hub-args.json` ) , "utf8" ) ,
97+ ) ;
9298 let invocation = 0 ;
9399 const invoke = async (
94100 owner : string ,
@@ -98,7 +104,8 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
98104 const file = NodePath . join ( home , `${ owner } -${ mode } -${ invocation ++ } .cjs` ) ;
99105 await NodeFSP . writeFile (
100106 file ,
101- `const originalKill = process.kill; process.kill = (pid, signal) => { if (signal === 'SIGTERM') require('node:fs').appendFileSync(${ JSON . stringify ( NodePath . join ( home , "stops" ) ) } , pid+'\\n'); return originalKill(pid, signal); };\n` +
107+ `Object.defineProperty(process, 'platform', { value: ${ JSON . stringify ( hostPlatforms [ owner ] ) } });\n` +
108+ `const originalKill = process.kill; process.kill = (pid, signal) => { if (signal === 'SIGTERM') require('node:fs').appendFileSync(${ JSON . stringify ( NodePath . join ( home , "stops" ) ) } , pid+'\\n'); return originalKill(pid, signal); };\n` +
102109 remoteDeviceScript ( owner , mode )
103110 . replace ( DEVICE_HUB_VERSION , upgraded ? nextHubVersion : DEVICE_HUB_VERSION )
104111 . replace ( AGENT_DEVICE_VERSION , upgraded ? nextAgentVersion : AGENT_DEVICE_VERSION ) ,
@@ -135,6 +142,19 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
135142 ] ) ;
136143 expect ( concurrent . hubPort ) . toBe ( manual . hubPort ) ;
137144 expect ( manual . daemonPort ) . toBeUndefined ( ) ;
145+ expect ( ( await hubArgs ( "one" ) ) . slice ( - 2 ) ) . toEqual ( [ "--platform" , "android" ] ) ;
146+ // A hub started before discovery was filtered has no recorded platform.
147+ const hubFile = NodePath . join ( root , "hosts/one/hub.json" ) ;
148+ const { platform : _platform , ...unfilteredHub } = JSON . parse (
149+ await NodeFSP . readFile ( hubFile , "utf8" ) ,
150+ ) ;
151+ await NodeFSP . writeFile ( hubFile , JSON . stringify ( unfilteredHub ) ) ;
152+ const filtered = await invoke ( "one" , "start" ) ;
153+ expect ( filtered . hubPort ) . not . toBe ( manual . hubPort ) ;
154+ expect ( await NodeFSP . readFile ( NodePath . join ( home , "stops" ) , "utf8" ) ) . toContain (
155+ `${ unfilteredHub . pid } \n` ,
156+ ) ;
157+ expect ( ( await invoke ( "one" , "start" ) ) . hubPort ) . toBe ( filtered . hubPort ) ;
138158 await expect (
139159 NodeFSP . stat ( NodePath . join ( root , "hosts/one/daemon.json" ) ) ,
140160 ) . rejects . toThrow ( ) ;
@@ -150,6 +170,8 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
150170 const second = await invoke ( "two" , "agent-start" ) ;
151171 const reused = await invoke ( "one" , "agent-start" ) ;
152172 expect ( reused . hubPort ) . toBe ( first . hubPort ) ;
173+ expect ( await hubArgs ( "two" ) ) . not . toContain ( "--platform" ) ;
174+ expect ( ( await invoke ( "two" , "start" ) ) . hubPort ) . toBe ( second . hubPort ) ;
153175 expect ( reused . daemonPort ) . toBe ( first . daemonPort ) ;
154176 expect ( second . hubPort ) . not . toBe ( first . hubPort ) ;
155177 expect ( second . daemonPort ) . not . toBe ( first . daemonPort ) ;
0 commit comments