@@ -3367,6 +3367,90 @@ describe("AcpAdapterV2", () => {
33673367 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
33683368 ) ;
33693369
3370+ it . live . each ( [ "cancelled" , "failed" , "end_turn" ] as const ) (
3371+ "closes unfinished ACP tools before a %s turn settles" ,
3372+ ( outcome ) =>
3373+ Effect . gen ( function * ( ) {
3374+ const path = yield * Path . Path ;
3375+ const instanceId = ProviderInstanceId . make ( "acp-unfinished-tool" ) ;
3376+ const threadId = ThreadId . make ( "thread-acp-unfinished-tool" ) ;
3377+ const adapter = yield * makeAcpAdapterV2 ( {
3378+ instanceId,
3379+ selfInvocation : yield * resolveSelfInvocation ( ) ,
3380+ flavor : {
3381+ driver : ACP_TEST_DRIVER ,
3382+ capabilities : AcpProviderCapabilitiesV2 ,
3383+ makeRuntime : makeMockRuntime ( {
3384+ childProcessSpawner : yield * ChildProcessSpawner . ChildProcessSpawner ,
3385+ mockAgentPath : yield * path . fromFileUrl (
3386+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
3387+ ) ,
3388+ environment : { T3_ACP_ACTIVE_TOOL_OUTCOME : outcome } ,
3389+ } ) ,
3390+ } ,
3391+ } ) ;
3392+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
3393+ runtimeMode : "full-access" ,
3394+ interactionMode : "default" ,
3395+ cwd : process . cwd ( ) ,
3396+ } ) ;
3397+ const modelSelection = { instanceId, model : "default" } as const ;
3398+ const runtime = yield * adapter . openSession ( {
3399+ threadId,
3400+ providerSessionId : ProviderSessionId . make ( "session-acp-unfinished-tool" ) ,
3401+ modelSelection,
3402+ runtimePolicy,
3403+ } ) ;
3404+ const providerThread = yield * runtime . ensureThread ( {
3405+ threadId,
3406+ modelSelection,
3407+ runtimePolicy,
3408+ } ) ;
3409+ yield * runtime . startTurn (
3410+ makeTurnInput ( {
3411+ threadId,
3412+ providerThread,
3413+ instanceId,
3414+ runtimePolicy,
3415+ now : yield * DateTime . now ,
3416+ } ) ,
3417+ ) ;
3418+ const events = yield * runtime . events . pipe (
3419+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
3420+ Stream . runCollect ,
3421+ ) ;
3422+ const toolUpdates = events . flatMap ( ( event ) =>
3423+ event . type === "turn_item.updated" &&
3424+ event . turnItem . nativeItemRef ?. nativeId === "tool-call-long-running-1"
3425+ ? [ event . turnItem ]
3426+ : [ ] ,
3427+ ) ;
3428+ const expectedStatus = outcome === "end_turn" ? "completed" : outcome ;
3429+ assert . include (
3430+ toolUpdates . map ( ( item ) => item . status ) ,
3431+ "running" ,
3432+ ) ;
3433+ const lastTool = toolUpdates . at ( - 1 ) ;
3434+ assert . equal ( lastTool ?. status , outcome === "cancelled" ? "interrupted" : expectedStatus ) ;
3435+ assert . isNotNull ( lastTool ?. completedAt ) ;
3436+ const lastWait = events . findLast (
3437+ ( event ) =>
3438+ event . type === "turn_item.updated" &&
3439+ event . turnItem . nativeItemRef ?. nativeId === "tool-call-pending-wait" ,
3440+ ) ;
3441+ assert . equal ( lastWait ?. type , "turn_item.updated" ) ;
3442+ if ( lastWait ?. type === "turn_item.updated" ) {
3443+ assert . equal ( lastWait . turnItem . type , "dynamic_tool" ) ;
3444+ assert . equal ( lastWait . turnItem . status , lastTool ?. status ) ;
3445+ assert . isNotNull ( lastWait . turnItem . completedAt ) ;
3446+ }
3447+ assert . equal (
3448+ events . find ( ( event ) => event . type === "turn.terminal" ) ?. status ,
3449+ expectedStatus ,
3450+ ) ;
3451+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
3452+ ) ;
3453+
33703454 it . live ( "terminalizes an empty successful foreground Bash tool when the turn completes" , ( ) =>
33713455 Effect . gen ( function * ( ) {
33723456 const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
0 commit comments