TestPackDropsDanglingPartialParallelGroup: cancelling a parallel round after only some results return leaves assistant(c1,c2)+tool(c1). The assistant has an unanswered call (c2), so it must be dropped, and dropOrphanTools must then clean up the now-orphaned tool(c1).
(t *testing.T)
| 306 | // no tool(c1): the user Ctrl+C'd before it finished |
| 307 | {Role: RoleUser, Content: "actually, do this instead"}, |
| 308 | } |
| 309 | r := Pack(history, 100000) |
| 310 | for _, m := range r.Messages { |
| 311 | if m.Role == RoleAssistant && len(m.ToolCalls) > 0 { |
| 312 | t.Fatalf("dangling assistant.tool_calls survived pack: %+v", r.Messages) |
| 313 | } |
| 314 | } |
| 315 | // Both user messages must remain, only the unpaired assistant is dropped. |
| 316 | if len(r.Messages) != 2 { |
| 317 | t.Fatalf("want 2 user messages kept, got %d: %+v", len(r.Messages), r.Messages) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // TestPackDropsDanglingPartialParallelGroup: cancelling a parallel round after |
| 322 | // only some results return leaves assistant(c1,c2)+tool(c1). The assistant has |
| 323 | // an unanswered call (c2), so it must be dropped, and dropOrphanTools must then |
| 324 | // clean up the now orphaned tool(c1). |
| 325 | func TestPackDropsDanglingPartialParallelGroup(t *testing.T) { |
| 326 | history := []Message{ |
| 327 | {Role: RoleUser, Content: "do two things"}, |
| 328 | {Role: RoleAssistant, ToolCalls: []ToolCall{ |
| 329 | {ID: "c1", Name: "bash"}, {ID: "c2", Name: "bash"}, |