MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestEngine_WeightedAggregate

Function TestEngine_WeightedAggregate

internal/piguard/engine_test.go:41–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestEngine_WeightedAggregate(t *testing.T) {
42 d1 := &stubDetector{name: "a", result: okResult("a", 0.8, CategoryInjectionDirect)}
43 d2 := &stubDetector{name: "b", result: okResult("b", 0.4, CategoryObfuscation)}
44 eng := NewEngine(EngineConfig{Weights: map[string]float64{"a": 3, "b": 1}}, d1, d2)
45
46 agg := eng.Evaluate(context.Background(), Request{})
47 if agg.Degraded {
48 t.Fatalf("unexpected degraded")
49 }
50 // weighted avg = (3*0.8 + 1*0.4) / 4 = 0.7
51 if agg.Score < 0.69 || agg.Score > 0.71 {
52 t.Errorf("weighted score = %v, want ~0.7", agg.Score)
53 }
54 if !agg.Flagged {
55 t.Errorf("expected flagged")
56 }
57 if len(agg.Categories) != 2 {
58 t.Errorf("expected 2 categories, got %+v", agg.Categories)
59 }
60 if len(agg.PerDetector) != 2 {
61 t.Errorf("expected per-detector results retained")
62 }
63}
64
65func TestEngine_DegradedFailsToReview(t *testing.T) {
66 // The only detector errors → no OK verdicts → degraded.

Callers

nothing calls this directly

Calls 3

EvaluateMethod · 0.95
okResultFunction · 0.85
NewEngineFunction · 0.85

Tested by

no test coverage detected