| 1 | package store |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestSessionSidecarLayout(t *testing.T) { |
| 6 | const p = "/home/u/.reasonix/sessions/abc.jsonl" |
| 7 | cases := []struct { |
| 8 | name string |
| 9 | got string |
| 10 | want string |
| 11 | }{ |
| 12 | // .meta appends to the full path (historical layout); the rest replace .jsonl. |
| 13 | {"meta", SessionMeta(p), p + ".meta"}, |
| 14 | {"goal-state", SessionGoalState(p), "/home/u/.reasonix/sessions/abc.goal-state.json"}, |
| 15 | {"event-log", SessionEventLog(p), "/home/u/.reasonix/sessions/abc.events.jsonl"}, |
| 16 | {"event-log-damaged", SessionEventLogDamaged(p), "/home/u/.reasonix/sessions/abc.events.jsonl.damaged"}, |
| 17 | {"event-index", SessionEventIndex(p), "/home/u/.reasonix/sessions/abc.event-index.json"}, |
| 18 | {"conflict-log", SessionConflictLog(p), "/home/u/.reasonix/sessions/abc.conflicts.jsonl"}, |
| 19 | {"lock", SessionLockFile(p), p + ".lock"}, |
| 20 | {"lease-lock", SessionLeaseLock(p), p + ".lease.lock"}, |
| 21 | {"lease-info", SessionLeaseInfo(p), p + ".lease.json"}, |
| 22 | {"checkpoint", SessionCheckpointDir(p), "/home/u/.reasonix/sessions/abc.ckpt"}, |
| 23 | {"jobs", SessionJobsDir(p), "/home/u/.reasonix/sessions/abc.jobs"}, |
| 24 | {"cleanup-pending", SessionCleanupPending(p), "/home/u/.reasonix/sessions/abc.cleanup-pending.json"}, |
| 25 | } |
| 26 | for _, c := range cases { |
| 27 | if c.got != c.want { |
| 28 | t.Errorf("%s = %q, want %q", c.name, c.got, c.want) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestSessionSidecarEmptyPath(t *testing.T) { |
| 34 | for _, fn := range []struct { |
| 35 | name string |
| 36 | f func(string) string |
| 37 | }{ |
| 38 | {"meta", SessionMeta}, |
| 39 | {"goal-state", SessionGoalState}, |
| 40 | {"event-log", SessionEventLog}, |
| 41 | {"event-log-damaged", SessionEventLogDamaged}, |
| 42 | {"event-index", SessionEventIndex}, |
| 43 | {"conflict-log", SessionConflictLog}, |
| 44 | {"lock", SessionLockFile}, |
| 45 | {"lease-lock", SessionLeaseLock}, |
| 46 | {"lease-info", SessionLeaseInfo}, |
| 47 | {"checkpoint", SessionCheckpointDir}, |
| 48 | {"jobs", SessionJobsDir}, |
| 49 | {"cleanup-pending", SessionCleanupPending}, |
| 50 | } { |
| 51 | if got := fn.f(""); got != "" { |
| 52 | t.Errorf("%s(\"\") = %q, want empty", fn.name, got) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestIsSessionTranscriptName(t *testing.T) { |
| 58 | cases := []struct { |
| 59 | name string |
| 60 | want bool |
| 61 | }{ |
| 62 | {"session.jsonl", true}, |
| 63 | {"session.events.jsonl", false}, |
| 64 | {"session.conflicts.jsonl", false}, |
| 65 | {"session.guardian.jsonl", false}, |
| 66 | {"session.guardian.events.jsonl", false}, |
| 67 | {"session.events.jsonl.damaged", false}, |
| 68 | {"session.jsonl.meta", false}, |
| 69 | {"notes.txt", false}, |
| 70 | {"", false}, |
| 71 | } |
| 72 | for _, c := range cases { |
| 73 | if got := IsSessionTranscriptName(c.name); got != c.want { |
| 74 | t.Errorf("IsSessionTranscriptName(%q) = %v, want %v", c.name, got, c.want) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestSessionSidecarFiles(t *testing.T) { |
| 80 | const p = "/home/u/.reasonix/sessions/abc.jsonl" |
| 81 | got := SessionSidecarFiles(p) |
| 82 | want := []string{ |
| 83 | p + ".meta", |
| 84 | "/home/u/.reasonix/sessions/abc.goal-state.json", |
| 85 | "/home/u/.reasonix/sessions/abc.events.jsonl", |
| 86 | "/home/u/.reasonix/sessions/abc.events.jsonl.damaged", |
| 87 | "/home/u/.reasonix/sessions/abc.event-index.json", |
| 88 | "/home/u/.reasonix/sessions/abc.conflicts.jsonl", |
| 89 | "/home/u/.reasonix/sessions/abc.recovery.json", |
| 90 | } |
| 91 | if len(got) != len(want) { |
| 92 | t.Fatalf("SessionSidecarFiles = %v, want %v", got, want) |
| 93 | } |
| 94 | for i := range want { |
| 95 | if got[i] != want[i] { |
| 96 | t.Errorf("SessionSidecarFiles[%d] = %q, want %q", i, got[i], want[i]) |
| 97 | } |
| 98 | } |
| 99 | if SessionSidecarFiles("") != nil { |
| 100 | t.Error("SessionSidecarFiles(\"\") should be nil") |
| 101 | } |
| 102 | } |
| 103 |