|
| 1 | +# Tencent is pleased to support the open source community by making tRPC-Agent-Python available. |
| 2 | +# |
| 3 | +# Copyright (C) 2026 Tencent. All rights reserved. |
| 4 | +# |
| 5 | +# tRPC-Agent-Python is licensed under Apache-2.0. |
| 6 | +"""Tests for the Finding model, dedup and confidence gating.""" |
| 7 | +from review.findings import Finding, dedupe, gate, severity_distribution |
| 8 | + |
| 9 | + |
| 10 | +def make(severity="high", category="security", file="a.py", line=1, |
| 11 | + confidence=0.9, source="static", title="t"): |
| 12 | + return Finding(severity=severity, category=category, file=file, line=line, |
| 13 | + title=title, confidence=confidence, source=source) |
| 14 | + |
| 15 | + |
| 16 | +def test_dedup_same_file_line_category(): |
| 17 | + kept, dropped = dedupe([make(title="eval"), make(title="exec", confidence=0.8)]) |
| 18 | + assert len(kept) == 1 and len(dropped) == 1 |
| 19 | + assert kept[0].confidence == 0.9 |
| 20 | + |
| 21 | + |
| 22 | +def test_dedup_merges_sources(): |
| 23 | + kept, _ = dedupe([make(source="static"), make(source="llm", confidence=0.7)]) |
| 24 | + assert kept[0].source == "static+llm" |
| 25 | + |
| 26 | + |
| 27 | +def test_dedup_keeps_highest_severity(): |
| 28 | + kept, _ = dedupe([make(severity="medium"), make(severity="critical", confidence=0.5)]) |
| 29 | + assert kept[0].severity == "critical" |
| 30 | + |
| 31 | + |
| 32 | +def test_no_dedup_across_lines(): |
| 33 | + kept, dropped = dedupe([make(line=1), make(line=2)]) |
| 34 | + assert len(kept) == 2 and dropped == [] |
| 35 | + |
| 36 | + |
| 37 | +def test_gate_splits_low_confidence(): |
| 38 | + reported, needs = gate([make(confidence=0.9), make(line=2, confidence=0.5)]) |
| 39 | + assert len(reported) == 1 and len(needs) == 1 |
| 40 | + assert needs[0].confidence == 0.5 |
| 41 | + |
| 42 | + |
| 43 | +def test_severity_distribution(): |
| 44 | + dist = severity_distribution([make(), make(line=2, severity="low")]) |
| 45 | + assert dist == {"high": 1, "low": 1} |
0 commit comments