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 TestBuildToolRegistryGrepSelectionAndDefaults(t *testing.T) {
50 cwd := t.TempDir()
51
52 defaultRegistry := buildToolRegistry(Args{}, cwd, nil, false, false, false)
53 if _, ok := defaultRegistry["grep"]; !ok {
54 t.Fatal("default registry does not contain grep")
55 }
56 defaultSummaries := toolSummaries(defaultRegistry, Args{})
57 grepIndex := -1
58 for i, summary := range defaultSummaries {
59 if summary.Name == "grep" {
60 grepIndex = i
61 break
62 }
63 }
64 if grepIndex < 0 {
65 t.Fatal("default tool summaries do not contain grep")
66 }
67 if grepIndex == 0 || defaultSummaries[grepIndex-1].Name != "edit" {
68 t.Fatalf("grep summary order has predecessor %q, want edit", defaultSummaries[grepIndex-1].Name)
69 }
70
71 selected := buildToolRegistry(Args{Tools: []string{"grep"}}, 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["grep"].(*tools.GrepTool); !ok {
76 t.Fatalf("selected grep has type %T", selected["grep"])
77 }
78 if summaries := toolSummaries(selected, Args{Tools: []string{"grep"}}); len(summaries) != 1 || summaries[0].Name != "grep" {
79 t.Fatalf("selected summaries = %#v, want only grep", summaries)
80 }
81
82 noTools := buildToolRegistry(Args{NoTools: true}, cwd, nil, false, false, false)
83 if len(noTools) != 0 {
84 t.Fatalf("no-tools registry has %d tools", len(noTools))
85 }
86 if summaries := toolSummaries(noTools, Args{NoTools: true}); len(summaries) != 0 {
87 t.Fatalf("no-tools summaries = %#v", summaries)
88 }
89}