Skip to content

Commit e806dad

Browse files
committed
test(agent): add maxHistory=1 compaction edge case
1 parent 13cd2f1 commit e806dad

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

agent/compact_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ func TestCompactHistory_EmptyHistory(t *testing.T) {
7474
}
7575
}
7676

77+
func TestCompactHistory_MaxHistoryOne(t *testing.T) {
78+
// maxHistory=1, keep=1/2=0, guard sets keep=1.
79+
// 5 messages → summary + 1 kept = 2.
80+
a := &Agent{maxHistory: 1}
81+
for i := range 5 {
82+
a.history = append(a.history, provider.NewTextMessage(
83+
provider.RoleUser, fmt.Sprintf("msg %d", i)))
84+
}
85+
a.compactHistory()
86+
87+
if len(a.history) != 2 {
88+
t.Fatalf("history len = %d, want 2 (summary + 1 kept)", len(a.history))
89+
}
90+
91+
last := a.history[1].Content[0].Text
92+
if last != "msg 4" {
93+
t.Errorf("last message = %q, want 'msg 4'", last)
94+
}
95+
}
96+
7797
func TestCompactHistory_ExactThreshold(t *testing.T) {
7898
a := &Agent{maxHistory: 40}
7999
for i := range 40 {

0 commit comments

Comments
 (0)