| 39 | } |
| 40 | |
| 41 | func 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 | |
| 65 | func TestEngine_DegradedFailsToReview(t *testing.T) { |
| 66 | // The only detector errors → no OK verdicts → degraded. |