@@ -1869,8 +1869,8 @@ describe("ClineProvider", () => {
18691869 const pruned = provider [ "prunePersistedViewStates" ] ( states )
18701870
18711871 expect ( Object . keys ( pruned ) ) . toHaveLength ( 50 )
1872- expect ( pruned [ "view-54" ] ) . toBeDefined ( )
1873- expect ( pruned [ "view-5" ] ) . toBeDefined ( )
1872+ expect ( pruned [ "view-54" ] ) . toEqual ( { mode : "mode-54" , updatedAt : 54 } )
1873+ expect ( pruned [ "view-5" ] ) . toEqual ( { mode : "mode-5" , updatedAt : 5 } )
18741874 expect ( pruned [ "view-4" ] ) . toBeUndefined ( )
18751875
18761876 await provider . dispose ( )
@@ -8292,6 +8292,7 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
82928292 // minimal double without the full provider/services graph.
82938293 const siblingTask = {
82948294 apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "old-key" } ,
8295+ taskApiConfigName : "saved-profile" ,
82958296 updateApiConfiguration : vi . fn ( ) ,
82968297 }
82978298 vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
@@ -8329,6 +8330,101 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
83298330 }
83308331 } )
83318332
8333+ it ( "does not rebuild a pinned sibling's task that runs under another profile" , async ( ) => {
8334+ // Defensive: the doubles in this suite can leave console writes pending
8335+ // at worker teardown.
8336+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
8337+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
8338+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
8339+ const sibling = new ClineProvider (
8340+ mockContext ,
8341+ mockOutputChannel ,
8342+ "editor" ,
8343+ new ContextProxy ( mockContext ) ,
8344+ new WebviewFocusTracker ( ) ,
8345+ )
8346+ try {
8347+ // The sibling pins the saved profile, but its active task follows a
8348+ // different sticky profile: the save must refresh the view overlay
8349+ // without switching that conversation to the saved profile's settings.
8350+ sibling [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
8351+ sibling [ "viewLocalState" ] . apiConfiguration = {
8352+ apiProvider : providerIdentifiers . anthropic ,
8353+ apiKey : "old-key" ,
8354+ }
8355+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
8356+
8357+ const siblingTask = {
8358+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
8359+ taskApiConfigName : "other-profile" ,
8360+ updateApiConfiguration : vi . fn ( ) ,
8361+ }
8362+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
8363+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
8364+ )
8365+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
8366+ // @ts -ignore - Replace providerSettingsManager with a test double.
8367+ provider . providerSettingsManager = {
8368+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
8369+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
8370+ setModeConfig : vi . fn ( ) ,
8371+ }
8372+
8373+ await provider . upsertProviderProfile (
8374+ "saved-profile" ,
8375+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
8376+ false ,
8377+ )
8378+
8379+ // The pinned view's overlay still catches up with the saved settings...
8380+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
8381+ apiProvider : providerIdentifiers . anthropic ,
8382+ apiKey : "new-key" ,
8383+ } )
8384+ // ...but the task runs under another profile: its handler must not be
8385+ // switched to the saved profile's settings.
8386+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
8387+ // Let queued view-local persistence settle while the console spies are
8388+ // still installed, so teardown has no pending writes.
8389+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
8390+ } finally {
8391+ await sibling . dispose ( )
8392+ }
8393+ } )
8394+
8395+ it ( "does not rebuild the acting view's task when it runs under another profile" , async ( ) => {
8396+ // The acting view pins the saved profile while its own task follows a
8397+ // different sticky profile: the non-activating save refreshes the view
8398+ // overlay but must leave the task's handler alone.
8399+ const task = {
8400+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
8401+ taskApiConfigName : "other-profile" ,
8402+ updateApiConfiguration : vi . fn ( ) ,
8403+ }
8404+ vi . spyOn ( provider , "getCurrentTask" ) . mockReturnValue (
8405+ task as unknown as ReturnType < typeof provider . getCurrentTask > ,
8406+ )
8407+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
8408+ provider [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
8409+ // @ts -ignore - Replace providerSettingsManager with a test double.
8410+ provider . providerSettingsManager = {
8411+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
8412+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
8413+ setModeConfig : vi . fn ( ) ,
8414+ }
8415+
8416+ await provider . upsertProviderProfile (
8417+ "saved-profile" ,
8418+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
8419+ false ,
8420+ )
8421+
8422+ expect ( provider [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
8423+ apiProvider : providerIdentifiers . anthropic ,
8424+ apiKey : "new-key" ,
8425+ } )
8426+ expect ( task . updateApiConfiguration ) . not . toHaveBeenCalled ( )
8427+ } )
83328428 it ( "does not leak shared provider keys into a pinned view's api configuration" , async ( ) => {
83338429 vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
83348430 vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
0 commit comments