@@ -3469,6 +3469,89 @@ describe("ClineProvider", () => {
34693469 await provider . dispose ( )
34703470 } )
34713471
3472+ it ( "does not re-point a pinned sibling's task that follows another profile when its profile is deleted" , async ( ) => {
3473+ // Defensive: the doubles in this suite can leave console writes pending
3474+ // at worker teardown.
3475+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
3476+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
3477+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
3478+ const provider = new ClineProvider (
3479+ mockContext ,
3480+ mockOutputChannel ,
3481+ "sidebar" ,
3482+ new ContextProxy ( mockContext ) ,
3483+ new WebviewFocusTracker ( ) ,
3484+ )
3485+ const sibling = new ClineProvider (
3486+ mockContext ,
3487+ mockOutputChannel ,
3488+ "editor" ,
3489+ new ContextProxy ( mockContext ) ,
3490+ new WebviewFocusTracker ( ) ,
3491+ )
3492+ try {
3493+ const oldProfile : ProviderSettingsEntry = {
3494+ name : "old-profile" ,
3495+ id : "old-id" ,
3496+ apiProvider : providerIdentifiers . openrouter ,
3497+ }
3498+ const keeperProfile : ProviderSettingsEntry = {
3499+ name : "keeper-profile" ,
3500+ id : "keeper-id" ,
3501+ apiProvider : providerIdentifiers . anthropic ,
3502+ }
3503+ await provider . contextProxy . setValue ( "listApiConfigMeta" , [ oldProfile , keeperProfile ] )
3504+ await provider . contextProxy . setValue ( "currentApiConfigName" , "keeper-profile" )
3505+ // The sibling pins the profile being deleted, but its active task
3506+ // follows a different sticky profile: the deletion must re-point the
3507+ // sibling's buffer to the surviving profile without switching that
3508+ // conversation's handler or rewriting its persisted profile name.
3509+ sibling [ "viewLocalState" ] . currentApiConfigName = "old-profile"
3510+ sibling [ "viewLocalState" ] . apiConfiguration = {
3511+ apiProvider : providerIdentifiers . openrouter ,
3512+ openRouterApiKey : "deleted-profile-secret" ,
3513+ }
3514+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
3515+ const siblingTask = {
3516+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
3517+ taskApiConfigName : "other-profile" ,
3518+ taskId : "sibling-task" ,
3519+ setTaskApiConfigName : vi . fn ( ) ,
3520+ updateApiConfiguration : vi . fn ( ) ,
3521+ }
3522+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
3523+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
3524+ )
3525+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
3526+ vi . spyOn ( provider . providerSettingsManager , "getProfile" ) . mockResolvedValue ( {
3527+ name : "keeper-profile" ,
3528+ id : "keeper-id" ,
3529+ apiProvider : providerIdentifiers . anthropic ,
3530+ } )
3531+ vi . spyOn ( provider . providerSettingsManager , "deleteConfig" ) . mockResolvedValue ( undefined )
3532+
3533+ await provider . deleteProviderProfile ( oldProfile )
3534+
3535+ // The sibling's view buffer is still re-pointed to the surviving
3536+ // profile...
3537+ expect ( sibling [ "viewLocalState" ] . currentApiConfigName ) . toBe ( "keeper-profile" )
3538+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
3539+ id : "keeper-id" ,
3540+ apiProvider : providerIdentifiers . anthropic ,
3541+ } )
3542+ // ...but the task follows another profile: neither the handler rebuild
3543+ // nor the sticky-name rewrite may touch it.
3544+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
3545+ expect ( siblingTask . setTaskApiConfigName ) . not . toHaveBeenCalled ( )
3546+ // Let queued view-local persistence settle while the console spies are
3547+ // still installed, so teardown has no pending writes.
3548+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
3549+ } finally {
3550+ await sibling . dispose ( )
3551+ await provider . dispose ( )
3552+ }
3553+ } )
3554+
34723555 it ( "leaves the view buffer untouched when the deleted profile is neither globally active nor view-pinned" , async ( ) => {
34733556 const provider = new ClineProvider (
34743557 mockContext ,
0 commit comments