test(v0.4): cover SummarizeFromDiff and FormatLaunchContext
This commit is contained in:
@@ -107,3 +107,65 @@ func TestReadSummaryCorruptReturnsError(t *testing.T) {
|
||||
t.Error("expected error reading corrupt summary")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarizeFromDiff(t *testing.T) {
|
||||
start := time.Date(2026, 4, 21, 14, 30, 22, 0, time.UTC)
|
||||
end := start.Add(90 * time.Second)
|
||||
|
||||
diff := &ManifestDiff{
|
||||
Added: []string{"output/result.md"},
|
||||
Modified: []string{"notes.md"},
|
||||
Deleted: []string{},
|
||||
}
|
||||
endManifest := &Manifest{
|
||||
CapturedAt: end,
|
||||
Files: []FileEntry{
|
||||
{Path: "notes.md", Size: 200, Mtime: end},
|
||||
{Path: "output/result.md", Size: 100, Mtime: end},
|
||||
},
|
||||
}
|
||||
|
||||
s := SummarizeFromDiff("sid", "host", "claude", "local", start, end, diff, endManifest)
|
||||
|
||||
if s.DurationSeconds != 90 {
|
||||
t.Errorf("DurationSeconds: got %d, want 90", s.DurationSeconds)
|
||||
}
|
||||
if !s.NotesUpdated {
|
||||
t.Error("NotesUpdated should be true")
|
||||
}
|
||||
if len(s.EndManifest) != 2 {
|
||||
t.Errorf("EndManifest length: got %d, want 2", len(s.EndManifest))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatLaunchContextNilReturnsEmpty(t *testing.T) {
|
||||
if got := FormatLaunchContext(nil); got != "" {
|
||||
t.Errorf("expected empty string for nil summary, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatLaunchContextRendersChanged(t *testing.T) {
|
||||
start := time.Date(2026, 4, 21, 14, 30, 22, 0, time.UTC)
|
||||
end := start.Add(1 * time.Hour)
|
||||
s := &SessionSummary{
|
||||
StartedAt: start,
|
||||
EndedAt: end,
|
||||
Hostname: "warren-desktop",
|
||||
Agent: "claude",
|
||||
FilesModified: []string{"notes.md"},
|
||||
FilesAdded: []string{"output/plan.md", "output/schema.sql", "output/notes.md"},
|
||||
}
|
||||
got := FormatLaunchContext(s)
|
||||
for _, want := range []string{
|
||||
"[ctask] Last session:",
|
||||
"warren-desktop",
|
||||
"claude",
|
||||
"Changed:",
|
||||
"notes.md",
|
||||
"(+2 more)",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("FormatLaunchContext missing %q in:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user