@@ -159,6 +159,65 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
159159 } else expect ( records . has ( "child-1" ) ) . toBe ( false )
160160 } )
161161
162+ it ( "releases the parent and rethrows the cancellation when the committed child was deleted" , async ( ) => {
163+ const parent = makeParentTask ( )
164+ const child = {
165+ taskId : "child-1" ,
166+ abort : false ,
167+ abandoned : false ,
168+ run : vi . fn ( ) ,
169+ dispose : vi . fn ( ) . mockResolvedValue ( undefined ) ,
170+ }
171+ let current : { taskId : string } | undefined = parent
172+ const records = new Map < string , HistoryItem > ( [ [ "parent-1" , { ...parentHistoryItem , status : "interrupted" } ] ] )
173+ const store = {
174+ invalidate : vi . fn ( ) . mockResolvedValue ( undefined ) ,
175+ get : ( id : string ) => records . get ( id ) ,
176+ atomicReadAndUpdate : vi . fn ( async ( id : string , update : ( item : HistoryItem ) => HistoryItem ) => {
177+ const item = records . get ( id )
178+ if ( ! item ) throw new Error ( `missing ${ id } ` )
179+ records . set ( id , update ( item ) )
180+ if ( id === "parent-1" ) child . abort = true
181+ return [ ...records . values ( ) ]
182+ } ) ,
183+ }
184+ const provider = makeProviderStub ( {
185+ taskHistoryStore : store ,
186+ taskScheduler : { schedule : vi . fn ( ) } ,
187+ createTask : vi . fn ( async ( ) => {
188+ current = child
189+ records . set ( child . taskId , {
190+ ...parentHistoryItem ,
191+ id : child . taskId ,
192+ status : "active" ,
193+ parentTaskId : "parent-1" ,
194+ } )
195+ return child
196+ } ) ,
197+ createTaskWithHistoryItem : vi . fn ( ) ,
198+ getCurrentTask : ( ) => current ,
199+ isViewLaunched : true ,
200+ emit : vi . fn ( ) ,
201+ postMessageToWebview : vi . fn ( ) ,
202+ deleteTaskWithId : vi . fn ( ) ,
203+ // A concurrent deleteTaskWithId removes the child while the handoff unwinds.
204+ removeClineFromStack : vi . fn ( async ( ) => {
205+ if ( current === child ) records . delete ( child . taskId )
206+ current = undefined
207+ } ) ,
208+ } )
209+
210+ await expect (
211+ ClineProvider . prototype . delegateParentAndOpenChild . call ( provider , {
212+ parentTaskId : "parent-1" ,
213+ message : "Child" ,
214+ initialTodos : [ ] ,
215+ mode : "code" ,
216+ } ) ,
217+ ) . rejects . toThrow ( / c a n c e l l e d / )
218+ expect ( records . get ( "parent-1" ) ) . toMatchObject ( { status : "active" , awaitingChildId : undefined } )
219+ } )
220+
162221 it ( "stops before delegation when refreshing the interrupted task's owner fails" , async ( ) => {
163222 const parentTask = makeParentTask ( )
164223 const historyItem : HistoryItem = {
0 commit comments