diff --git a/pilot/ai_review.py b/pilot/ai_review.py index 073da0e..37f5d50 100644 --- a/pilot/ai_review.py +++ b/pilot/ai_review.py @@ -102,7 +102,7 @@ Output STRICT JSON only — no prose, no markdown fences. Shape: { "findings": [ { - "severity": "critical|high|medium|low", + "severity": "critical|high|medium|low|trivial|info", "path": "file path exactly as it appears in the diff (`+++ b/` side)", "line": , "problem": "one line: what is wrong", @@ -963,12 +963,19 @@ _SEVERITY_EMOJI = { "nit": "⚪", } +# Severities whose own name is rendered verbatim (uppercased) in the badge. +# Anything outside this set falls back to "INFO" so the badge label stays +# a clean short token regardless of what the model emits. +_BADGED_SEVERITY_LABELS = frozenset({ + "critical", "high", "medium", "low", "trivial", "info", "nit", +}) + def _severity_badge(severity: str) -> str: """Render the severity as emoji + uppercase label (e.g. ``🔴 [HIGH]``).""" sev = (severity or "").lower() emoji = _SEVERITY_EMOJI.get(sev, "⚪") - label = sev.upper() if sev in {"critical", "high", "medium", "low"} else "INFO" + label = sev.upper() if sev in _BADGED_SEVERITY_LABELS else "INFO" return f"{emoji} [{label}]" diff --git a/tests/pilot/test_ai_review.py b/tests/pilot/test_ai_review.py index 3ab2231..d5e02dd 100644 --- a/tests/pilot/test_ai_review.py +++ b/tests/pilot/test_ai_review.py @@ -17,6 +17,7 @@ from ai_review import ( # noqa: E402 _last_balanced_json, _normalize_finding, _render_collapsible_usage, + _severity_badge, build_user_prompt, compute_attribution, findings_table, @@ -321,7 +322,7 @@ def test_inline_comment_body_severity_emoji_mapping(): ("medium", "🟡 [MEDIUM]"), ("low", "🔵 [LOW]"), ("info", "⚪ [INFO]"), - ("nit", "⚪ [INFO]"), # "nit" maps to the INFO label + ("nit", "⚪ [NIT]"), # legacy alias — renders with its own name ("bogus", "⚪ [INFO]"), # unknown severity falls back to INFO ] for sev, badge in cases: @@ -1746,3 +1747,11 @@ def test_emoji_for_trivial_and_info_is_neutral(): assert _SEVERITY_EMOJI["trivial"] == "⚪" assert _SEVERITY_EMOJI["info"] == "⚪" + +def test_severity_badge_labels_each_known_severity(): + # Trivial and info (and legacy nit) should render with their own name, + # not fall back to "INFO". + for sev in ("critical", "high", "medium", "low", "trivial", "info", "nit"): + badge = _severity_badge(sev) + assert f"[{sev.upper()}]" in badge, (sev, badge) +