1package tui
2
3import (
4 "encoding/json"
5 "strings"
6 "testing"
7
8 "github.com/patriceckhart/zot/packages/provider"
9)
10
11func TestLiveToolOverlayRemainsAfterAssistantToolUse(t *testing.T) {
12 args := json.RawMessage(`{"command":"sleep 1"}`)
13 v := View{
14 Theme: Dark,
15 Messages: []provider.Message{
16 {
17 Role: provider.RoleAssistant,
18 Content: []provider.Content{
19 provider.ToolCallBlock{ID: "toolu_1", Name: "bash", Arguments: args},
20 },
21 },
22 },
23 ToolCalls: []ToolCallView{
24 {ID: "toolu_1", Name: "bash", Args: ShortArgs("bash", args), Done: false},
25 },
26 }
27
28 plain := stripANSI(strings.Join(v.Build(80), "\n"))
29 if !strings.Contains(plain, "bash sleep 1") {
30 t.Fatalf("live tool overlay disappeared after assistant tool_use was appended:\n%s", plain)
31 }
32}
33
34func TestLiveToolOverlayKeepsWritePreviewAfterArgsEnd(t *testing.T) {
35 args := json.RawMessage(`{"path":"/tmp/sample.ts","content":"export const n = 1\n"}`)
36 v := View{
37 Theme: Dark,
38 Messages: []provider.Message{
39 {
40 Role: provider.RoleAssistant,
41 Content: []provider.Content{
42 provider.ToolCallBlock{ID: "toolu_1", Name: "write", Arguments: args},
43 },
44 },
45 },
46 ToolCalls: []ToolCallView{
47 {
48 ID: "toolu_1",
49 Name: "write",
50 Args: ShortArgs("write", args),
51 Streaming: false,
52 RawJSONBuf: string(args),
53 LivePath: "/tmp/sample.ts",
54 },
55 },
56 }
57
58 plain := stripANSI(strings.Join(v.Build(80), "\n"))
59 if !strings.Contains(plain, "export const n = 1") {
60 t.Fatalf("write preview collapsed after tool args ended but before tool_result arrived:\n%s", plain)
61 }
62}
63
64func TestLiveToolOverlayHidesAfterToolResult(t *testing.T) {
65 args := json.RawMessage(`{"command":"sleep 1"}`)
66 v := View{
67 Theme: Dark,
68 Messages: []provider.Message{
69 {
70 Role: provider.RoleAssistant,
71 Content: []provider.Content{
72 provider.ToolCallBlock{ID: "toolu_1", Name: "bash", Arguments: args},
73 },
74 },
75 {
76 Role: provider.RoleTool,
77 Content: []provider.Content{
78 provider.ToolResultBlock{
79 CallID: "toolu_1",
80 Content: []provider.Content{provider.TextBlock{Text: "done"}},
81 },
82 },
83 },
84 },
85 ToolCalls: []ToolCallView{
86 {ID: "toolu_1", Name: "bash", Args: ShortArgs("bash", args), Result: "done", Done: true},
87 },
88 }
89
90 plain := stripANSI(strings.Join(v.BuildLive(80), "\n"))
91 if strings.Contains(plain, "bash sleep 1") {
92 t.Fatalf("live tool overlay still rendered after tool_result was appended:\n%s", plain)
93 }
94}