@@ -41,11 +41,14 @@ function run(command, args, options = {}) {
4141 let stdout = '' ; let stderr = '' ; let internal = '' ;
4242 child . stdout ?. on ( 'data' , ( chunk ) => { stdout += chunk ; } ) ; child . stderr ?. on ( 'data' , ( chunk ) => { stderr += chunk ; } ) ;
4343 child . stdio [ 4 ] ?. on ( 'data' , ( chunk ) => { internal += chunk ; } ) ;
44+ child . stdio [ 3 ] ?. on ( 'error' , consumePipeError ) ; child . stdio [ 4 ] ?. on ( 'error' , consumePipeError ) ;
4445 /** @type {import('node:stream').Writable } */ ( child . stdio [ 3 ] ) . end ( options . rawInput ?? `${ JSON . stringify ( options . input ?? { } ) } \n` ) ;
4546 child . once ( 'error' , reject ) ; child . once ( 'exit' , ( code ) => resolvePromise ( { code, stdout, stderr, internal } ) ) ;
4647 } ) ;
4748}
4849
50+ function consumePipeError ( ) { }
51+
4952/** @param {any } context @param {string[] } args @param {NodeJS.ProcessEnv } [extraEnv] @param {Record<string,unknown> } [authorization] */
5053async function companion ( context , args , extraEnv = { } , authorization = { callerContext : context . caller } ) {
5154 const result = await run ( process . execPath , [ cli , ...args ] , { cwd : context . workspace , env : { ...context . env , ...extraEnv } , input : authorization } ) ;
@@ -141,7 +144,7 @@ test('caller authorization is absent from the running process command line and p
141144 const context = await fixture ( ) ; const reserved = await companion ( context , [ 'review' , '--background' ] ) ;
142145 const caller = await context . identity . createCallerContext ( { sessionId : 'codex-session' , turnId : 'turn-ps' , workspace : context . workspace , permissionMode : 'workspace-write' } ) ;
143146 const child = spawn ( process . execPath , [ cli , 'status' , reserved . json . job . id , '--wait' , '--timeout-ms' , '500' ] , { cwd : context . workspace , env : context . env , stdio : [ 'ignore' , 'pipe' , 'pipe' , 'pipe' , 'pipe' ] , shell : false } ) ;
144- let stdout = '' ; let stderr = '' ; let internal = '' ; child . stdout ?. on ( 'data' , ( chunk ) => { stdout += chunk ; } ) ; child . stderr ?. on ( 'data' , ( chunk ) => { stderr += chunk ; } ) ; child . stdio [ 4 ] ?. on ( 'data' , ( chunk ) => { internal += chunk ; } ) ; /** @type {import('node:stream').Writable } */ ( child . stdio [ 3 ] ) . end ( `${ JSON . stringify ( { callerContext : caller } ) } \n` ) ;
147+ let stdout = '' ; let stderr = '' ; let internal = '' ; child . stdout ?. on ( 'data' , ( chunk ) => { stdout += chunk ; } ) ; child . stderr ?. on ( 'data' , ( chunk ) => { stderr += chunk ; } ) ; child . stdio [ 3 ] ?. on ( 'error' , consumePipeError ) ; child . stdio [ 4 ] ?. on ( 'error' , consumePipeError ) ; child . stdio [ 4 ] ?. on ( 'data' , ( chunk ) => { internal += chunk ; } ) ; /** @type {import('node:stream').Writable } */ ( child . stdio [ 3 ] ) . end ( `${ JSON . stringify ( { callerContext : caller } ) } \n` ) ;
145148 const inspected = await run ( 'ps' , [ '-p' , String ( child . pid ) , '-o' , 'command=' ] ) ;
146149 assert . equal ( inspected . code , 0 ) ; assert . doesNotMatch ( inspected . stdout , new RegExp ( caller ) ) ;
147150 const code = await new Promise ( ( resolvePromise , reject ) => { child . once ( 'error' , reject ) ; child . once ( 'exit' , resolvePromise ) ; } ) ;
0 commit comments