| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/agent" |
| 10 | "reasonix/internal/config" |
| 11 | ) |
| 12 | |
| 13 | func TestUnmodifiedRecoveryCopyDoesNotMigrateIntoTopics(t *testing.T) { |
| 14 | isolateDesktopUserDirs(t) |
| 15 | dir := config.SessionDir() |
| 16 | if err := os.MkdirAll(dir, 0o755); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | parent, recovery, branchMsgs := forkDesktopRecoveryBranch(t, dir, "normal") |
| 20 | coverDesktopRecoveryParent(t, parent, branchMsgs) |
| 21 | metaPath := agent.BranchMetaPath(recovery) |
| 22 | before, err := os.ReadFile(metaPath) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | app := NewApp() |
| 27 | // Metadata discovery may proceed, but content proof must wait until this |
| 28 | // test has observed both sources. Wall-clock timing cannot fence that phase. |
| 29 | release, err := app.historyMaintenance.Foreground(t.Context()) |
| 30 | if err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | defer release() |
| 34 | app.startSessionCatalog() |
| 35 | catalog := waitForSessionCatalogForTest(t, app, nil) |
| 36 | catalog.PrioritizeWorkspace("global", "") |
| 37 | nodes := waitForCatalogTopic(t, app, "global", "", legacySessionTopicID(parent)) |
| 38 | if len(nodes) != 1 || len(nodes[0].Children) != 2 { |
| 39 | t.Fatalf("project tree = %#v, want both sources before content proof", nodes) |
| 40 | } |
| 41 | release() |
| 42 | if err := catalog.ProveRecoveryLineage(t.Context()); err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | nodes = mustListProjectTree(t, app) |
| 46 | if len(nodes) != 1 || len(nodes[0].Children) != 1 || filepath.Clean(nodes[0].Children[0].SessionPath) != filepath.Clean(parent) { |
| 47 | t.Fatalf("project tree = %#v, want the covering parent after content proof", nodes) |
| 48 | } |
| 49 | if meta, ok, err := agent.LoadBranchMeta(recovery); err != nil || !ok { |
| 50 | t.Fatalf("load recovery meta: ok=%v err=%v", ok, err) |
| 51 | } else if strings.TrimSpace(meta.TopicID) != "" { |
| 52 | t.Fatalf("parent-covered recovery copy was migrated into topic %q", meta.TopicID) |
| 53 | } |
| 54 | after, err := os.ReadFile(metaPath) |
| 55 | if err != nil || string(after) != string(before) { |
| 56 | t.Fatalf("content proof changed the recovery sidecar: %v", err) |
| 57 | } |
| 58 | } |
| 59 |