@@ -5,7 +5,7 @@ import type { HistoryItem } from "@roo-code/types"
55import { RooCodeEventName } from "@roo-code/types"
66import { ClineProvider } from "../core/webview/ClineProvider"
77import { TaskScheduler } from "../core/task/TaskScheduler"
8- import { bindRestoreParentOrReleasePermit } from "./helpers/provider-stub"
8+ import { bindDelegationMethods } from "./helpers/provider-stub"
99
1010const parentHistoryItem : HistoryItem = {
1111 id : "parent-1" ,
@@ -44,6 +44,18 @@ const makeParentTask = () =>
4444 } ) as any
4545
4646describe ( "ClineProvider.delegateParentAndOpenChild()" , ( ) => {
47+ it ( "forwards an explicit target task through the typed child mode-switch binder" , async ( ) => {
48+ const handleModeSwitch = vi . fn ( ) . mockResolvedValue ( undefined )
49+ const provider = { handleModeSwitch } as unknown as ClineProvider
50+ bindDelegationMethods ( provider )
51+ const targetTask = makeParentTask ( )
52+
53+ const snapshot = await provider . handleModeSwitchForChild ( "architect" , targetTask )
54+
55+ expect ( handleModeSwitch ) . toHaveBeenCalledWith ( "architect" , targetTask )
56+ expect ( snapshot ) . toMatchObject ( { mode : "architect" } )
57+ } )
58+
4759 it ( "persists parent delegation metadata via atomicReadAndUpdate and emits TaskDelegated" , async ( ) => {
4860 const providerEmit = vi . fn ( )
4961 const parentTask = makeParentTask ( )
@@ -66,6 +78,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
6678 recentTasksCache : undefined ,
6779 taskHistoryStore,
6880 } as unknown as ClineProvider
81+ bindDelegationMethods ( provider )
6982
7083 const child = await ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
7184 parentTaskId : "parent-1" ,
@@ -81,11 +94,22 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
8194 expect ( removeClineFromStack ) . toHaveBeenCalledTimes ( 1 )
8295
8396 // Child task created with startTask: false and initialStatus: "active"
84- expect ( createTask ) . toHaveBeenCalledWith ( "Do something" , undefined , parentTask , {
85- initialTodos : [ ] ,
86- initialStatus : "active" ,
87- startTask : false ,
88- } )
97+ expect ( createTask ) . toHaveBeenCalledWith (
98+ "Do something" ,
99+ undefined ,
100+ parentTask ,
101+ {
102+ initialTodos : [ ] ,
103+ initialStatus : "active" ,
104+ startTask : false ,
105+ } ,
106+ { } ,
107+ {
108+ apiConfiguration : { } ,
109+ mode : "code" ,
110+ apiConfigName : "default" ,
111+ } ,
112+ )
89113
90114 // Delegation metadata written via atomicReadAndUpdate with correct taskId
91115 expect ( taskHistoryStore . atomicReadAndUpdate ) . toHaveBeenCalledTimes ( 1 )
@@ -133,6 +157,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
133157 recentTasksCache : undefined ,
134158 taskHistoryStore,
135159 } as unknown as ClineProvider
160+ bindDelegationMethods ( provider )
136161
137162 await ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
138163 parentTaskId : "parent-1" ,
@@ -167,6 +192,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
167192 recentTasksCache : undefined ,
168193 taskHistoryStore,
169194 } as unknown as ClineProvider
195+ bindDelegationMethods ( provider )
170196
171197 await ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
172198 parentTaskId : "parent-1" ,
@@ -208,6 +234,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
208234 recentTasksCache : undefined ,
209235 taskHistoryStore,
210236 } as unknown as ClineProvider
237+ bindDelegationMethods ( provider )
211238
212239 await ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
213240 parentTaskId : "parent-1" ,
@@ -255,6 +282,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
255282 recentTasksCache : undefined ,
256283 taskHistoryStore,
257284 } as unknown as ClineProvider
285+ bindDelegationMethods ( provider )
258286
259287 await ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
260288 parentTaskId : "parent-1" ,
@@ -319,7 +347,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
319347 recentTasksCache : undefined ,
320348 taskHistoryStore,
321349 } as unknown as ClineProvider
322- bindRestoreParentOrReleasePermit ( provider )
350+ bindDelegationMethods ( provider )
323351
324352 await expect (
325353 ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
@@ -375,7 +403,7 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
375403 // still needs evicting, independent of current focus.
376404 taskRegistry : { getById : vi . fn ( ( id : string ) => ( id === "child-1" ? child : undefined ) ) } ,
377405 } as unknown as ClineProvider
378- bindRestoreParentOrReleasePermit ( provider )
406+ bindDelegationMethods ( provider )
379407
380408 await expect (
381409 ( ClineProvider . prototype as any ) . delegateParentAndOpenChild . call ( provider , {
0 commit comments