1package agent
2
3import (
4 "testing"
5
6 "github.com/bnema/zut/packages/agent/tools"
7)
8
9func TestBuildToolRegistryWebCapabilityBundle(t *testing.T) {
10 cwd := t.TempDir()
11 for _, tc := range []struct {
12 name string
13 args Args
14 want bool
15 }{
16 {name: "default", want: true},
17 {name: "explicit selector", args: Args{ToolsSet: true, Tools: []string{"web_search"}}, want: true},
18 {name: "excluded explicit list", args: Args{ToolsSet: true, Tools: []string{"read"}}, want: false},
19 {name: "no tools", args: Args{NoTools: true}, want: false},
20 } {
21 t.Run(tc.name, func(t *testing.T) {
22 registry := buildToolRegistry(tc.args, cwd, nil, false, false, false)
23 for _, name := range tools.WebCapabilityNames {
24 _, got := registry[name]
25 if got != tc.want {
26 t.Fatalf("tool %s present = %v, want %v", name, got, tc.want)
27 }
28 }
29 })
30 }
31}
32
33func TestBuildToolRegistryIncludesUpdatePlanByDefaultAndExplicitSelection(t *testing.T) {
34 cwd := t.TempDir()
35 defaultRegistry := buildToolRegistry(Args{}, cwd, nil, false, false, false)
36 if _, ok := defaultRegistry[tools.UpdatePlanToolName].(*tools.UpdatePlanTool); !ok {
37 t.Fatalf("default update_plan has type %T", defaultRegistry[tools.UpdatePlanToolName])
38 }
39
40 selected := buildToolRegistry(Args{Tools: []string{tools.UpdatePlanToolName}}, cwd, nil, false, false, false)
41 if len(selected) != 1 {
42 t.Fatalf("selected registry has %d tools, want one", len(selected))
43 }
44 if _, ok := selected[tools.UpdatePlanToolName].(*tools.UpdatePlanTool); !ok {
45 t.Fatalf("selected update_plan has type %T", selected[tools.UpdatePlanToolName])
46 }
47}
48
49func TestBuildToolRegistryGlobSelectionAndDefaults(t *testing.T) {
50 cwd := t.TempDir()
51
52 defaultRegistry := buildToolRegistry(Args{}, cwd, nil, false, false, false)
53 if _, ok := defaultRegistry["glob"].(*tools.GlobTool); !ok {
54 t.Fatalf("default glob has type %T", defaultRegistry["glob"])
55 }
56 defaultSummaries := toolSummaries(defaultRegistry, Args{})
57 globIndex := -1
58 for i, summary := range defaultSummaries {
59 if summary.Name == "glob" {
60 globIndex = i
61 break
62 }
63 }
64 if globIndex < 0 {
65 t.Fatal("default tool summaries do not contain glob")
66 }
67 if globIndex == 0 || defaultSummaries[globIndex-1].Name != "grep" {
68 t.Fatalf("glob summary order has predecessor %q, want grep", defaultSummaries[globIndex-1].Name)
69 }
70
71 selected := buildToolRegistry(Args{Tools: []string{"glob"}}, cwd, nil, false, false, false)
72 if len(selected) != 1 {
73 t.Fatalf("selected registry has %d tools, want one", len(selected))
74 }
75 if _, ok := selected["glob"].(*tools.GlobTool); !ok {
76 t.Fatalf("selected glob has type %T", selected["glob"])
77 }
78 if summaries := toolSummaries(selected, Args{Tools: []string{"glob"}}); len(summaries) != 1 || summaries[0].Name != "glob" {
79 t.Fatalf("selected summaries = %#v, want only glob", summaries)
80 }
81}
82
83func TestBuildToolRegistryGrepSelectionAndDefaults(t *testing.T) {
84 cwd := t.TempDir()
85
86 defaultRegistry := buildToolRegistry(Args{}, cwd, nil, false, false, false)
87 if _, ok := defaultRegistry["grep"]; !ok {
88 t.Fatal("default registry does not contain grep")
89 }
90 defaultSummaries := toolSummaries(defaultRegistry, Args{})
91 grepIndex := -1
92 for i, summary := range defaultSummaries {
93 if summary.Name == "grep" {
94 grepIndex = i
95 break
96 }
97 }
98 if grepIndex < 0 {
99 t.Fatal("default tool summaries do not contain grep")
100 }
101 if grepIndex == 0 || defaultSummaries[grepIndex-1].Name != "edit" {
102 t.Fatalf("grep summary order has predecessor %q, want edit", defaultSummaries[grepIndex-1].Name)
103 }
104
105 selected := buildToolRegistry(Args{Tools: []string{"grep"}}, cwd, nil, false, false, false)
106 if len(selected) != 1 {
107 t.Fatalf("selected registry has %d tools, want one", len(selected))
108 }
109 if _, ok := selected["grep"].(*tools.GrepTool); !ok {
110 t.Fatalf("selected grep has type %T", selected["grep"])
111 }
112 if summaries := toolSummaries(selected, Args{Tools: []string{"grep"}}); len(summaries) != 1 || summaries[0].Name != "grep" {
113 t.Fatalf("selected summaries = %#v, want only grep", summaries)
114 }
115
116 noTools := buildToolRegistry(Args{NoTools: true}, cwd, nil, false, false, false)
117 if len(noTools) != 0 {
118 t.Fatalf("no-tools registry has %d tools", len(noTools))
119 }
120 if summaries := toolSummaries(noTools, Args{NoTools: true}); len(summaries) != 0 {
121 t.Fatalf("no-tools summaries = %#v", summaries)
122 }
123}