@@ -52,7 +52,7 @@ func (m *mockSubagentRunner) recordedCalls() []delegateCall {
5252}
5353
5454func TestDelegateTool_Metadata (t * testing.T ) {
55- tool := NewDelegateTool (& mockSubagentRunner {})
55+ tool := NewDelegateTool (& mockSubagentRunner {}, [] string { "explorer" , "implementer" } )
5656
5757 if tool .Name () != "delegate_task" {
5858 t .Fatalf ("Name() = %q, want %q" , tool .Name (), "delegate_task" )
@@ -63,7 +63,7 @@ func TestDelegateTool_Metadata(t *testing.T) {
6363}
6464
6565func TestDelegateTool_InputSchema (t * testing.T ) {
66- tool := NewDelegateTool (& mockSubagentRunner {})
66+ tool := NewDelegateTool (& mockSubagentRunner {}, [] string { "explorer" , "implementer" } )
6767 schema := tool .InputSchema ()
6868
6969 if schema ["type" ] != "object" {
@@ -95,11 +95,15 @@ func TestDelegateTool_InputSchema(t *testing.T) {
9595 if _ , ok := itemProperties ["timeout_seconds" ]; ok {
9696 t .Fatal ("item properties should not include timeout_seconds" )
9797 }
98+ agent := itemProperties ["agent" ].(map [string ]any )
99+ if ! reflect .DeepEqual (agent ["enum" ], []string {"explorer" , "implementer" }) {
100+ t .Fatalf ("agent enum = %#v, want [explorer implementer]" , agent ["enum" ])
101+ }
98102}
99103
100104func TestDelegateTool_ExecutePassesTasksToRunner (t * testing.T ) {
101105 runner := & mockSubagentRunner {result : map [string ]any {"status" : "completed" }}
102- tool := NewDelegateTool (runner )
106+ tool := NewDelegateTool (runner , [] string { "explorer" , "implementer" } )
103107
104108 result , err := tool .Execute (context .Background (), delegateTasks (
105109 map [string ]any {"agent" : "explorer" , "task" : "Inspect internal/tools." },
@@ -133,7 +137,7 @@ func TestDelegateTool_ExecutePassesTasksToRunner(t *testing.T) {
133137
134138func TestDelegateTool_AssignsPerAgentInstancePositions (t * testing.T ) {
135139 runner := & mockSubagentRunner {}
136- tool := NewDelegateTool (runner )
140+ tool := NewDelegateTool (runner , [] string { "explorer" , "implementer" } )
137141 _ , err := tool .Execute (context .Background (), delegateTasks (
138142 map [string ]any {"agent" : "explorer" , "task" : "inspect" },
139143 map [string ]any {"agent" : "implementer" , "task" : "one" },
@@ -168,7 +172,7 @@ func TestDelegateTool_ExecuteRunsTasksInParallel(t *testing.T) {
168172 started : make (chan struct {}, taskCount ),
169173 release : make (chan struct {}),
170174 }
171- tool := NewDelegateTool (runner )
175+ tool := NewDelegateTool (runner , [] string { "explorer" , "implementer" } )
172176 done := make (chan error , 1 )
173177
174178 go func () {
@@ -199,7 +203,7 @@ func TestDelegateTool_ExecuteReturnsPerTaskErrors(t *testing.T) {
199203 result : map [string ]any {"status" : "error" },
200204 err : wantErr ,
201205 }
202- tool := NewDelegateTool (runner )
206+ tool := NewDelegateTool (runner , [] string { "explorer" , "implementer" } )
203207
204208 result , err := tool .Execute (context .Background (), delegateTasks (
205209 map [string ]any {"agent" : "explorer" , "task" : "Inspect docs." },
@@ -241,12 +245,13 @@ func TestDelegateTool_ValidateInputRejectsInvalidInput(t *testing.T) {
241245 {name : "too many tasks" , input : map [string ]any {"tasks" : tooMany }, wantErr : "at most 10 tasks" },
242246 {name : "missing agent" , input : delegateTasks (map [string ]any {"task" : "Inspect docs." }), wantErr : "tasks[0].agent" },
243247 {name : "missing task" , input : delegateTasks (map [string ]any {"agent" : "explorer" }), wantErr : "tasks[0].task" },
248+ {name : "unknown agent" , input : delegateTasks (map [string ]any {"agent" : "reviewer" , "task" : "Review changes." }), wantErr : "must be one of: explorer, implementer" },
244249 }
245250
246251 for _ , tt := range tests {
247252 t .Run (tt .name , func (t * testing.T ) {
248253 runner := & mockSubagentRunner {}
249- tool := NewDelegateTool (runner )
254+ tool := NewDelegateTool (runner , [] string { "explorer" , "implementer" } )
250255
251256 err := tool .ValidateInput (context .Background (), tt .input )
252257 if err == nil {
@@ -262,8 +267,23 @@ func TestDelegateTool_ValidateInputRejectsInvalidInput(t *testing.T) {
262267 }
263268}
264269
270+ func TestDelegateTool_ExecuteRejectsUnknownAgent (t * testing.T ) {
271+ runner := & mockSubagentRunner {}
272+ tool := NewDelegateTool (runner , []string {"explorer" })
273+
274+ _ , err := tool .Execute (context .Background (), delegateTasks (
275+ map [string ]any {"agent" : "reviewer" , "task" : "Review changes." },
276+ ))
277+ if err == nil || ! strings .Contains (err .Error (), "must be one of: explorer" ) {
278+ t .Fatalf ("Execute() error = %v, want unknown-agent validation error" , err )
279+ }
280+ if len (runner .recordedCalls ()) != 0 {
281+ t .Fatal ("runner should not be called for an unknown agent" )
282+ }
283+ }
284+
265285func TestDelegateTool_ExecuteRejectsMissingRunner (t * testing.T ) {
266- tool := NewDelegateTool (nil )
286+ tool := NewDelegateTool (nil , [] string { "explorer" } )
267287
268288 _ , err := tool .Execute (context .Background (), delegateTasks (
269289 map [string ]any {"agent" : "explorer" , "task" : "Inspect docs." },
0 commit comments