@@ -2335,4 +2335,38 @@ describe("CopilotSdkAdapterV2", () => {
23352335 vi . useRealTimers ( ) ;
23362336 }
23372337 } ) ;
2338+
2339+ it . live ( "kills the processes under a live Copilot CLI on Linux and macOS" , ( ) =>
2340+ Effect . gen ( function * ( ) {
2341+ // Signals and ps are POSIX; Windows goes through taskkill /T, covered above.
2342+ if ( ( yield * HostProcess . Platform ) === "win32" ) return ;
2343+ yield * Effect . promise ( async ( ) => {
2344+ const cli = NodeChildProcess . spawn ( "sh" , [ "-c" , "sleep 300 & echo $!; wait" ] , {
2345+ stdio : [ "ignore" , "pipe" , "ignore" ] ,
2346+ } ) ;
2347+ const exited = new Promise ( ( resolve ) => cli . once ( "exit" , resolve ) ) ;
2348+ try {
2349+ const descendant = Number (
2350+ await new Promise < string > ( ( resolve ) =>
2351+ cli . stdout . once ( "data" , ( chunk ) => resolve ( `${ chunk } ` ) ) ,
2352+ ) ,
2353+ ) ;
2354+ const tracked = copilotClientProcess ( { cliProcess : cli } ) ;
2355+ if ( ! tracked ) return assert . fail ( "Copilot's process is not tracked" ) ;
2356+ assert . isUndefined ( await tracked . killDescendants ( ) ) ;
2357+ cli . kill ( "SIGKILL" ) ;
2358+ await exited ;
2359+ const state = NodeChildProcess . spawnSync (
2360+ "ps" ,
2361+ [ "-o" , "stat=" , "-p" , String ( descendant ) ] ,
2362+ { encoding : "utf8" } ,
2363+ ) . stdout . trim ( ) ;
2364+ // Killed: gone, or a zombie until whoever inherited it reaps it.
2365+ assert . isTrue ( state === "" || state . startsWith ( "Z" ) , `process ${ descendant } is ${ state } ` ) ;
2366+ } finally {
2367+ cli . kill ( "SIGKILL" ) ;
2368+ }
2369+ } ) ;
2370+ } ) . pipe ( Effect . provide ( testLayer ) ) ,
2371+ ) ;
23382372} ) ;
0 commit comments