MCPcopy Create free account
hub / github.com/astercloud/aster / TestDefaultToolSelector_SelectTools

Function TestDefaultToolSelector_SelectTools

pkg/tools/constraints_test.go:137–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestDefaultToolSelector_SelectTools(t *testing.T) {
138 selector := &DefaultToolSelector{}
139 ctx := context.Background()
140
141 // 创建模拟工具
142 allTools := []Tool{
143 &mockTool{name: "Read"},
144 &mockTool{name: "Write"},
145 &mockTool{name: "Bash"},
146 }
147
148 tests := []struct {
149 name string
150 constraints ToolConstraints
151 expectedCount int
152 expectedNames []string
153 }{
154 {
155 name: "no constraints",
156 constraints: &NoConstraints{},
157 expectedCount: 3,
158 },
159 {
160 name: "whitelist",
161 constraints: NewWhitelistConstraints([]string{"Read", "Write"}),
162 expectedCount: 2,
163 expectedNames: []string{"Read", "Write"},
164 },
165 {
166 name: "blacklist",
167 constraints: NewBlacklistConstraints([]string{"Bash"}),
168 expectedCount: 2,
169 expectedNames: []string{"Read", "Write"},
170 },
171 {
172 name: "required",
173 constraints: NewRequiredToolConstraints("Read"),
174 expectedCount: 1,
175 expectedNames: []string{"Read"},
176 },
177 }
178
179 for _, tt := range tests {
180 t.Run(tt.name, func(t *testing.T) {
181 selected, err := selector.SelectTools(ctx, allTools, tt.constraints)
182 if err != nil {
183 t.Fatalf("SelectTools failed: %v", err)
184 }
185
186 if len(selected) != tt.expectedCount {
187 t.Errorf("Expected %d tools, got %d", tt.expectedCount, len(selected))
188 }
189
190 if tt.expectedNames != nil {
191 names := make(map[string]bool)
192 for _, tool := range selected {
193 names[tool.Name()] = true
194 }

Callers

nothing calls this directly

Calls 6

SelectToolsMethod · 0.95
NewWhitelistConstraintsFunction · 0.85
NewBlacklistConstraintsFunction · 0.85
NameMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected