@@ -1870,8 +1870,8 @@ describe("ClineProvider", () => {
18701870 const pruned = provider [ "prunePersistedViewStates" ] ( states )
18711871
18721872 expect ( Object . keys ( pruned ) ) . toHaveLength ( 50 )
1873- expect ( pruned [ "view-54" ] ) . toBeDefined ( )
1874- expect ( pruned [ "view-5" ] ) . toBeDefined ( )
1873+ expect ( pruned [ "view-54" ] ) . toEqual ( { mode : "mode-54" , updatedAt : 54 } )
1874+ expect ( pruned [ "view-5" ] ) . toEqual ( { mode : "mode-5" , updatedAt : 5 } )
18751875 expect ( pruned [ "view-4" ] ) . toBeUndefined ( )
18761876
18771877 await provider . dispose ( )
@@ -7496,6 +7496,7 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
74967496 // minimal double without the full provider/services graph.
74977497 const siblingTask = {
74987498 apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "old-key" } ,
7499+ taskApiConfigName : "saved-profile" ,
74997500 updateApiConfiguration : vi . fn ( ) ,
75007501 }
75017502 vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
@@ -7539,5 +7540,101 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
75397540 await sibling . dispose ( )
75407541 }
75417542 } )
7543+
7544+ it ( "does not rebuild a pinned sibling's task that runs under another profile" , async ( ) => {
7545+ // Defensive: the doubles in this suite can leave console writes pending
7546+ // at worker teardown.
7547+ vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } )
7548+ vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } )
7549+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
7550+ const sibling = new ClineProvider (
7551+ mockContext ,
7552+ mockOutputChannel ,
7553+ "editor" ,
7554+ new ContextProxy ( mockContext ) ,
7555+ new WebviewFocusTracker ( ) ,
7556+ )
7557+ try {
7558+ // The sibling pins the saved profile, but its active task follows a
7559+ // different sticky profile: the save must refresh the view overlay
7560+ // without switching that conversation to the saved profile's settings.
7561+ sibling [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
7562+ sibling [ "viewLocalState" ] . apiConfiguration = {
7563+ apiProvider : providerIdentifiers . anthropic ,
7564+ apiKey : "old-key" ,
7565+ }
7566+ vi . spyOn ( sibling , "postStateToWebview" ) . mockResolvedValue ( undefined )
7567+
7568+ const siblingTask = {
7569+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
7570+ taskApiConfigName : "other-profile" ,
7571+ updateApiConfiguration : vi . fn ( ) ,
7572+ }
7573+ vi . spyOn ( sibling , "getCurrentTask" ) . mockReturnValue (
7574+ siblingTask as unknown as ReturnType < typeof sibling . getCurrentTask > ,
7575+ )
7576+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
7577+ // @ts -ignore - Replace providerSettingsManager with a test double.
7578+ provider . providerSettingsManager = {
7579+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
7580+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
7581+ setModeConfig : vi . fn ( ) ,
7582+ }
7583+
7584+ await provider . upsertProviderProfile (
7585+ "saved-profile" ,
7586+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
7587+ false ,
7588+ )
7589+
7590+ // The pinned view's overlay still catches up with the saved settings...
7591+ expect ( sibling [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
7592+ apiProvider : providerIdentifiers . anthropic ,
7593+ apiKey : "new-key" ,
7594+ } )
7595+ // ...but the task runs under another profile: its handler must not be
7596+ // switched to the saved profile's settings.
7597+ expect ( siblingTask . updateApiConfiguration ) . not . toHaveBeenCalled ( )
7598+ // Let queued view-local persistence settle while the console spies are
7599+ // still installed, so teardown has no pending writes.
7600+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
7601+ } finally {
7602+ await sibling . dispose ( )
7603+ }
7604+ } )
7605+
7606+ it ( "does not rebuild the acting view's task when it runs under another profile" , async ( ) => {
7607+ // The acting view pins the saved profile while its own task follows a
7608+ // different sticky profile: the non-activating save refreshes the view
7609+ // overlay but must leave the task's handler alone.
7610+ const task = {
7611+ apiConfiguration : { apiProvider : providerIdentifiers . anthropic , apiKey : "other-key" } ,
7612+ taskApiConfigName : "other-profile" ,
7613+ updateApiConfiguration : vi . fn ( ) ,
7614+ }
7615+ vi . spyOn ( provider , "getCurrentTask" ) . mockReturnValue (
7616+ task as unknown as ReturnType < typeof provider . getCurrentTask > ,
7617+ )
7618+ vi . spyOn ( provider , "postStateToWebview" ) . mockResolvedValue ( undefined )
7619+ provider [ "viewLocalState" ] . currentApiConfigName = "saved-profile"
7620+ // @ts -ignore - Replace providerSettingsManager with a test double.
7621+ provider . providerSettingsManager = {
7622+ saveConfig : vi . fn ( ) . mockResolvedValue ( "saved-id" ) ,
7623+ listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
7624+ setModeConfig : vi . fn ( ) ,
7625+ }
7626+
7627+ await provider . upsertProviderProfile (
7628+ "saved-profile" ,
7629+ { apiProvider : providerIdentifiers . anthropic , apiKey : "new-key" } ,
7630+ false ,
7631+ )
7632+
7633+ expect ( provider [ "viewLocalState" ] . apiConfiguration ) . toEqual ( {
7634+ apiProvider : providerIdentifiers . anthropic ,
7635+ apiKey : "new-key" ,
7636+ } )
7637+ expect ( task . updateApiConfiguration ) . not . toHaveBeenCalled ( )
7638+ } )
75427639 } )
75437640} )
0 commit comments