TestQueueAutoSubmitsAfterTurn drives a full turn with a prompt queued mid-flight and asserts the queued prompt auto-fires a second request when the turn ends, then the slot is cleared. round==2 is the proof the follow-up actually ran.
(t *testing.T)
| 125 | // and asserts the queued prompt auto-fires a second request when the turn ends, |
| 126 | // then the slot is cleared. round==2 is the proof the follow-up actually ran. |
| 127 | func TestQueueAutoSubmitsAfterTurn(t *testing.T) { |
| 128 | var round int |
| 129 | var bodies []string |
| 130 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 131 | w.Header().Set("Content-Type", "text/event-stream") |
| 132 | round++ |
| 133 | buf, _ := io.ReadAll(r.Body) |
| 134 | bodies = append(bodies, string(buf)) |
| 135 | fmt.Fprintf(w, "data: %s\n\n", `{"choices":[{"delta":{"content":"reply"}}]}`) |
| 136 | fmt.Fprintf(w, "data: %s\n\n", `{"choices":[{"delta":{},"finish_reason":"stop"}],"usage":{"completion_tokens":1}}`) |
| 137 | fmt.Fprint(w, "data: [DONE]\n\n") |
| 138 | } |
| 139 | m := newTestModel(t, handler) |
| 140 | mm, cmd := m.submit("first", "first", promptEntry{display: "first"}) |
| 141 | // Queue a follow-up while the first turn is in flight (before draining it). |
| 142 | m2 := mm.(Model) |
| 143 | m2.queued = &queuedPrompt{send: "second please", echo: "second please"} |
| 144 | |
| 145 | out, _ := drain(m2, cmd) |
| 146 | final := out.(Model) |
| 147 | |
| 148 | if round != 2 { |
| 149 | t.Fatalf("queued prompt must auto-fire a second request, got %d round(s)", round) |
| 150 | } |
| 151 | if final.queued != nil { |
| 152 | t.Fatalf("slot must clear after auto-fire, got %+v", final.queued) |
| 153 | } |
| 154 | if !strings.Contains(strings.Join(bodies, ""), "second please") { |
| 155 | t.Fatalf("the queued prompt never reached the server:\n%s", strings.Join(bodies, "\n")) |
| 156 | } |
| 157 | if final.phase.active() { |
| 158 | t.Fatalf("both turns done → idle, got phase %v", final.phase) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // TestQueueRestoredOnCtrlC: a Ctrl+C abort never fires the queued prompt (the |
| 163 | // user took back control); it returns the text to the textarea as an editable |
nothing calls this directly
no test coverage detected