(t *testing.T)
| 1834 | } |
| 1835 | |
| 1836 | func TestPermissions_DenyBlocksToolExecution(t *testing.T) { |
| 1837 | t.Parallel() |
| 1838 | |
| 1839 | // Test that tools matching deny patterns are blocked |
| 1840 | permChecker := permissions.NewChecker(&latest.PermissionsConfig{ |
| 1841 | Deny: []string{"dangerous_tool"}, |
| 1842 | }) |
| 1843 | |
| 1844 | prov := &mockProvider{id: "test/mock-model", stream: &mockStream{}} |
| 1845 | root := agent.New("root", "You are a test agent", agent.WithModel(prov)) |
| 1846 | tm := team.New( |
| 1847 | team.WithAgents(root), |
| 1848 | team.WithPermissions(permChecker), |
| 1849 | ) |
| 1850 | |
| 1851 | rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{})) |
| 1852 | require.NoError(t, err) |
| 1853 | |
| 1854 | sess := session.New(session.WithUserMessage("Test")) |
| 1855 | |
| 1856 | // Create a tool call for the denied tool |
| 1857 | calls := []tools.ToolCall{{ |
| 1858 | ID: "call_1", |
| 1859 | Type: "function", |
| 1860 | Function: tools.FunctionCall{Name: "dangerous_tool", Arguments: "{}"}, |
| 1861 | }} |
| 1862 | |
| 1863 | // Define a tool that exists |
| 1864 | agentTools := []tools.Tool{{ |
| 1865 | Name: "dangerous_tool", |
| 1866 | Parameters: map[string]any{}, |
| 1867 | Handler: func(ctx context.Context, tc tools.ToolCall) (*tools.ToolCallResult, error) { |
| 1868 | return tools.ResultSuccess("executed"), nil |
| 1869 | }, |
| 1870 | }} |
| 1871 | |
| 1872 | events := make(chan Event, 10) |
| 1873 | rt.processToolCalls(t.Context(), sess, calls, agentTools, NewChannelSink(events)) |
| 1874 | close(events) |
| 1875 | |
| 1876 | // The tool should be denied, look for a ToolCallResponseEvent with error |
| 1877 | var toolResponse *ToolCallResponseEvent |
| 1878 | for ev := range events { |
| 1879 | if tr, ok := ev.(*ToolCallResponseEvent); ok { |
| 1880 | toolResponse = tr |
| 1881 | break |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | require.NotNil(t, toolResponse, "expected ToolCallResponseEvent") |
| 1886 | require.Contains(t, toolResponse.Response, "denied by permissions") |
| 1887 | } |
| 1888 | |
| 1889 | func TestPermissions_AllowAutoApprovesTool(t *testing.T) { |
| 1890 | t.Parallel() |
nothing calls this directly
no test coverage detected