(t *testing.T)
| 198 | func (m *mockToolWithoutAnnotations) Prompt() string { return "mock prompt" } |
| 199 | |
| 200 | func TestGetAnnotations(t *testing.T) { |
| 201 | tests := []struct { |
| 202 | name string |
| 203 | tool Tool |
| 204 | expectedSafe bool |
| 205 | expectedRisk int |
| 206 | }{ |
| 207 | { |
| 208 | name: "tool with annotations", |
| 209 | tool: &mockToolWithAnnotations{name: "test", annotations: AnnotationsSafeReadOnly}, |
| 210 | expectedSafe: true, |
| 211 | expectedRisk: RiskLevelSafe, |
| 212 | }, |
| 213 | { |
| 214 | name: "tool without annotations", |
| 215 | tool: &mockToolWithoutAnnotations{name: "test"}, |
| 216 | expectedSafe: false, // 默认不安全 |
| 217 | expectedRisk: RiskLevelMedium, // 未知工具保守处理 |
| 218 | }, |
| 219 | } |
| 220 | |
| 221 | for _, tt := range tests { |
| 222 | t.Run(tt.name, func(t *testing.T) { |
| 223 | ann := GetAnnotations(tt.tool) |
| 224 | if ann == nil { |
| 225 | t.Fatal("GetAnnotations returned nil") |
| 226 | } |
| 227 | if ann.IsSafeForAutoApproval() != tt.expectedSafe { |
| 228 | t.Errorf("IsSafeForAutoApproval() = %v, want %v", ann.IsSafeForAutoApproval(), tt.expectedSafe) |
| 229 | } |
| 230 | if ann.RiskLevel != tt.expectedRisk { |
| 231 | t.Errorf("RiskLevel = %d, want %d", ann.RiskLevel, tt.expectedRisk) |
| 232 | } |
| 233 | }) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func TestIsToolSafeForAutoApproval(t *testing.T) { |
| 238 | safeTool := &mockToolWithAnnotations{name: "safe", annotations: AnnotationsSafeReadOnly} |
nothing calls this directly
no test coverage detected