@@ -135,6 +135,42 @@ describe("runSubagentAnnounceDispatch", () => {
135135 ] ) ;
136136 } ) ;
137137
138+ it ( "preserves direct failure when completion dispatch aborts before fallback queue" , async ( ) => {
139+ const controller = new AbortController ( ) ;
140+ const queue = vi . fn ( async ( ) => "queued" as const ) ;
141+ const direct = vi . fn ( async ( ) => {
142+ controller . abort ( ) ;
143+ return {
144+ delivered : false ,
145+ path : "direct" as const ,
146+ error : "direct failed before abort" ,
147+ } ;
148+ } ) ;
149+
150+ const result = await runSubagentAnnounceDispatch ( {
151+ expectsCompletionMessage : true ,
152+ signal : controller . signal ,
153+ queue,
154+ direct,
155+ } ) ;
156+
157+ expect ( direct ) . toHaveBeenCalledTimes ( 1 ) ;
158+ expect ( queue ) . not . toHaveBeenCalled ( ) ;
159+ expect ( result ) . toMatchObject ( {
160+ delivered : false ,
161+ path : "direct" ,
162+ error : "direct failed before abort" ,
163+ } ) ;
164+ expect ( result . phases ) . toEqual ( [
165+ {
166+ phase : "direct-primary" ,
167+ delivered : false ,
168+ path : "direct" ,
169+ error : "direct failed before abort" ,
170+ } ,
171+ ] ) ;
172+ } ) ;
173+
138174 it ( "returns none immediately when signal is already aborted" , async ( ) => {
139175 const queue = vi . fn ( async ( ) => "none" as const ) ;
140176 const direct = vi . fn ( async ( ) => ( { delivered : true , path : "direct" as const } ) ) ;
0 commit comments