1package tui
2
3import (
4 "encoding/json"
5 "strings"
6 "testing"
7)
8
9func TestToolArgWidthDefault(t *testing.T) {
10 t.Setenv("ZUT_TOOL_ARG_WIDTH", "")
11 if got := toolArgWidth(); got != defaultToolArgWidth {
12 t.Fatalf("toolArgWidth() with unset env = %d, want %d", got, defaultToolArgWidth)
13 }
14}
15
16func TestToolArgWidthEnvOverride(t *testing.T) {
17 t.Setenv("ZUT_TOOL_ARG_WIDTH", "120")
18 if got := toolArgWidth(); got != 120 {
19 t.Fatalf("toolArgWidth() = %d, want 120", got)
20 }
21}
22
23func TestToolArgWidthIgnoresInvalid(t *testing.T) {
24 cases := []string{"nope", "0", "10", "501", "-5", "12.5"}
25 for _, c := range cases {
26 t.Setenv("ZUT_TOOL_ARG_WIDTH", c)
27 if got := toolArgWidth(); got != defaultToolArgWidth {
28 t.Fatalf("toolArgWidth() with %q = %d, want default %d", c, got, defaultToolArgWidth)
29 }
30 }
31}
32
33func TestShortArgsTruncatesAtDefaultWidth(t *testing.T) {
34 t.Setenv("ZUT_TOOL_ARG_WIDTH", "")
35 long := strings.Repeat("a", 200)
36 raw := json.RawMessage(`{"command":"` + long + `"}`)
37 got := ShortArgs("web_answer", raw)
38 if len(got) != defaultToolArgWidth {
39 t.Fatalf("ShortArgs length = %d, want %d (%q)", len(got), defaultToolArgWidth, got)
40 }
41 if !strings.HasSuffix(got, "...") {
42 t.Fatalf("ShortArgs should end with ellipsis, got %q", got)
43 }
44}
45
46func TestShortArgsRespectsWiderWidth(t *testing.T) {
47 t.Setenv("ZUT_TOOL_ARG_WIDTH", "120")
48 long := strings.Repeat("a", 200)
49 raw := json.RawMessage(`{"command":"` + long + `"}`)
50 got := ShortArgs("web_answer", raw)
51 if len(got) != 120 {
52 t.Fatalf("ShortArgs length = %d, want 120", len(got))
53 }
54}
55
56func TestShortArgsNoTruncationWhenShort(t *testing.T) {
57 t.Setenv("ZUT_TOOL_ARG_WIDTH", "120")
58 raw := json.RawMessage(`{"command":"short query"}`)
59 got := ShortArgs("web_answer", raw)
60 if got != "short query" {
61 t.Fatalf("ShortArgs = %q, want %q", got, "short query")
62 }
63}
64
65func TestShortArgsGlobShowsPatternAndDir(t *testing.T) {
66 t.Setenv("ZUT_TOOL_ARG_WIDTH", "")
67 if got := ShortArgs("glob", json.RawMessage(`{"pattern":"**/*.go"}`)); got != "**/*.go" {
68 t.Fatalf("ShortArgs glob = %q, want pattern", got)
69 }
70 if got := ShortArgs("glob", json.RawMessage(`{"pattern":"*.json","path":"configs"}`)); got != "*.json in configs" {
71 t.Fatalf("ShortArgs glob with dir = %q, want pattern plus dir", got)
72 }
73 if got := ShortArgs("glob", json.RawMessage(`{"pattern":"*.json","path":"."}`)); got != "*.json" {
74 t.Fatalf("ShortArgs glob with dot dir = %q, want bare pattern", got)
75 }
76}
77
78func TestQuestionToolSummary(t *testing.T) {
79 if got := ShortArgs("ask_user_question", json.RawMessage(`{"questions":[{}, {}, {}]}`)); got != "· 3 questions" {
80 t.Fatalf("summary: %q", got)
81 }
82}