(t *testing.T)
| 2199 | } |
| 2200 | |
| 2201 | func TestToolRejectionWithoutReason(t *testing.T) { |
| 2202 | t.Parallel() |
| 2203 | |
| 2204 | // Test that rejection without a reason still works |
| 2205 | agentTools := []tools.Tool{{ |
| 2206 | Name: "shell", |
| 2207 | Parameters: map[string]any{}, |
| 2208 | Handler: func(_ context.Context, _ tools.ToolCall) (*tools.ToolCallResult, error) { |
| 2209 | t.Fatal("tool should not be executed when rejected") |
| 2210 | return nil, nil |
| 2211 | }, |
| 2212 | }} |
| 2213 | |
| 2214 | prov := &mockProvider{id: "test/mock-model", stream: &mockStream{}} |
| 2215 | root := agent.New("root", "You are a test agent", |
| 2216 | agent.WithModel(prov), |
| 2217 | agent.WithToolSets(newStubToolSet(nil, agentTools, nil)), |
| 2218 | ) |
| 2219 | tm := team.New(team.WithAgents(root)) |
| 2220 | |
| 2221 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 2222 | require.NoError(t, err) |
| 2223 | |
| 2224 | sess := session.New(session.WithUserMessage("Test")) |
| 2225 | require.False(t, sess.ToolsApproved) // No --yolo |
| 2226 | |
| 2227 | calls := []tools.ToolCall{{ |
| 2228 | ID: "call_1", |
| 2229 | Type: "function", |
| 2230 | Function: tools.FunctionCall{Name: "shell", Arguments: "{}"}, |
| 2231 | }} |
| 2232 | |
| 2233 | events := make(chan Event, 10) |
| 2234 | |
| 2235 | // Run in goroutine since it will block waiting for confirmation |
| 2236 | go func() { |
| 2237 | rt.processToolCalls(t.Context(), sess, calls, agentTools, NewChannelSink(events)) |
| 2238 | close(events) |
| 2239 | }() |
| 2240 | |
| 2241 | // Wait for confirmation request and then reject without a reason |
| 2242 | var toolResponse *ToolCallResponseEvent |
| 2243 | for ev := range events { |
| 2244 | if _, ok := ev.(*ToolCallConfirmationEvent); ok { |
| 2245 | // Send rejection without a reason |
| 2246 | rt.resumeChan <- ResumeReject("") |
| 2247 | } |
| 2248 | if resp, ok := ev.(*ToolCallResponseEvent); ok { |
| 2249 | toolResponse = resp |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | require.NotNil(t, toolResponse, "expected a tool response event") |
| 2254 | require.True(t, toolResponse.Result.IsError, "expected tool result to be an error") |
| 2255 | require.Equal(t, "The user rejected the tool call.", toolResponse.Response) |
| 2256 | require.NotContains(t, toolResponse.Response, "Reason:") |
| 2257 | } |
| 2258 |
nothing calls this directly
no test coverage detected