@@ -502,6 +502,55 @@ final class SessionStoreTests: XCTestCase {
502502 XCTAssertEqual ( snapshot. workspaces [ 2 ] . sidebarWidth ?? - 1 , 246 , accuracy: 0.1 )
503503 }
504504
505+ func testPerWorkspaceSidebarWidthAndVisibilityAreIndependent( ) {
506+ // Each workspace has a distinct sidebar width and visibility.
507+ // After save + restore, every workspace gets back its own values — not the others'.
508+ let state = AppState ( )
509+
510+ let ws1 = Workspace ( folderPath: " /tmp " )
511+ ws1. customName = " Alpha "
512+ ws1. sidebarState = SidebarWorkspaceState ( isVisible: true , width: 200 )
513+
514+ let ws2 = Workspace ( folderPath: " /tmp " )
515+ ws2. customName = " Beta "
516+ ws2. sidebarState = SidebarWorkspaceState ( isVisible: false , width: 350 )
517+
518+ let ws3 = Workspace ( folderPath: " /tmp " )
519+ ws3. customName = " Gamma "
520+ ws3. sidebarState = SidebarWorkspaceState ( isVisible: true , width: 500 )
521+
522+ state. addWorkspace ( ws1)
523+ state. addWorkspace ( ws2)
524+ state. addWorkspace ( ws3)
525+
526+ SessionStore . save ( appState: state)
527+
528+ // Verify the raw JSON values are correct.
529+ let snapshot = SessionStore . load ( ) !
530+ XCTAssertEqual ( snapshot. workspaces [ 0 ] . sidebarIsVisible, true , " ws1 visible " )
531+ XCTAssertEqual ( snapshot. workspaces [ 0 ] . sidebarWidth ?? - 1 , 200 , accuracy: 0.1 , " ws1 width " )
532+ XCTAssertEqual ( snapshot. workspaces [ 1 ] . sidebarIsVisible, false , " ws2 hidden " )
533+ XCTAssertEqual ( snapshot. workspaces [ 1 ] . sidebarWidth ?? - 1 , 350 , accuracy: 0.1 , " ws2 width " )
534+ XCTAssertEqual ( snapshot. workspaces [ 2 ] . sidebarIsVisible, true , " ws3 visible " )
535+ XCTAssertEqual ( snapshot. workspaces [ 2 ] . sidebarWidth ?? - 1 , 500 , accuracy: 0.1 , " ws3 width " )
536+
537+ // Verify restored Workspace objects carry distinct, correct sidebar states.
538+ let restored = SessionStore . workspaces ( from: snapshot)
539+ XCTAssertEqual ( restored. count, 3 )
540+
541+ XCTAssertEqual ( restored [ 0 ] . sidebarState. isVisible, true , " restored ws1 visible " )
542+ XCTAssertEqual ( restored [ 0 ] . sidebarState. width ?? - 1 , 200 , accuracy: 0.1 , " restored ws1 width " )
543+ XCTAssertEqual ( restored [ 1 ] . sidebarState. isVisible, false , " restored ws2 hidden " )
544+ XCTAssertEqual ( restored [ 1 ] . sidebarState. width ?? - 1 , 350 , accuracy: 0.1 , " restored ws2 width " )
545+ XCTAssertEqual ( restored [ 2 ] . sidebarState. isVisible, true , " restored ws3 visible " )
546+ XCTAssertEqual ( restored [ 2 ] . sidebarState. width ?? - 1 , 500 , accuracy: 0.1 , " restored ws3 width " )
547+
548+ // No values leaked across workspaces.
549+ XCTAssertNotEqual ( restored [ 0 ] . sidebarState. width ?? - 1 , 350 , " ws1 must not have ws2 width " )
550+ XCTAssertNotEqual ( restored [ 1 ] . sidebarState. isVisible, true , " ws2 must not have ws1 visibility " )
551+ XCTAssertNotEqual ( restored [ 2 ] . sidebarState. width ?? - 1 , 200 , " ws3 must not have ws1 width " )
552+ }
553+
505554 func testSavePreservesActiveWorkspaceIndex( ) {
506555 let state = AppState ( )
507556 state. addWorkspace ( Workspace ( folderPath: " /tmp " ) )
0 commit comments