返回 DeepSeek-Reasonix
historical_tab_restore_test.go
根目录 / desktop / historical_tab_restore_test.go
1 package main
2
3 import (
4 "context"
5 "os"
6 "path/filepath"
7 "testing"
8
9 "reasonix/internal/config"
10 )
11
12 func TestHistoricalRestoredTabActivationKeepsPreparationExplicit(t *testing.T) {
13 for _, activate := range []bool{false, true} {
14 t.Run(map[bool]string{false: "direct-build", true: "tab-selection"}[activate], func(t *testing.T) {
15 isolateDesktopUserDirs(t)
16 app := newHistoricalLifecycleApp(t)
17 t.Cleanup(func() { app.shutdown(context.Background()) })
18 release, err := app.beginProjectRuntimeAdmission("global", globalTabWorkspaceRoot())
19 if err != nil {
20 t.Fatal(err)
21 }
22 tab := app.createTabEntry("global", globalTabWorkspaceRoot(), "")
23 source := &SessionSourceRef{HostID: localDesktopHostID, Path: filepath.Join(t.TempDir(), "old.jsonl")}
24 tab.HistoricalSource = source
25 tab.SessionPath = source.Path
26 tab.sink = &tabEventSink{tabID: tab.ID, app: app}
27 app.publishRestoredTab(tab, release)
28 if activate {
29 if err := app.SetActiveTab(tab.ID); err != nil {
30 t.Fatal(err)
31 }
32 } else {
33 app.startTabControllerBuild(tab)
34 }
35 app.mu.RLock()
36 defer app.mu.RUnlock()
37 if tab.buildGeneration != 0 || tab.Ctrl != nil || tab.HistoricalSource != source {
38 t.Fatal("selecting a historical shell must not start a runtime before explicit preparation")
39 }
40 })
41 }
42 }
43
44 func TestHistoricalDiscoveryIgnoresEmptyCanonicalDirectories(t *testing.T) {
45 isolateDesktopUserDirs(t)
46 root := config.SessionStoreDir()
47 for _, id := range []string{"empty-read-probe", "damaged-history"} {
48 if err := os.MkdirAll(filepath.Join(root, id), 0700); err != nil {
49 t.Fatal(err)
50 }
51 }
52 if err := os.WriteFile(filepath.Join(root, "damaged-history", "manifest.json"), []byte("invalid"), 0600); err != nil {
53 t.Fatal(err)
54 }
55 app := newHistoricalLifecycleApp(t)
56 status, err := app.ListHistoricalSessions()
57 if err != nil || len(status.Items) != 1 || status.Items[0].Title != "damaged-history" {
58 t.Fatalf("empty probes should be hidden but damaged artifacts preserved: %+v %v", status, err)
59 }
60 }
61
62 func TestHistoricalRestoredSourceClearsOnCanonicalActivation(t *testing.T) {
63 tab := &WorkspaceTab{HistoricalSource: &SessionSourceRef{HostID: localDesktopHostID, Path: "/fixture/old.jsonl"}}
64 setTabSessionIdentity(tab, remoteSessionIDRoutePrefix+"canonical-target")
65 if tab.HistoricalSource != nil {
66 t.Fatal("pending source leaked into the next session")
67 }
68 if tab.SessionID != "canonical-target" {
69 t.Fatal("test must activate a canonical identity")
70 }
71 }
72
72 lines GO