@@ -64,7 +64,7 @@ describe("advanceSubtaskQueue", () => {
6464 getCurrentTask : vi . fn ( ) . mockReturnValue ( { taskId : "child-1" } ) ,
6565 removeClineFromStack : vi . fn ( ) . mockResolvedValue ( undefined ) ,
6666 getTaskWithId : vi . fn ( ) . mockResolvedValue ( {
67- historyItem : makeHistoryItem ( { id : "child-1" , status : "active" } ) ,
67+ historyItem : makeHistoryItem ( { id : "child-1" , mode : "code" , status : "active" } ) ,
6868 } ) ,
6969 updateTaskHistory : vi . fn ( ) . mockResolvedValue ( undefined ) ,
7070 handleModeSwitch : vi . fn ( ) . mockResolvedValue ( undefined ) ,
@@ -73,6 +73,8 @@ describe("advanceSubtaskQueue", () => {
7373 log : vi . fn ( ) ,
7474 }
7575
76+ // Queue items represent ADDITIONAL subtasks after the initial child.
77+ // subtaskQueueIndex=0 means queue[0] is the next to dispatch.
7678 const subtaskQueue : SubtaskQueueItem [ ] = [
7779 { mode : "code" , message : "Step 1" } ,
7880 { mode : "debug" , message : "Step 2" } ,
@@ -88,7 +90,7 @@ describe("advanceSubtaskQueue", () => {
8890 const result = await ( ClineProvider . prototype as any ) . advanceSubtaskQueue . call ( provider , {
8991 parentTaskId : "parent-1" ,
9092 childTaskId : "child-1" ,
91- completionResultSummary : "Step 1 done" ,
93+ completionResultSummary : "Initial task done" ,
9294 historyItem,
9395 } )
9496
@@ -102,11 +104,11 @@ describe("advanceSubtaskQueue", () => {
102104 expect . objectContaining ( { id : "child-1" , status : "completed" } ) ,
103105 )
104106
105- // Should have switched mode to next subtask 's mode
106- expect ( provider . handleModeSwitch ) . toHaveBeenCalledWith ( "debug " )
107+ // Should have switched mode to queue[0] 's mode (the next item to dispatch)
108+ expect ( provider . handleModeSwitch ) . toHaveBeenCalledWith ( "code " )
107109
108- // Should have created the next child with the queued message
109- expect ( provider . createTask ) . toHaveBeenCalledWith ( "Step 2 " , undefined , undefined , {
110+ // Should have created the next child with queue[0]'s message
111+ expect ( provider . createTask ) . toHaveBeenCalledWith ( "Step 1 " , undefined , undefined , {
110112 initialTodos : [ ] ,
111113 initialStatus : "active" ,
112114 startTask : false ,
@@ -115,12 +117,13 @@ describe("advanceSubtaskQueue", () => {
115117 // Should have started the next child
116118 expect ( mockChild . start ) . toHaveBeenCalled ( )
117119
118- // Should have updated parent with advanced queue index
120+ // Should have updated parent with advanced queue index (0 -> 1)
121+ // completedMode comes from child's history (mode: "code")
119122 expect ( provider . updateTaskHistory ) . toHaveBeenCalledWith (
120123 expect . objectContaining ( {
121124 id : "parent-1" ,
122125 subtaskQueueIndex : 1 ,
123- subtaskResults : [ { taskId : "child-1" , mode : "unknown " , summary : "Step 1 done" } ] ,
126+ subtaskResults : [ { taskId : "child-1" , mode : "code " , summary : "Initial task done" } ] ,
124127 awaitingChildId : "child-2" ,
125128 delegatedToId : "child-2" ,
126129 } ) ,
@@ -131,7 +134,7 @@ describe("advanceSubtaskQueue", () => {
131134 RooCodeEventName . TaskDelegationCompleted ,
132135 "parent-1" ,
133136 "child-1" ,
134- "Step 1 done" ,
137+ "Initial task done" ,
135138 )
136139 expect ( emitSpy ) . toHaveBeenCalledWith ( RooCodeEventName . TaskDelegated , "parent-1" , "child-2" )
137140 } )
@@ -141,7 +144,7 @@ describe("advanceSubtaskQueue", () => {
141144 getCurrentTask : vi . fn ( ) . mockReturnValue ( { taskId : "child-2" } ) ,
142145 removeClineFromStack : vi . fn ( ) . mockResolvedValue ( undefined ) ,
143146 getTaskWithId : vi . fn ( ) . mockResolvedValue ( {
144- historyItem : makeHistoryItem ( { id : "child-2" , status : "active" } ) ,
147+ historyItem : makeHistoryItem ( { id : "child-2" , mode : "code" , status : "active" } ) ,
145148 } ) ,
146149 updateTaskHistory : vi . fn ( ) . mockResolvedValue ( undefined ) ,
147150 handleModeSwitch : vi . fn ( ) ,
@@ -151,11 +154,13 @@ describe("advanceSubtaskQueue", () => {
151154 formatAggregatedQueueResults : ( ClineProvider . prototype as any ) . formatAggregatedQueueResults ,
152155 }
153156
157+ // Queue has 1 item, subtaskQueueIndex=1 means queue[0] was already dispatched.
158+ // Now that child completes and the queue is exhausted.
154159 const subtaskQueue : SubtaskQueueItem [ ] = [ { mode : "code" , message : "Step 1" } ]
155160
156161 const historyItem = makeHistoryItem ( {
157162 subtaskQueue,
158- subtaskQueueIndex : 0 ,
163+ subtaskQueueIndex : 1 ,
159164 subtaskResults : [ { taskId : "child-1" , mode : "code" , summary : "Step 1 done" } ] ,
160165 childIds : [ "child-1" , "child-2" ] ,
161166 } )
0 commit comments