TestStaleStreamCloseDoesNotKillLiveTurn: the prior turn's channel closing after a fresh submit must NOT run handleStreamClosed against the live turn. Doing so would (a) nil out m.stream, breaking the live read loop, and (b) finalizeTurn + endTurn the current request out from under the user.
(t *testing.T)
| 2613 | om = out.(Model) |
| 2614 | if om.sessionTokens != 100 { |
| 2615 | t.Fatalf("stale EventDone credited tokens to session: %d", om.sessionTokens) |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | // TestHandleStreamClosedSkipsAdvanceAfterCancel: after Ctrl+C leaves phase=idle, |
| 2620 | // the deferred streamClosedMsg must not auto-restart a turn (the agent re- |
| 2621 | // entering chat after a stop would surprise the user). No history mutation. |
| 2622 | func TestHandleStreamClosedSkipsAdvanceAfterCancel(t *testing.T) { |
| 2623 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 2624 | m.phase = phaseIdle // handleCtrlC already finalised |
| 2625 | m.history = []chmctx.Message{{Role: chmctx.RoleUser, Content: "earlier"}} |
| 2626 | before := len(m.history) |
| 2627 | |
| 2628 | out, cmd := m.handleStreamClosed() |
| 2629 | om := out.(Model) |
| 2630 | if cmd != nil { |
| 2631 | t.Fatal("stale close after cancel must NOT return a new-turn Cmd") |
| 2632 | } |
| 2633 | if len(om.history) != before { |
| 2634 | t.Fatalf("stale close after cancel must not mutate history, grew by %d", len(om.history)-before) |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | // TestStaleStreamEventDoesNotMutateLiveTurn: after Ctrl+C kills turn 1 and the |
| 2639 | // user submits turn 2, turn 1's readEvent Cmd can still fire (buffered channel |
| 2640 | // or producer not yet exited). That stale event must not write turn 2's |
nothing calls this directly
no test coverage detected