TestHandleStreamClosedSkipsAdvanceAfterCancel: after Ctrl+C leaves phase=idle, the deferred streamClosedMsg must not auto-restart a turn (the agent re- entering chat after a stop would surprise the user). No history mutation.
(t *testing.T)
| 2568 | // populate m.pending, and credit a cancelled turn's usage to sessionTokens. |
| 2569 | // handleStream must drain-only. |
| 2570 | func TestHandleStreamDrainsAfterCancel(t *testing.T) { |
| 2571 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 2572 | m.phase = phaseIdle // post-cancel state |
| 2573 | m.sessionTokens = 100 |
| 2574 | |
| 2575 | out, _ := m.handleStream(llm.Event{Kind: llm.EventContent, Content: "ghost"}) |
| 2576 | om := out.(Model) |
| 2577 | if om.streaming.Len() != 0 { |
| 2578 | t.Fatalf("stale EventContent wrote to streaming: %q", om.streaming.String()) |
| 2579 | } |
| 2580 | out, _ = om.handleStream(llm.Event{Kind: llm.EventToolCall, ToolCall: &chmctx.ToolCall{ID: "c", Name: "bash"}}) |
| 2581 | om = out.(Model) |
| 2582 | if len(om.pending) != 0 { |
| 2583 | t.Fatalf("stale EventToolCall re-populated pending: %+v", om.pending) |
| 2584 | } |
| 2585 | out, _ = om.handleStream(llm.Event{Kind: llm.EventDone, Tokens: 50}) |
| 2586 | om = out.(Model) |
| 2587 | if om.sessionTokens != 100 { |
nothing calls this directly
no test coverage detected