返回 DeepSeek-Reasonix
interject_test.go
根目录 / internal / cli / interject_test.go
1 package cli
2
3 import (
4 "testing"
5
6 tea "charm.land/bubbletea/v2"
7
8 "reasonix/internal/control"
9 "reasonix/internal/event"
10 )
11
12 func TestInterjectQueuesWhileRunningWithoutOverwrite(t *testing.T) {
13 m := newTestChatTUI()
14 m.state = tuiRunning
15
16 m.input.SetValue("first")
17 m0, _ := m.update(tea.KeyPressMsg{Code: tea.KeyEnter})
18 m = m0.(chatTUI)
19
20 m.input.SetValue("second")
21 m0, _ = m.update(tea.KeyPressMsg{Code: tea.KeyEnter})
22 m = m0.(chatTUI)
23
24 m.input.SetValue("")
25 m0, _ = m.update(tea.KeyPressMsg{Code: tea.KeyEnter})
26 m = m0.(chatTUI)
27
28 if want := []string{"first", "second"}; len(m.pendingInterject) != len(want) ||
29 m.pendingInterject[0] != want[0] || m.pendingInterject[1] != want[1] {
30 t.Fatalf("pendingInterject = %v, want %v (second must not overwrite first; empty must not queue)", m.pendingInterject, want)
31 }
32 if m.state != tuiRunning {
33 t.Fatalf("queuing input must not change state; got %v", m.state)
34 }
35 }
36
37 func TestInterjectDequeuesFrontOnTurnDone(t *testing.T) {
38 r := &blockingTurnRunner{started: make(chan struct{})}
39 ctrl := control.New(control.Options{Runner: r, Sink: event.Discard, SessionDir: t.TempDir(), Label: "test"})
40 m := newChatTUI(ctrl, "", make(chan event.Event, 8), 80)
41 m.state = tuiRunning
42 m.pendingInterject = []string{"first", "second"}
43
44 m0, _ := m.update(agentEventMsg(event.Event{Kind: event.TurnDone}))
45 m = m0.(chatTUI)
46
47 if len(m.pendingInterject) != 1 || m.pendingInterject[0] != "second" {
48 t.Fatalf("TurnDone should dequeue only the front; got %v", m.pendingInterject)
49 }
50 }
51
51 lines GO