| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/desktop/internal/workspacestate" |
| 9 | ) |
| 10 | |
| 11 | func TestKeepOnlyVisibleTabKeepsCanonicalRuntimeWhenRegistryCannotPersist(t *testing.T) { |
| 12 | isolateDesktopUserDirs(t) |
| 13 | statePath := filepath.Join(t.TempDir(), "desktop", "workspace-state-v1.json") |
| 14 | if err := os.MkdirAll(filepath.Dir(statePath), 0o700); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if err := os.WriteFile(statePath, []byte(`{"version":99}`), 0o600); err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | hidden := &WorkspaceTab{ |
| 21 | ID: "hidden", Scope: "global", WorkspaceRoot: globalTabWorkspaceRoot(), |
| 22 | SessionID: "durable-session", Ready: true, disabledMCP: map[string]ServerView{}, |
| 23 | } |
| 24 | target := &WorkspaceTab{ID: "target", Scope: "global", Ready: true, disabledMCP: map[string]ServerView{}} |
| 25 | app := &App{ |
| 26 | tabs: map[string]*WorkspaceTab{"hidden": hidden, "target": target}, tabOrder: []string{"hidden", "target"}, |
| 27 | activeTabID: "hidden", |
| 28 | desktopPersistenceState: desktopPersistenceState{ |
| 29 | desktopSessions: desktopSessionState{workspaceState: workspacestate.NewStore(statePath)}, |
| 30 | }, |
| 31 | } |
| 32 | if _, err := app.keepOnlyVisibleTab("target"); err == nil { |
| 33 | t.Fatal("keepOnlyVisibleTab succeeded despite an unpublishable canonical registry") |
| 34 | } |
| 35 | if app.tabs["hidden"] != hidden || hidden.removed { |
| 36 | t.Fatal("canonical tab was pruned after registry persistence failed") |
| 37 | } |
| 38 | } |
| 39 |