@@ -17,7 +17,7 @@ import * as Fiber from "effect/Fiber";
1717import * as Scope from "effect/Scope" ;
1818import * as Result from "effect/Result" ;
1919import * as Stream from "effect/Stream" ;
20- import { ChildProcessSpawner } from "effect/process" ;
20+ import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
2121import { describe , expect } from "vite-plus/test" ;
2222
2323import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime" ;
@@ -297,6 +297,45 @@ describe("AcpSessionRuntime", () => {
297297 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
298298 ) ;
299299
300+ it . effect . each ( [ 0 , 1 ] ) ( "reuses Windows finalizer cleanup result %s before replacement" , ( code ) =>
301+ Effect . gen ( function * ( ) {
302+ const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
303+ let kills = 0 ;
304+ const runtime = yield * AcpSessionRuntime . make ( {
305+ ...mockRuntimeOptions ,
306+ ownDetachedProcessGroup : true ,
307+ processGroupPlatform : "win32" ,
308+ } ) . pipe (
309+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
310+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , {
311+ ...spawner ,
312+ spawn : ( command ) => {
313+ if ( ! ChildProcess . isStandardCommand ( command ) || command . command !== "taskkill" ) {
314+ return spawner . spawn ( command ) ;
315+ }
316+ return spawner . spawn (
317+ ChildProcess . make ( process . execPath , [
318+ "-e" ,
319+ `process.exit(${ kills ++ === 0 ? code : 128 } )` ,
320+ ] ) ,
321+ ) ;
322+ } ,
323+ } ) ,
324+ Effect . scoped ,
325+ ) ;
326+ expect ( kills ) . toBe ( 1 ) ;
327+ if ( runtime . terminateProcessGroup === undefined ) return expect . fail ( "Missing ACP teardown" ) ;
328+ if ( code === 0 ) yield * runtime . terminateProcessGroup ;
329+ else {
330+ expect ( yield * Effect . flip ( runtime . terminateProcessGroup ) ) . toMatchObject ( {
331+ _tag : "AcpProcessGroupTerminationError" ,
332+ exitCode : code ,
333+ } ) ;
334+ }
335+ expect ( kills ) . toBe ( 1 ) ;
336+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
337+ ) ;
338+
300339 it . effect . each ( [ "session/new" , "session/resume" ] as const ) (
301340 "buffers root metadata while %s startup is still pending" ,
302341 ( setupMethod ) =>
0 commit comments