@@ -4687,6 +4687,89 @@ describe("ClineProvider", () => {
46874687 await provider . dispose ( )
46884688 } )
46894689
4690+ it ( "does not re-point a pinned sibling's task that follows another profile when its profile is deleted" , async ( ) => {
4691+ // Defensive: the doubles in this suite can leave console writes pending
4692+ // at worker teardown.
4693+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
4694+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
4695+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
4696+ const provider = new ClineProvider (
4697+ mockContext ,
4698+ mockOutputChannel ,
4699+ "sidebar" ,
4700+ new ContextProxy ( mockContext ) ,
4701+ new WebviewFocusTracker ( ) ,
4702+ )
4703+ const sibling = new ClineProvider (
4704+ mockContext ,
4705+ mockOutputChannel ,
4706+ "editor" ,
4707+ new ContextProxy ( mockContext ) ,
4708+ new WebviewFocusTracker ( ) ,
4709+ )
4710+ try {
4711+ const oldProfile : ProviderSettingsEntry = {
4712+ name : "old-profile" ,
4713+ id : "old-id" ,
4714+ apiProvider : providerIdentifiers . openrouter ,
4715+ }
4716+ const keeperProfile : ProviderSettingsEntry = {
4717+ name : "keeper-profile" ,
4718+ id : "keeper-id" ,
4719+ apiProvider : providerIdentifiers . anthropic ,
4720+ }
4721+ await provider . contextProxy . setValue ( "listApiConfigMeta" , [ oldProfile , keeperProfile ] )
4722+ await provider . contextProxy . setValue ( "currentApiConfigName" , "keeper-profile" )
4723+ // The sibling pins the profile being deleted, but its active task
4724+ // follows a different sticky profile: the deletion must re-point the
4725+ // sibling's buffer to the surviving profile without switching that
4726+ // conversation's handler or rewriting its persisted profile name.
4727+ sibling [ "viewLocalState" ] . currentApiConfigName = "old-profile"
4728+ sibling [ "viewLocalState" ] . apiConfiguration = {
4729+ apiProvider : providerIdentifiers . openrouter ,
4730+ openRouterApiKey : "deleted-profile-secret" ,
4731+ }
4732+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
4733+ const siblingTask = {
4734+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
4735+ taskApiConfigName : "other-profile" ,
4736+ taskId : "sibling-task" ,
4737+ setTaskApiConfigName : vi . fn ( ) ,
4738+ updateApiConfiguration : vi . fn ( ) ,
4739+ }
4740+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
4741+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
4742+ )
4743+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
4744+ vi . spyOn ( provider . providerSettingsManager , "getProfile" ) . mockResolvedValue ( {
4745+ name : "keeper-profile" ,
4746+ id : "keeper-id" ,
4747+ apiProvider : providerIdentifiers . anthropic ,
4748+ } )
4749+ vi . spyOn ( provider . providerSettingsManager , "deleteConfig" ) . mockResolvedValue ( undefined )
4750+
4751+ await provider . deleteProviderProfile ( oldProfile )
4752+
4753+ // The sibling's view buffer is still re-pointed to the surviving
4754+ // profile...
4755+ expect ( sibling [ "viewLocalState" ] . currentApiConfigName ) . toBe ( "keeper-profile" )
4756+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
4757+ id : "keeper-id" ,
4758+ apiProvider : providerIdentifiers . anthropic ,
4759+ } )
4760+ // ...but the task follows another profile: neither the handler rebuild
4761+ // nor the sticky-name rewrite may touch it.
4762+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
4763+ expect ( siblingTask . setTaskApiConfigName ) . not . toHaveBeenCalled ( )
4764+ // Let queued view-local persistence settle while the console spies are
4765+ // still installed, so teardown has no pending writes.
4766+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
4767+ } finally {
4768+ await sibling . dispose ( )
4769+ await provider . dispose ( )
4770+ }
4771+ } )
4772+
46904773 it ( "leaves the view buffer untouched when the deleted profile is neither globally active nor view-pinned" , async ( ) => {
46914774 const provider = new ClineProvider (
46924775 mockContext ,
0 commit comments