TestPackAnchorsTaskEvenWithSystemNudge: a long single turn evicts the sole user task, and a nudge (system) is the newest message. The system→user demotion must run AFTER anchorUserMessage, otherwise the demoted nudge masquerades as a surviving user message, anchorUserMessage no-ops, and the wire los
(t *testing.T)
| 568 | } |
| 569 | |
| 570 | // TestPackAnchorsTaskEvenWithSystemNudge: a long single turn evicts the sole user |
| 571 | // task, and a nudge (system) is the newest message. The system→user demotion must |
| 572 | // run AFTER anchorUserMessage, otherwise the demoted nudge masquerades as a |
| 573 | // surviving user message, anchorUserMessage no-ops, and the wire loses the |
| 574 | // original task. The real first user task must still be re-anchored. |
| 575 | func TestPackAnchorsTaskEvenWithSystemNudge(t *testing.T) { |
| 576 | big := strings.Repeat("x", 4*3000) |
| 577 | history := []Message{ |
| 578 | {Role: RoleUser, Content: "BUILD THE GALAXY"}, |
| 579 | {Role: RoleAssistant, Content: big}, |
| 580 | {Role: RoleAssistant, Content: big}, |
| 581 | {Role: RoleSystem, Content: "[Automated codehamr check] runaway self-check"}, |
| 582 | } |
| 583 | r := Pack(history, 5000) |
| 584 | var sawTask bool |
| 585 | for _, m := range r.Messages { |
| 586 | if m.Role == RoleSystem { |
| 587 | t.Fatalf("system nudge survived Pack: %+v", r.Messages) |
| 588 | } |
| 589 | if m.Role == RoleUser && m.Content == "BUILD THE GALAXY" { |
| 590 | sawTask = true |
| 591 | } |
| 592 | } |
| 593 | if !sawTask { |
| 594 | t.Fatalf("original task must stay anchored even when a nudge is the newest message: %+v", r.Messages) |