@@ -3094,6 +3094,89 @@ describe("ClineProvider", () => {
30943094 await provider . dispose ( )
30953095 } )
30963096
3097+ it ( "does not re-point a pinned sibling's task that follows another profile when its profile is deleted" , async ( ) => {
3098+ // Defensive: the doubles in this suite can leave console writes pending
3099+ // at worker teardown.
3100+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
3101+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
3102+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
3103+ const provider = new ClineProvider (
3104+ mockContext ,
3105+ mockOutputChannel ,
3106+ "sidebar" ,
3107+ new ContextProxy ( mockContext ) ,
3108+ new WebviewFocusTracker ( ) ,
3109+ )
3110+ const sibling = new ClineProvider (
3111+ mockContext ,
3112+ mockOutputChannel ,
3113+ "editor" ,
3114+ new ContextProxy ( mockContext ) ,
3115+ new WebviewFocusTracker ( ) ,
3116+ )
3117+ try {
3118+ const oldProfile : ProviderSettingsEntry = {
3119+ name : "old-profile" ,
3120+ id : "old-id" ,
3121+ apiProvider : providerIdentifiers . openrouter ,
3122+ }
3123+ const keeperProfile : ProviderSettingsEntry = {
3124+ name : "keeper-profile" ,
3125+ id : "keeper-id" ,
3126+ apiProvider : providerIdentifiers . anthropic ,
3127+ }
3128+ await provider . contextProxy . setValue ( "listApiConfigMeta" , [ oldProfile , keeperProfile ] )
3129+ await provider . contextProxy . setValue ( "currentApiConfigName" , "keeper-profile" )
3130+ // The sibling pins the profile being deleted, but its active task
3131+ // follows a different sticky profile: the deletion must re-point the
3132+ // sibling's buffer to the surviving profile without switching that
3133+ // conversation's handler or rewriting its persisted profile name.
3134+ sibling [ "viewLocalState" ] . currentApiConfigName = "old-profile"
3135+ sibling [ "viewLocalState" ] . apiConfiguration = {
3136+ apiProvider : providerIdentifiers . openrouter ,
3137+ openRouterApiKey : "deleted-profile-secret" ,
3138+ }
3139+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
3140+ const siblingTask = {
3141+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
3142+ taskApiConfigName : "other-profile" ,
3143+ taskId : "sibling-task" ,
3144+ setTaskApiConfigName : vi . fn ( ) ,
3145+ updateApiConfiguration : vi . fn ( ) ,
3146+ }
3147+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
3148+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
3149+ )
3150+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
3151+ vi . spyOn ( provider . providerSettingsManager , "getProfile" ) . mockResolvedValue ( {
3152+ name : "keeper-profile" ,
3153+ id : "keeper-id" ,
3154+ apiProvider : providerIdentifiers . anthropic ,
3155+ } )
3156+ vi . spyOn ( provider . providerSettingsManager , "deleteConfig" ) . mockResolvedValue ( undefined )
3157+
3158+ await provider . deleteProviderProfile ( oldProfile )
3159+
3160+ // The sibling's view buffer is still re-pointed to the surviving
3161+ // profile...
3162+ expect ( sibling [ "viewLocalState" ] . currentApiConfigName ) . toBe ( "keeper-profile" )
3163+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
3164+ id : "keeper-id" ,
3165+ apiProvider : providerIdentifiers . anthropic ,
3166+ } )
3167+ // ...but the task follows another profile: neither the handler rebuild
3168+ // nor the sticky-name rewrite may touch it.
3169+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
3170+ expect ( siblingTask . setTaskApiConfigName ) . not . toHaveBeenCalled ( )
3171+ // Let queued view-local persistence settle while the console spies are
3172+ // still installed, so teardown has no pending writes.
3173+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
3174+ } finally {
3175+ await sibling . dispose ( )
3176+ await provider . dispose ( )
3177+ }
3178+ } )
3179+
30973180 it ( "leaves the view buffer untouched when the deleted profile is neither globally active nor view-pinned" , async ( ) => {
30983181 const provider = new ClineProvider (
30993182 mockContext ,
0 commit comments