@@ -25,6 +25,7 @@ import * as Crypto from "effect/Crypto";
2525import * as Effect from "effect/Effect" ;
2626import * as Layer from "effect/Layer" ;
2727import * as Option from "effect/Option" ;
28+ import * as Result from "effect/Result" ;
2829import * as SubscriptionRef from "effect/SubscriptionRef" ;
2930
3031import {
@@ -44,6 +45,7 @@ import {
4445 editQueuedRun ,
4546 forkThreadFromRun ,
4647 interruptThreadTurn ,
48+ interruptSubagent ,
4749 mergeThreadBack ,
4850 promoteQueuedRun ,
4951 reorderActiveThread ,
@@ -78,6 +80,7 @@ const makeSupervisor = Effect.fn("TestEnvironmentCommands.makeSupervisor")(funct
7880 readonly projection ?: OrchestrationV2ThreadProjection ;
7981 readonly projectionRequests ?: ThreadId [ ] ;
8082 readonly advertiseServerResolvedCommandContext ?: boolean ;
83+ readonly subagentInterrupt ?: boolean ;
8184} ) {
8285 const client = {
8386 [ ORCHESTRATION_V2_WS_METHODS . dispatchCommand ] : ( command : OrchestrationV2Command ) =>
@@ -125,6 +128,9 @@ const makeSupervisor = Effect.fn("TestEnvironmentCommands.makeSupervisor")(funct
125128 environment : {
126129 capabilities : {
127130 repositoryIdentity : true ,
131+ ...( input . subagentInterrupt === undefined
132+ ? { }
133+ : { subagentInterrupt : input . subagentInterrupt } ) ,
128134 ...( input . advertiseServerResolvedCommandContext === false
129135 ? { }
130136 : { serverResolvedCommandContext : true } ) ,
@@ -148,6 +154,35 @@ const makeSupervisor = Effect.fn("TestEnvironmentCommands.makeSupervisor")(funct
148154} ) ;
149155
150156describe ( "V2 environment commands" , ( ) => {
157+ it . effect . each ( [ undefined , false , true ] ) (
158+ "dispatches a subagent interrupt only when support is advertised as %s" ,
159+ ( supported ) =>
160+ Effect . gen ( function * ( ) {
161+ const commands : OrchestrationV2Command [ ] = [ ] ;
162+ const supervisor = yield * makeSupervisor ( {
163+ commands,
164+ projects : [ ] ,
165+ ...( supported === undefined ? { } : { subagentInterrupt : supported } ) ,
166+ } ) ;
167+ const commandId = CommandId . make ( "subagent-interrupt" ) ;
168+ const subagentId = NodeId . make ( "subagent-1" ) ;
169+ const result = yield * interruptSubagent ( {
170+ commandId,
171+ threadId : v2ThreadId ,
172+ subagentId,
173+ } ) . pipe (
174+ Effect . provideService ( EnvironmentSupervisor . EnvironmentSupervisor , supervisor ) ,
175+ Effect . result ,
176+ ) ;
177+ expect ( Result . isSuccess ( result ) ) . toBe ( supported === true ) ;
178+ expect ( commands ) . toEqual (
179+ supported === true
180+ ? [ { type : "subagent.interrupt" , commandId, threadId : v2ThreadId , subagentId } ]
181+ : [ ] ,
182+ ) ;
183+ } ) . pipe ( Effect . provide ( TEST_CRYPTO_LAYER ) ) ,
184+ ) ;
185+
151186 it . effect ( "routes projects through the event-sourced project transport" , ( ) =>
152187 Effect . gen ( function * ( ) {
153188 const projects : ProjectMutation [ ] = [ ] ;
0 commit comments