| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "reasonix/internal/config" |
| 9 | ) |
| 10 | |
| 11 | func TestRestoreGlobalTopicSessionReindexesProjectTree(t *testing.T) { |
| 12 | isolateDesktopUserDirs(t) |
| 13 | |
| 14 | dir := config.SessionDir() |
| 15 | if err := os.MkdirAll(dir, 0o755); err != nil { |
| 16 | t.Fatalf("mkdir sessions: %v", err) |
| 17 | } |
| 18 | sessionPath := writeLegacySession(t, dir, "restore-global.jsonl", "restore global history", time.Now().Add(-time.Hour)) |
| 19 | topicID := legacySessionTopicID(sessionPath) |
| 20 | app := NewApp() |
| 21 | |
| 22 | nodes := waitForCatalogTopic(t, app, "global", "", topicID) |
| 23 | if len(nodes) != 1 || len(nodes[0].Children) != 1 || nodes[0].Children[0].TopicID != topicID { |
| 24 | t.Fatalf("legacy session should start in Global, got %#v", nodes) |
| 25 | } |
| 26 | // The projected identity is sufficient for an explicit archive/restore; |
| 27 | // discovery does not need to modify the historical branch metadata first. |
| 28 | if err := app.TrashTopic(topicID); err != nil { |
| 29 | t.Fatalf("trash global topic: %v", err) |
| 30 | } |
| 31 | ref := assertLegacyLifecycle(t, app, sessionPath, "archived") |
| 32 | |
| 33 | if err := app.RestoreCanonicalSession(ref); err != nil { |
| 34 | t.Fatalf("restore global session: %v", err) |
| 35 | } |
| 36 | if got := app.ListTrashedSessions(); len(got) != 0 { |
| 37 | t.Fatalf("trash should be empty after restore, got %#v", got) |
| 38 | } |
| 39 | nodes = waitForCatalogTopic(t, app, "global", "", topicID) |
| 40 | if len(nodes) != 1 || nodes[0].Kind != "global_folder" || len(nodes[0].Children) != 1 || nodes[0].Children[0].TopicID != topicID { |
| 41 | t.Fatalf("restored global session should reappear in Global, got %#v", nodes) |
| 42 | } |
| 43 | } |
| 44 |