返回 DeepSeek-Reasonix
compaction_test.go
根目录 / internal / cli / compaction_test.go
1 package cli
2
3 import (
4 "strings"
5 "testing"
6
7 "reasonix/internal/event"
8 )
9
10 // TestCompactionCardLines locks the finished-compaction card: a header naming
11 // the count and trigger, the summary under a gutter, and an archive line.
12 func TestCompactionCardLines(t *testing.T) {
13 lines := compactionCardLines(event.Compaction{
14 Trigger: "auto",
15 Messages: 12,
16 Summary: "## Goal\n- do X\n## Files & code\n- a.go edited",
17 Archive: "/tmp/arch/20260531.jsonl",
18 })
19
20 joined := strings.Join(lines, "\n")
21 if !strings.Contains(lines[0], "◆") {
22 t.Errorf("header should carry the card glyph, got %q", lines[0])
23 }
24 for _, want := range []string{"Context compacted", "12", "auto"} {
25 if !strings.Contains(lines[0], want) {
26 t.Errorf("header missing %q: %q", want, lines[0])
27 }
28 }
29 // Every summary line (and the archive line) sits under the "│" gutter.
30 for _, want := range []string{"│ ## Goal", "│ - do X", "│ - a.go edited", "│ archived /tmp/arch/20260531.jsonl"} {
31 if !strings.Contains(joined, want) {
32 t.Errorf("card missing gutter line %q in:\n%s", want, joined)
33 }
34 }
35 }
36
37 // TestCompactionCardLinesNoArchive omits the archive line when none was written.
38 func TestCompactionCardLinesNoArchive(t *testing.T) {
39 lines := compactionCardLines(event.Compaction{Trigger: "manual", Messages: 3, Summary: "- brief"})
40 if strings.Contains(strings.Join(lines, "\n"), "archived") {
41 t.Errorf("no archive path should mean no archive line: %v", lines)
42 }
43 if !strings.Contains(lines[0], "manual") {
44 t.Errorf("header should reflect the manual trigger: %q", lines[0])
45 }
46 }
47
47 lines GO