| 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 | {"turn-event-log", SessionTurnEventLog(p), "/home/u/.reasonix/sessions/abc.turns.jsonl"}, |
| 18 | {"turn-event-log-damaged", SessionTurnEventLogDamaged(p), "/home/u/.reasonix/sessions/abc.turns.jsonl.damaged"}, |
| 19 | {"event-index", SessionEventIndex(p), "/home/u/.reasonix/sessions/abc.event-index.json"}, |
| 20 | {"display-index", SessionDisplayIndex(p), "/home/u/.reasonix/sessions/abc.display-index.json"}, |
| 21 | {"transcript-projection", SessionTranscriptProjection(p), "/home/u/.reasonix/sessions/abc.transcript-projection.json"}, |
| 22 | {"conflict-log", SessionConflictLog(p), "/home/u/.reasonix/sessions/abc.conflicts.jsonl"}, |
| 23 | {"lock", SessionLockFile(p), p + ".lock"}, |
| 24 | {"lease-lock", SessionLeaseLock(p), p + ".lease.lock"}, |
| 25 | {"lease-info", SessionLeaseInfo(p), p + ".lease.json"}, |
| 26 | {"checkpoint", SessionCheckpointDir(p), "/home/u/.reasonix/sessions/abc.ckpt"}, |
| 27 | {"jobs", SessionJobsDir(p), "/home/u/.reasonix/sessions/abc.jobs"}, |
| 28 | {"inbox", SessionInboxDir(p), "/home/u/.reasonix/sessions/abc.inbox"}, |
| 29 | {"cleanup-pending", SessionCleanupPending(p), "/home/u/.reasonix/sessions/abc.cleanup-pending.json"}, |
| 30 | {"context", SessionContext(p), "/home/u/.reasonix/sessions/abc.context.json"}, |
| 31 | } |
| 32 | for _, c := range cases { |
| 33 | if c.got != c.want { |
| 34 | t.Errorf("%s = %q, want %q", c.name, c.got, c.want) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestSessionSidecarEmptyPath(t *testing.T) { |
| 40 | for _, fn := range []struct { |
| 41 | name string |
| 42 | f func(string) string |
| 43 | }{ |
| 44 | {"meta", SessionMeta}, |
| 45 | {"goal-state", SessionGoalState}, |
| 46 | {"event-log", SessionEventLog}, |
| 47 | {"event-log-damaged", SessionEventLogDamaged}, |
| 48 | {"turn-event-log", SessionTurnEventLog}, |
| 49 | {"turn-event-log-damaged", SessionTurnEventLogDamaged}, |
| 50 | {"event-index", SessionEventIndex}, |
| 51 | {"display-index", SessionDisplayIndex}, |
| 52 | {"transcript-projection", SessionTranscriptProjection}, |
| 53 | {"conflict-log", SessionConflictLog}, |
| 54 | {"lock", SessionLockFile}, |
| 55 | {"lease-lock", SessionLeaseLock}, |
| 56 | {"lease-info", SessionLeaseInfo}, |
| 57 | {"checkpoint", SessionCheckpointDir}, |
| 58 | {"jobs", SessionJobsDir}, |
| 59 | {"inbox", SessionInboxDir}, |
| 60 | {"cleanup-pending", SessionCleanupPending}, |
| 61 | {"context", SessionContext}, |
| 62 | } { |
| 63 | if got := fn.f(""); got != "" { |
| 64 | t.Errorf("%s(\"\") = %q, want empty", fn.name, got) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func TestIsSessionTranscriptName(t *testing.T) { |
| 70 | cases := []struct { |
| 71 | name string |
| 72 | want bool |
| 73 | }{ |
| 74 | {"session.jsonl", true}, |
| 75 | {"session.events.jsonl", false}, |
| 76 | {"session.turns.jsonl", false}, |
| 77 | {"session.conflicts.jsonl", false}, |
| 78 | {"session.guardian.jsonl", false}, |
| 79 | {"session.guardian.events.jsonl", false}, |
| 80 | {"session.events.jsonl.damaged", false}, |
| 81 | {"session.jsonl.meta", false}, |
| 82 | {"notes.txt", false}, |
| 83 | {"", false}, |
| 84 | } |
| 85 | for _, c := range cases { |
| 86 | if got := IsSessionTranscriptName(c.name); got != c.want { |
| 87 | t.Errorf("IsSessionTranscriptName(%q) = %v, want %v", c.name, got, c.want) |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | func TestSessionSidecarFiles(t *testing.T) { |
| 93 | const p = "/home/u/.reasonix/sessions/abc.jsonl" |
| 94 | got := SessionSidecarFiles(p) |
| 95 | want := []string{ |
| 96 | p + ".meta", |
| 97 | "/home/u/.reasonix/sessions/abc.goal-state.json", |
| 98 | "/home/u/.reasonix/sessions/abc.events.jsonl", |
| 99 | "/home/u/.reasonix/sessions/abc.events.jsonl.damaged", |
| 100 | "/home/u/.reasonix/sessions/abc.events.jsonl.rotating", |
| 101 | "/home/u/.reasonix/sessions/abc.turns.jsonl", |
| 102 | "/home/u/.reasonix/sessions/abc.turns.jsonl.damaged", |
| 103 | "/home/u/.reasonix/sessions/abc.event-index.json", |
| 104 | "/home/u/.reasonix/sessions/abc.display-index.json", |
| 105 | "/home/u/.reasonix/sessions/abc.transcript-projection.json", |
| 106 | "/home/u/.reasonix/sessions/abc.conflicts.jsonl", |
| 107 | "/home/u/.reasonix/sessions/abc.recovery.json", |
| 108 | "/home/u/.reasonix/sessions/abc.context.json", |
| 109 | "/home/u/.reasonix/sessions/abc.pinned-context.json", |
| 110 | } |
| 111 | if len(got) != len(want) { |
| 112 | t.Fatalf("SessionSidecarFiles = %v, want %v", got, want) |
| 113 | } |
| 114 | for i := range want { |
| 115 | if got[i] != want[i] { |
| 116 | t.Errorf("SessionSidecarFiles[%d] = %q, want %q", i, got[i], want[i]) |
| 117 | } |
| 118 | } |
| 119 | if SessionSidecarFiles("") != nil { |
| 120 | t.Error("SessionSidecarFiles(\"\") should be nil") |
| 121 | } |
| 122 | } |
| 123 |