@@ -1977,8 +1977,8 @@ describe("ClineProvider", () => {
19771977 const pruned = provider [ "prunePersistedViewStates" ] ( states )
19781978
19791979 expect ( Object . keys ( pruned ) ) . toHaveLength ( 50 )
1980- expect ( pruned [ "view-54" ] ) . toBeDefined ( )
1981- expect ( pruned [ "view-5" ] ) . toBeDefined ( )
1980+ expect ( pruned [ "view-54" ] ) . toEqual ( { mode : "mode-54" , updatedAt : 54 } )
1981+ expect ( pruned [ "view-5" ] ) . toEqual ( { mode : "mode-5" , updatedAt : 5 } )
19821982 expect ( pruned [ "view-4" ] ) . toBeUndefined ( )
19831983
19841984 await provider . dispose ( )
@@ -10810,6 +10810,7 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
1081010810 // minimal double without the full provider/services graph.
1081110811 const siblingTask = {
1081210812 apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "old-key" } ,
10813+ taskApiConfigName : "saved-profile" ,
1081310814 updateApiConfiguration : vi . fn ( ) ,
1081410815 }
1081510816 vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
@@ -10854,6 +10855,109 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
1085410855 }
1085510856 } )
1085610857
10858+ it ( "does not rebuild a pinned sibling's task that runs under another profile" , async ( ) => {
10859+ // Defensive: the doubles in this suite can leave console writes pending
10860+ // at worker teardown.
10861+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
10862+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
10863+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
10864+ const sibling = new ClineProvider (
10865+ mockContext ,
10866+ mockOutputChannel ,
10867+ "editor" ,
10868+ new ContextProxy ( mockContext ) ,
10869+ new WebviewFocusTracker ( ) ,
10870+ )
10871+ try {
10872+ // The sibling pins the saved profile, but its active task follows a
10873+ // different sticky profile: the save must refresh the view overlay
10874+ // without switching that conversation to the saved profile's settings.
10875+ sibling [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
10876+ sibling [ "viewLocalState" ] . apiConfiguration = {
10877+ apiProvider : providerIdentifiers . anthropic ,
10878+ apiKey : "old-key" ,
10879+ }
10880+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
10881+
10882+ const siblingTask = {
10883+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
10884+ taskApiConfigName : "other-profile" ,
10885+ updateApiConfiguration : vi . fn ( ) ,
10886+ }
10887+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
10888+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
10889+ )
10890+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
10891+ // @ts -ignore - Replace providerSettingsManager with a test double.
10892+ provider . providerSettingsManager = {
10893+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
10894+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
10895+ setModeConfig : vi . fn ( ) ,
10896+ getProfile : vi
10897+ . fn ( )
10898+ . mockResolvedValue ( { name : "saved-profile" , apiProvider : providerIdentifiers . anthropic } ) ,
10899+ getModeConfigId : vi . fn ( ) . mockResolvedValue ( undefined ) ,
10900+ }
10901+
10902+ await provider . upsertProviderProfile (
10903+ "saved-profile" ,
10904+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
10905+ false ,
10906+ )
10907+
10908+ // The pinned view's overlay still catches up with the saved settings...
10909+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
10910+ apiProvider : providerIdentifiers . anthropic ,
10911+ apiKey : "new-key" ,
10912+ } )
10913+ // ...but the task runs under another profile: its handler must not be
10914+ // switched to the saved profile's settings.
10915+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
10916+ // Let queued view-local persistence settle while the console spies are
10917+ // still installed, so teardown has no pending writes.
10918+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
10919+ } finally {
10920+ await sibling . dispose ( )
10921+ }
10922+ } )
10923+
10924+ it ( "does not rebuild the acting view's task when it runs under another profile" , async ( ) => {
10925+ // The acting view pins the saved profile while its own task follows a
10926+ // different sticky profile: the non-activating save refreshes the view
10927+ // overlay but must leave the task's handler alone.
10928+ const task = {
10929+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
10930+ taskApiConfigName : "other-profile" ,
10931+ updateApiConfiguration : vi . fn ( ) ,
10932+ }
10933+ vi . spyOn ( provider , "getCurrentTask" ) . mockReturnValue (
10934+ task as unknown as ReturnType < typeof provider . getCurrentTask > ,
10935+ )
10936+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
10937+ provider [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
10938+ // @ts -ignore - Replace providerSettingsManager with a test double.
10939+ provider . providerSettingsManager = {
10940+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
10941+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
10942+ setModeConfig : vi . fn ( ) ,
10943+ getProfile : vi
10944+ . fn ( )
10945+ . mockResolvedValue ( { name : "saved-profile" , apiProvider : providerIdentifiers . anthropic } ) ,
10946+ getModeConfigId : vi . fn ( ) . mockResolvedValue ( undefined ) ,
10947+ }
10948+
10949+ await provider . upsertProviderProfile (
10950+ "saved-profile" ,
10951+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
10952+ false ,
10953+ )
10954+
10955+ expect ( provider [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
10956+ apiProvider : providerIdentifiers . anthropic ,
10957+ apiKey : "new-key" ,
10958+ } )
10959+ expect ( task . updateApiConfiguration ) . not . toHaveBeenCalled ( )
10960+ } )
1085710961 it ( "does not leak shared provider keys into a pinned view's api configuration" , async ( ) => {
1085810962 vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
1085910963 vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
0 commit comments