@@ -741,15 +741,16 @@ describe("ClineProvider - Parallel Mode Support", () => {
741741 const provider = new ClineProvider ( mockContext , mockOutputChannel , "sidebar" , new ContextProxy ( mockContext ) )
742742
743743 const contextProxySpy = vi . spyOn ( provider . contextProxy , "setValue" )
744+ await ( provider as any ) . setViewStateId ( "stable-sidebar-view" )
744745
745746 await ( provider as any ) . saveViewState ( "mode" , "architect" )
746747
747748 // Verify viewLocalState was updated
748749 expect ( ( provider as any ) . viewLocalState . mode ) . toBe ( "architect" )
749750
750- // saveViewState now uses view-specific key for mode/currentApiConfigName/apiConfiguration
751- const expectedViewKey = `__view_state_sidebar- ${ provider . viewId . split ( "-" ) [ 1 ] } _mode`
752- expect ( contextProxySpy ) . toHaveBeenCalledWith ( expectedViewKey , "architect" )
751+ // saveViewState uses the stable per-view id, not the construction-order viewId suffix.
752+ expect ( contextProxySpy ) . toHaveBeenCalledWith ( "__view_state_stable-sidebar-view_mode" , "architect" )
753+ expect ( contextProxySpy ) . not . toHaveBeenCalledWith ( `__view_state_ ${ provider . viewId } _mode` , expect . anything ( ) )
753754
754755 await provider . dispose ( )
755756 } )
@@ -859,6 +860,37 @@ describe("ClineProvider - Parallel Mode Support", () => {
859860 await provider . dispose ( )
860861 } )
861862
863+ it ( "should restore mode, current API config name, and API configuration from stable per-view state" , async ( ) => {
864+ const provider = new ClineProvider ( mockContext , mockOutputChannel , "editor" , new ContextProxy ( mockContext ) )
865+ const stableViewId = "stable-editor-tab-a"
866+ const persistedApiConfiguration = {
867+ apiProvider : "openrouter" as const ,
868+ openRouterModelId : "openrouter/anthropic/claude-sonnet-4" ,
869+ }
870+
871+ await provider . contextProxy . setValue ( `__view_state_${ stableViewId } _mode` as any , "architect" )
872+ await provider . contextProxy . setValue (
873+ `__view_state_${ stableViewId } _currentApiConfigName` as any ,
874+ "profile-a" ,
875+ )
876+ await provider . contextProxy . setValue (
877+ `__view_state_${ stableViewId } _apiConfiguration` as any ,
878+ persistedApiConfiguration ,
879+ )
880+ await provider . contextProxy . setValue ( "mode" as any , "debugger" )
881+ await provider . contextProxy . setValue ( "currentApiConfigName" as any , "profile-b" )
882+ await provider . contextProxy . setValue ( "apiConfiguration" as any , { apiProvider : "anthropic" } )
883+
884+ await ( provider as any ) . setViewStateId ( stableViewId )
885+ const state = await provider . getState ( )
886+
887+ expect ( state . mode ) . toBe ( "architect" )
888+ expect ( state . currentApiConfigName ) . toBe ( "profile-a" )
889+ expect ( state . apiConfiguration ) . toMatchObject ( persistedApiConfiguration )
890+
891+ await provider . dispose ( )
892+ } )
893+
862894 it ( "should log and keep existing viewLocalState when loadViewState fails" , async ( ) => {
863895 const provider = new ClineProvider ( mockContext , mockOutputChannel , "sidebar" , new ContextProxy ( mockContext ) )
864896 const logSpy = vi . spyOn ( provider as any , "log" )
0 commit comments