Add RecentSessions reader over the audit chain
Exposes the last n session summaries (oldest-first) for the reviewer to read as recent-history context. Missing/empty chain or n<=0 yields nil. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,3 +75,45 @@ func TestTamperDetected(t *testing.T) {
|
||||
t.Fatalf("tamper on line 2 should be reported, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecentSessionsReturnsLastNOldestFirst(t *testing.T) {
|
||||
path := auditFixture(t)
|
||||
for _, id := range []string{"a", "b", "c"} {
|
||||
if err := AppendSession(path, sampleSummary("session-"+id)); err != nil {
|
||||
t.Fatalf("append %s: %v", id, err)
|
||||
}
|
||||
}
|
||||
got, err := RecentSessions(path, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("recent: %v", err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("want 2 summaries, got %d", len(got))
|
||||
}
|
||||
if got[0].SessionID != "session-b" || got[1].SessionID != "session-c" {
|
||||
t.Fatalf("want [b c] oldest-first, got [%s %s]", got[0].SessionID, got[1].SessionID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecentSessionsFewerThanN(t *testing.T) {
|
||||
path := auditFixture(t)
|
||||
_ = AppendSession(path, sampleSummary("session-a"))
|
||||
got, err := RecentSessions(path, 5)
|
||||
if err != nil {
|
||||
t.Fatalf("recent: %v", err)
|
||||
}
|
||||
if len(got) != 1 || got[0].SessionID != "session-a" {
|
||||
t.Fatalf("want [a], got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecentSessionsMissingOrZero(t *testing.T) {
|
||||
if got, err := RecentSessions(auditFixture(t), 5); err != nil || got != nil {
|
||||
t.Fatalf("missing chain: want (nil,nil), got (%+v,%v)", got, err)
|
||||
}
|
||||
path := auditFixture(t)
|
||||
_ = AppendSession(path, sampleSummary("session-a"))
|
||||
if got, err := RecentSessions(path, 0); err != nil || got != nil {
|
||||
t.Fatalf("n=0: want (nil,nil), got (%+v,%v)", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user