@@ -178,6 +178,7 @@ test('metro companion worker proxies websocket frames to the local upstream serv
178178 const upstreamMessage = createDeferred < string > ( ) ;
179179 const bridgePong = createDeferred < void > ( ) ;
180180 const bridgeSocketReady = createDeferred < NodeJS . WritableStream > ( ) ;
181+ const registrationBody = createDeferred < Record < string , unknown > > ( ) ;
181182 const bridgeOpen = createDeferred < void > ( ) ;
182183 const bridgeFrame = createDeferred < string > ( ) ;
183184 const bridgeClose = createDeferred < CloseFrame > ( ) ;
@@ -233,8 +234,12 @@ test('metro companion worker proxies websocket frames to the local upstream serv
233234 const bridgeServer = http . createServer ( ( req , res ) => {
234235 const url = new URL ( req . url || '/' , 'http://127.0.0.1' ) ;
235236 if ( req . method === 'POST' && url . pathname === '/api/metro/companion/register' ) {
236- req . resume ( ) ;
237+ const chunks : Buffer [ ] = [ ] ;
238+ req . on ( 'data' , ( chunk ) => {
239+ chunks . push ( Buffer . isBuffer ( chunk ) ? chunk : Buffer . from ( chunk ) ) ;
240+ } ) ;
237241 req . on ( 'end' , ( ) => {
242+ registrationBody . resolve ( JSON . parse ( Buffer . concat ( chunks ) . toString ( 'utf8' ) ) ) ;
238243 res . writeHead ( 200 , { 'content-type' : 'application/json' } ) ;
239244 res . end (
240245 JSON . stringify ( {
@@ -325,6 +330,9 @@ test('metro companion worker proxies websocket frames to the local upstream serv
325330 AGENT_DEVICE_METRO_COMPANION_SERVER_BASE_URL : `http://127.0.0.1:${ bridgePort } ` ,
326331 AGENT_DEVICE_METRO_COMPANION_BEARER_TOKEN : 'test-token' ,
327332 AGENT_DEVICE_METRO_COMPANION_LOCAL_BASE_URL : `http://127.0.0.1:${ upstreamPort } ` ,
333+ AGENT_DEVICE_METRO_COMPANION_SCOPE_TENANT_ID : 'tenant-1' ,
334+ AGENT_DEVICE_METRO_COMPANION_SCOPE_RUN_ID : 'run-1' ,
335+ AGENT_DEVICE_METRO_COMPANION_SCOPE_LEASE_ID : 'lease-1' ,
328336 } ,
329337 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
330338 } ,
@@ -349,6 +357,12 @@ test('metro companion worker proxies websocket frames to the local upstream serv
349357 waitFor ( bridgeSocketReady . promise , 5_000 , 'bridge websocket connection' ) ,
350358 earlyExit ,
351359 ] ) ;
360+ assert . deepEqual ( await waitFor ( registrationBody . promise , 5_000 , 'companion registration' ) , {
361+ tenantId : 'tenant-1' ,
362+ runId : 'run-1' ,
363+ leaseId : 'lease-1' ,
364+ local_base_url : `http://127.0.0.1:${ upstreamPort } ` ,
365+ } ) ;
352366 await Promise . race ( [ waitFor ( bridgePong . promise , 5_000 , 'bridge pong' ) , earlyExit ] ) ;
353367 await Promise . race ( [ waitFor ( bridgeOpen . promise , 5_000 , 'bridge ws-open-result' ) , earlyExit ] ) ;
354368 bridgeSocket . write (
@@ -467,6 +481,9 @@ test('metro companion worker reconnects after the bridge closes immediately afte
467481 AGENT_DEVICE_METRO_COMPANION_SERVER_BASE_URL : `http://127.0.0.1:${ bridgePort } ` ,
468482 AGENT_DEVICE_METRO_COMPANION_BEARER_TOKEN : 'test-token' ,
469483 AGENT_DEVICE_METRO_COMPANION_LOCAL_BASE_URL : `http://127.0.0.1:${ localPort } ` ,
484+ AGENT_DEVICE_METRO_COMPANION_SCOPE_TENANT_ID : 'tenant-1' ,
485+ AGENT_DEVICE_METRO_COMPANION_SCOPE_RUN_ID : 'run-1' ,
486+ AGENT_DEVICE_METRO_COMPANION_SCOPE_LEASE_ID : 'lease-1' ,
470487 } ,
471488 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
472489 } ,
@@ -571,6 +588,9 @@ test('metro companion worker exits after its state file is removed', async () =>
571588 AGENT_DEVICE_METRO_COMPANION_SERVER_BASE_URL : `http://127.0.0.1:${ bridgePort } ` ,
572589 AGENT_DEVICE_METRO_COMPANION_BEARER_TOKEN : 'test-token' ,
573590 AGENT_DEVICE_METRO_COMPANION_LOCAL_BASE_URL : `http://127.0.0.1:${ localPort } ` ,
591+ AGENT_DEVICE_METRO_COMPANION_SCOPE_TENANT_ID : 'tenant-1' ,
592+ AGENT_DEVICE_METRO_COMPANION_SCOPE_RUN_ID : 'run-1' ,
593+ AGENT_DEVICE_METRO_COMPANION_SCOPE_LEASE_ID : 'lease-1' ,
574594 AGENT_DEVICE_METRO_COMPANION_STATE_PATH : statePath ,
575595 } ,
576596 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
@@ -615,6 +635,9 @@ test('metro companion worker exits immediately when its state file is already mi
615635 AGENT_DEVICE_METRO_COMPANION_SERVER_BASE_URL : 'http://127.0.0.1:1' ,
616636 AGENT_DEVICE_METRO_COMPANION_BEARER_TOKEN : 'test-token' ,
617637 AGENT_DEVICE_METRO_COMPANION_LOCAL_BASE_URL : 'http://127.0.0.1:1' ,
638+ AGENT_DEVICE_METRO_COMPANION_SCOPE_TENANT_ID : 'tenant-1' ,
639+ AGENT_DEVICE_METRO_COMPANION_SCOPE_RUN_ID : 'run-1' ,
640+ AGENT_DEVICE_METRO_COMPANION_SCOPE_LEASE_ID : 'lease-1' ,
618641 AGENT_DEVICE_METRO_COMPANION_STATE_PATH : statePath ,
619642 } ,
620643 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
0 commit comments