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

Function TestGetAnnotations

pkg/tools/annotations_test.go:200–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198func (m *mockToolWithoutAnnotations) Prompt() string { return "mock prompt" }
199
200func 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
237func TestIsToolSafeForAutoApproval(t *testing.T) {
238 safeTool := &mockToolWithAnnotations{name: "safe", annotations: AnnotationsSafeReadOnly}

Callers

nothing calls this directly

Calls 3

GetAnnotationsFunction · 0.85
IsSafeForAutoApprovalMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected