| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/store" |
| 9 | ) |
| 10 | |
| 11 | // A listing repair replays the transcript and rewrites the event index; on a |
| 12 | // schema-2 log that index is the head index and must stay schema 2. |
| 13 | func TestListingRepairKeepsSchemaTwoHeadIndex(t *testing.T) { |
| 14 | path := dagTestSession(t) |
| 15 | dagSavedSession(t, path, "q1", "a1") |
| 16 | if err := os.Remove(store.SessionEventIndex(path)); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | if err := os.Remove(store.SessionDisplayIndex(path)); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if err := UpdateBranchMeta(path, false, func(meta *BranchMeta) error { |
| 23 | meta.ListingRevision, meta.ListingContentDigest = 0, "" |
| 24 | return nil |
| 25 | }); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | result, err := RepairSessionListingProjection(context.Background(), path) |
| 29 | if err != nil || result.Status != SessionListingRepairApplied { |
| 30 | t.Fatalf("repair = %+v err=%v", result, err) |
| 31 | } |
| 32 | idx, err := ReadSessionHeadIndex(path) |
| 33 | if err != nil || idx == nil || !idx.Current(path) || idx.SelectedHead != SessionMainHead || len(idx.Heads) != 1 { |
| 34 | t.Fatalf("head index after repair = %+v err=%v, want a current schema-2 index", idx, err) |
| 35 | } |
| 36 | if _, err := readSessionEventIndex(path); err == nil { |
| 37 | t.Fatal("repair must not write a schema-1 index over a schema-2 log") |
| 38 | } |
| 39 | } |
| 40 |