@@ -2411,11 +2411,15 @@ describe("CopilotSdkAdapterV2", () => {
24112411 stdio : [ "ignore" , "pipe" , "ignore" ] ,
24122412 } ) ;
24132413 const exited = new Promise ( ( resolve ) => cli . once ( "exit" , resolve ) ) ;
2414+ let descendant : number | undefined ;
2415+ let verified = false ;
24142416 try {
2415- const descendant = Number (
2416- await new Promise < string > ( ( resolve ) =>
2417- cli . stdout . once ( "data" , ( chunk ) => resolve ( `${ chunk } ` ) ) ,
2418- ) ,
2417+ descendant = Number (
2418+ await new Promise < string > ( ( resolve , reject ) => {
2419+ cli . once ( "error" , reject ) ;
2420+ cli . stdout . once ( "data" , ( chunk ) => resolve ( `${ chunk } ` ) ) ;
2421+ cli . stdout . once ( "close" , ( ) => reject ( new Error ( "sh exited without a child pid" ) ) ) ;
2422+ } ) ,
24192423 ) ;
24202424 const tracked = copilotClientProcess ( { cliProcess : cli } ) ;
24212425 if ( ! tracked ) return assert . fail ( "Copilot's process is not tracked" ) ;
@@ -2429,8 +2433,14 @@ describe("CopilotSdkAdapterV2", () => {
24292433 ) . stdout . trim ( ) ;
24302434 // Killed: gone, or a zombie until whoever inherited it reaps it.
24312435 assert . isTrue ( state === "" || state . startsWith ( "Z" ) , `process ${ descendant } is ${ state } ` ) ;
2436+ verified = true ;
24322437 } finally {
24332438 cli . kill ( "SIGKILL" ) ;
2439+ // A failed kill must not leave the sleep behind, stopped and holding the pipe. After a
2440+ // verified kill its pid is free for reuse, so it is left alone.
2441+ if ( descendant !== undefined && ! verified ) {
2442+ NodeChildProcess . spawnSync ( "kill" , [ "-KILL" , String ( descendant ) ] ) ;
2443+ }
24342444 }
24352445 } ) ;
24362446 } ) . pipe ( Effect . provide ( testLayer ) ) ,
0 commit comments