| 112 | } |
| 113 | |
| 114 | func TestPackAlwaysKeepsNewest(t *testing.T) { |
| 115 | massive := strings.Repeat("z", 4*10000) |
| 116 | history := []Message{ |
| 117 | {Role: RoleUser, Content: "small"}, |
| 118 | {Role: RoleUser, Content: massive}, |
| 119 | } |
| 120 | r := Pack(history, 100) |
| 121 | if len(r.Messages) != 1 { |
| 122 | t.Fatalf("expected only newest kept, got %d", len(r.Messages)) |
| 123 | } |
| 124 | if r.Messages[0].Content != massive { |
| 125 | t.Fatal("newest should have been kept even if over budget") |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // TestPackDropsOrphanToolMessage: if budget-trimming cuts the assistant whose |
| 130 | // tool_calls spawned a tool message, that orphan must be dropped, else |