@@ -2864,6 +2864,89 @@ describe("ClineProvider", () => {
28642864 await provider . dispose ( )
28652865 } )
28662866
2867+ it ( "does not re-point a pinned sibling's task that follows another profile when its profile is deleted" , async ( ) => {
2868+ // Defensive: the doubles in this suite can leave console writes pending
2869+ // at worker teardown.
2870+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
2871+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
2872+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
2873+ const provider = new ClineProvider (
2874+ mockContext ,
2875+ mockOutputChannel ,
2876+ "sidebar" ,
2877+ new ContextProxy ( mockContext ) ,
2878+ new WebviewFocusTracker ( ) ,
2879+ )
2880+ const sibling = new ClineProvider (
2881+ mockContext ,
2882+ mockOutputChannel ,
2883+ "editor" ,
2884+ new ContextProxy ( mockContext ) ,
2885+ new WebviewFocusTracker ( ) ,
2886+ )
2887+ try {
2888+ const oldProfile : ProviderSettingsEntry = {
2889+ name : "old-profile" ,
2890+ id : "old-id" ,
2891+ apiProvider : providerIdentifiers . openrouter ,
2892+ }
2893+ const keeperProfile : ProviderSettingsEntry = {
2894+ name : "keeper-profile" ,
2895+ id : "keeper-id" ,
2896+ apiProvider : providerIdentifiers . anthropic ,
2897+ }
2898+ await provider . contextProxy . setValue ( "listApiConfigMeta" , [ oldProfile , keeperProfile ] )
2899+ await provider . contextProxy . setValue ( "currentApiConfigName" , "keeper-profile" )
2900+ // The sibling pins the profile being deleted, but its active task
2901+ // follows a different sticky profile: the deletion must re-point the
2902+ // sibling's buffer to the surviving profile without switching that
2903+ // conversation's handler or rewriting its persisted profile name.
2904+ sibling [ "viewLocalState" ] . currentApiConfigName = "old-profile"
2905+ sibling [ "viewLocalState" ] . apiConfiguration = {
2906+ apiProvider : providerIdentifiers . openrouter ,
2907+ openRouterApiKey : "deleted-profile-secret" ,
2908+ }
2909+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
2910+ const siblingTask = {
2911+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
2912+ taskApiConfigName : "other-profile" ,
2913+ taskId : "sibling-task" ,
2914+ setTaskApiConfigName : vi . fn ( ) ,
2915+ updateApiConfiguration : vi . fn ( ) ,
2916+ }
2917+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
2918+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
2919+ )
2920+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
2921+ vi . spyOn ( provider . providerSettingsManager , "getProfile" ) . mockResolvedValue ( {
2922+ name : "keeper-profile" ,
2923+ id : "keeper-id" ,
2924+ apiProvider : providerIdentifiers . anthropic ,
2925+ } )
2926+ vi . spyOn ( provider . providerSettingsManager , "deleteConfig" ) . mockResolvedValue ( undefined )
2927+
2928+ await provider . deleteProviderProfile ( oldProfile )
2929+
2930+ // The sibling's view buffer is still re-pointed to the surviving
2931+ // profile...
2932+ expect ( sibling [ "viewLocalState" ] . currentApiConfigName ) . toBe ( "keeper-profile" )
2933+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
2934+ id : "keeper-id" ,
2935+ apiProvider : providerIdentifiers . anthropic ,
2936+ } )
2937+ // ...but the task follows another profile: neither the handler rebuild
2938+ // nor the sticky-name rewrite may touch it.
2939+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
2940+ expect ( siblingTask . setTaskApiConfigName ) . not . toHaveBeenCalled ( )
2941+ // Let queued view-local persistence settle while the console spies are
2942+ // still installed, so teardown has no pending writes.
2943+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
2944+ } finally {
2945+ await sibling . dispose ( )
2946+ await provider . dispose ( )
2947+ }
2948+ } )
2949+
28672950 it ( "leaves the view buffer untouched when the deleted profile is neither globally active nor view-pinned" , async ( ) => {
28682951 const provider = new ClineProvider (
28692952 mockContext ,
0 commit comments