@@ -3577,12 +3577,18 @@ describe("AcpAdapterV2", () => {
35773577 ) ;
35783578
35793579 it . effect . each ( [
3580- { name : "wrapped text" , imageOnly : false , matches : true } ,
3581- { name : "image-only input" , imageOnly : true , matches : true } ,
3582- { name : "an unmatched message" , imageOnly : false , matches : false } ,
3580+ { name : "wrapped text" , imageOnly : false , matches : true , stateOnlyWake : false } ,
3581+ { name : "image-only input" , imageOnly : true , matches : true , stateOnlyWake : false } ,
3582+ { name : "an unmatched message" , imageOnly : false , matches : false , stateOnlyWake : false } ,
3583+ {
3584+ name : "a state-only pre-acceptance wake" ,
3585+ imageOnly : false ,
3586+ matches : true ,
3587+ stateOnlyWake : true ,
3588+ } ,
35833589 ] ) (
35843590 "handles Copilot acceptance for $name without a spurious continuation" ,
3585- ( { imageOnly, matches } ) =>
3591+ ( { imageOnly, matches, stateOnlyWake } ) =>
35863592 Effect . gen ( function * ( ) {
35873593 const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
35883594 const path = yield * Path . Path ;
@@ -3696,6 +3702,10 @@ describe("AcpAdapterV2", () => {
36963702 } ,
36973703 } ) ;
36983704 yield * Deferred . await ( dispatched ) ;
3705+ if ( stateOnlyWake ) {
3706+ yield * event ! ( { sessionId : "mock-session-1" , type : "assistant.turn_start" } ) ;
3707+ yield * event ! ( { sessionId : "mock-session-1" , type : "assistant.idle" } ) ;
3708+ }
36993709 yield * event ! ( {
37003710 sessionId : "mock-session-1" ,
37013711 type : "user.message" ,
@@ -3734,16 +3744,49 @@ describe("AcpAdapterV2", () => {
37343744 ) ;
37353745
37363746 it . effect . each ( [
3737- { scenario : "a late lost-session error" , accepted : true , wake : false , restart : true } ,
3747+ {
3748+ scenario : "a late lost-session error" ,
3749+ accepted : true ,
3750+ wake : false ,
3751+ restart : true ,
3752+ stop : false ,
3753+ } ,
37383754 {
37393755 scenario : "a rejected prompt with a buffered wake" ,
37403756 accepted : false ,
3741- wake : true ,
3757+ wake : "output" ,
37423758 restart : false ,
3759+ stop : false ,
37433760 } ,
3744- { scenario : "a rejected prompt without a wake" , accepted : false , wake : false , restart : false } ,
3745- { scenario : "a lost runtime with a buffered wake" , accepted : false , wake : true , restart : true } ,
3746- ] ) ( "handles a Copilot prompt failure with $scenario" , ( { accepted, wake, restart } ) =>
3761+ {
3762+ scenario : "a rejected prompt without a wake" ,
3763+ accepted : false ,
3764+ wake : false ,
3765+ restart : false ,
3766+ stop : false ,
3767+ } ,
3768+ {
3769+ scenario : "a lost runtime with a buffered wake" ,
3770+ accepted : false ,
3771+ wake : "output" ,
3772+ restart : true ,
3773+ stop : false ,
3774+ } ,
3775+ {
3776+ scenario : "a state-only buffered wake" ,
3777+ accepted : false ,
3778+ wake : "state" ,
3779+ restart : false ,
3780+ stop : false ,
3781+ } ,
3782+ {
3783+ scenario : "a prompt rejected during Stop close" ,
3784+ accepted : false ,
3785+ wake : "output" ,
3786+ restart : false ,
3787+ stop : true ,
3788+ } ,
3789+ ] ) ( "handles a Copilot prompt failure with $scenario" , ( { accepted, wake, restart, stop } ) =>
37473790 Effect . gen ( function * ( ) {
37483791 const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
37493792 const path = yield * Path . Path ;
@@ -3800,9 +3843,26 @@ describe("AcpAdapterV2", () => {
38003843 runtime . start ( ) . pipe (
38013844 Effect . map ( ( setup ) => ( {
38023845 ...setup ,
3803- initializeResult : { ...setup . initializeResult , protocolVersion : 1 } ,
3846+ initializeResult : {
3847+ ...setup . initializeResult ,
3848+ protocolVersion : 1 ,
3849+ agentCapabilities : {
3850+ ...setup . initializeResult . agentCapabilities ,
3851+ sessionCapabilities : { close : { } } ,
3852+ } ,
3853+ } ,
38043854 } ) ) ,
38053855 ) ,
3856+ closeSession : ( ) =>
3857+ stop
3858+ ? Deferred . fail (
3859+ response ,
3860+ new EffectAcpErrors . AcpRequestError ( {
3861+ code : - 32800 ,
3862+ errorMessage : "cancelled before insertion" ,
3863+ } ) ,
3864+ ) . pipe ( Effect . andThen ( Deferred . await ( failed ) ) , Effect . as ( { } ) )
3865+ : runtime . closeSession ( ) ,
38063866 handleSessionUpdate : ( handler ) =>
38073867 Effect . sync ( ( ) => {
38083868 sessionUpdate = handler ;
@@ -3850,28 +3910,40 @@ describe("AcpAdapterV2", () => {
38503910 }
38513911 if ( wake ) {
38523912 yield * update ! ( { sessionId : "mock-session-1" , state : "running" } ) ;
3853- yield * sessionUpdate ! ( {
3854- sessionId : "mock-session-1" ,
3855- update : {
3856- sessionUpdate : "agent_message_chunk" ,
3857- content : { type : "text" , text : "buffered wake output" } ,
3858- } ,
3859- } ) ;
3913+ if ( wake === "output" )
3914+ yield * sessionUpdate ! ( {
3915+ sessionId : "mock-session-1" ,
3916+ update : {
3917+ sessionUpdate : "agent_message_chunk" ,
3918+ content : { type : "text" , text : "buffered wake output" } ,
3919+ } ,
3920+ } ) ;
38603921 yield * update ! ( { sessionId : "mock-session-1" , state : "idle" } ) ;
38613922 }
38623923 assert . deepEqual ( offered , [ ] , "a wake must remain buffered before acceptance" ) ;
3863- yield * Deferred . fail (
3864- response ,
3865- new EffectAcpErrors . AcpRequestError ( { code : - 32603 , errorMessage : "lost session" } ) ,
3866- ) ;
3924+ if ( stop ) {
3925+ const snapshot = yield * runtime . readThreadSnapshot ( { providerThread } ) ;
3926+ const running = snapshot . providerTurns . at ( - 1 ) ;
3927+ if ( running === undefined ) return yield * Effect . die ( "missing running turn" ) ;
3928+ yield * runtime . interruptTurn ( {
3929+ providerThread,
3930+ providerTurnId : running . id ,
3931+ requestRuntimeRestart : true ,
3932+ } ) ;
3933+ } else {
3934+ yield * Deferred . fail (
3935+ response ,
3936+ new EffectAcpErrors . AcpRequestError ( { code : - 32603 , errorMessage : "lost session" } ) ,
3937+ ) ;
3938+ }
38673939 yield * Deferred . await ( failed ) ;
3868- const shouldContinue = wake && ! restart ;
3940+ const shouldContinue = wake === "output" && ! restart && ! stop ;
38693941 assert . deepEqual (
38703942 offered ,
38713943 shouldContinue ? [ { threadId, providerThreadId : providerThread . id } ] : [ ] ,
38723944 "only a surviving runtime's buffered wake can continue after rejection" ,
38733945 ) ;
3874- if ( ! restart ) {
3946+ if ( ! restart && ! stop ) {
38753947 const failedSnapshot = yield * runtime . readThreadSnapshot ( { providerThread } ) ;
38763948 assert . equal ( failedSnapshot . providerTurns . at ( - 1 ) ?. status , "failed" ) ;
38773949 }
@@ -3887,7 +3959,7 @@ describe("AcpAdapterV2", () => {
38873959 : { } ) ,
38883960 } ) ;
38893961 yield * runtime . startTurn ( next ) ;
3890- assert . equal ( runtimeCount , restart ? 2 : 1 ) ;
3962+ assert . equal ( runtimeCount , restart || stop ? 2 : 1 ) ;
38913963 if ( shouldContinue ) {
38923964 const snapshot = yield * runtime . readThreadSnapshot ( { providerThread } ) ;
38933965 assert . equal ( snapshot . providerTurns . at ( - 1 ) ?. status , "completed" ) ;
0 commit comments