TestSessionTokensSurviveFinalizeTurn: finalizeTurn clears turnTokens but must NOT touch sessionTokens. turnStart must be set or finalizeTurn no-ops.
(t *testing.T)
| 1678 | // TestSessionTokensAccumulateAcrossTurns: the session counter is separate |
| 1679 | // from the per-turn counter. finalizeTurn resets turnTokens; sessionTokens |
| 1680 | // keeps growing for the rest of the session. |
| 1681 | func TestSessionTokensAccumulateAcrossTurns(t *testing.T) { |
| 1682 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 1683 | // Simulate three Done events. phase must be active or handleStream will |
| 1684 | // (correctly) drop events as stale post-cancel buffer: EventDone does |
| 1685 | // not move phase, so we seed streaming once and let each Done carry |
| 1686 | // through. |
| 1687 | m.phase = phaseStreaming |
| 1688 | for _, n := range []int{7, 13, 22} { |
| 1689 | out, _ := m.handleStream(llm.Event{Kind: llm.EventDone, Tokens: n}) |
| 1690 | m = out.(Model) |
| 1691 | } |
| 1692 | if m.sessionTokens != 7+13+22 { |
| 1693 | t.Fatalf("session counter should sum all Done events: got %d, want %d", |
| 1694 | m.sessionTokens, 7+13+22) |
| 1695 | } |
| 1696 | if m.turnTokens != 7+13+22 { |
| 1697 | // Without a streamClosedMsg between events, turnTokens keeps summing |
| 1698 | // too, verifying the two counters are in lockstep before finalize. |
nothing calls this directly
no test coverage detected