TestStaleToolResultDoesNotEnterLiveHistory: a bash result from cancelled turn N must not append to turn N+1's history (its unmatched tool_call_id would 400 the next /v1 request) and must not steal the live stream via startChat.
(t *testing.T)
| 2640 | m.sessionTokens = 50 |
| 2641 | |
| 2642 | out, _ := m.Update(streamEventMsg{ch: stale, e: llm.Event{Kind: llm.EventContent, Content: "ghost"}}) |
| 2643 | om := out.(Model) |
| 2644 | if om.streaming.Len() != 0 { |
| 2645 | t.Fatalf("stale content event leaked into live turn's streaming buffer: %q", om.streaming.String()) |
| 2646 | } |
| 2647 | if om.sessionTokens != 50 { |
| 2648 | t.Fatalf("stale event credited tokens to live session: %d", om.sessionTokens) |
| 2649 | } |
| 2650 | if om.stream != live { |
| 2651 | t.Fatal("stale event must not overwrite live m.stream") |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | // TestStaleStreamCloseDoesNotKillLiveTurn: the prior turn's channel closing |
| 2656 | // after a fresh submit must NOT run handleStreamClosed against the live turn. |
| 2657 | // Doing so would (a) nil out m.stream, breaking the live read loop, and |
| 2658 | // (b) finalizeTurn + endTurn the current request out from under the user. |
| 2659 | func TestStaleStreamCloseDoesNotKillLiveTurn(t *testing.T) { |
| 2660 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 2661 | stale := make(chan llm.Event) |
| 2662 | live := make(chan llm.Event, 1) |
| 2663 | ctx, cancel := context.WithCancel(context.Background()) |
| 2664 | t.Cleanup(cancel) |
| 2665 | m.turnCtx = ctx |
| 2666 | m.cancel = cancel |
| 2667 | m.stream = live |
| 2668 | m.phase = phaseStreaming |
| 2669 | |
| 2670 | out, _ := m.Update(streamClosedMsg{ch: stale}) |
| 2671 | om := out.(Model) |
| 2672 | if om.stream != live { |
| 2673 | t.Fatal("stale close must not overwrite m.stream - live read loop would die") |
| 2674 | } |
| 2675 | if !om.phase.active() { |
| 2676 | t.Fatalf("stale close finalised the live turn - phase is now %v", om.phase) |
| 2677 | } |
nothing calls this directly
no test coverage detected