返回 DeepSeek-Reasonix
textsink_partial_test.go
根目录 / internal / agent / textsink_partial_test.go
1 package agent
2
3 import (
4 "strings"
5 "testing"
6
7 "reasonix/internal/event"
8 )
9
10 // TestTextSinkSkipsPartialDispatch probes the headless sink against the early
11 // (Partial) ToolDispatch the agent emits when a call begins streaming. The chat
12 // TUI skips it; if TextSink prints it too, every tool call shows a duplicate
13 // "-> name" line (the first with empty args) in piped / `reasonix run` output.
14 func TestTextSinkSkipsPartialDispatch(t *testing.T) {
15 var b strings.Builder
16 s := NewTextSink(&b, nil, 80)
17
18 s.Emit(event.Event{Kind: event.TurnStarted})
19 s.Emit(event.Event{Kind: event.ToolDispatch, Tool: event.Tool{ID: "c1", Name: "read_file", Partial: true}})
20 s.Emit(event.Event{Kind: event.ToolDispatch, Tool: event.Tool{ID: "c1", Name: "read_file", Args: `{"path":"a"}`}})
21 s.Emit(event.Event{Kind: event.ToolDispatch, Tool: event.Tool{ID: "c1", Name: "read_file", Args: `{"path":"a"}`, Refreshed: true}})
22
23 got := b.String()
24 if n := strings.Count(got, "-> read_file"); n != 1 {
25 t.Errorf("want exactly one dispatch line after partial/full/refresh, got %d:\n%q", n, got)
26 }
27 }
28
28 lines GO