fix(severity): extend badge label set + update SYSTEM_PROMPT

This commit is contained in:
claude
2026-08-22 00:06:22 +00:00
parent 23ec1bf74a
commit 0b295e2443
2 changed files with 19 additions and 3 deletions
+9 -2
View File
@@ -102,7 +102,7 @@ Output STRICT JSON only — no prose, no markdown fences. Shape:
{ {
"findings": [ "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)", "path": "file path exactly as it appears in the diff (`+++ b/` side)",
"line": <int, the NEW-file line number the issue is on, within the diff>, "line": <int, the NEW-file line number the issue is on, within the diff>,
"problem": "one line: what is wrong", "problem": "one line: what is wrong",
@@ -963,12 +963,19 @@ _SEVERITY_EMOJI = {
"nit": "", "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: def _severity_badge(severity: str) -> str:
"""Render the severity as emoji + uppercase label (e.g. ``🔴 [HIGH]``).""" """Render the severity as emoji + uppercase label (e.g. ``🔴 [HIGH]``)."""
sev = (severity or "").lower() sev = (severity or "").lower()
emoji = _SEVERITY_EMOJI.get(sev, "") 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}]" return f"{emoji} [{label}]"
+10 -1
View File
@@ -17,6 +17,7 @@ from ai_review import ( # noqa: E402
_last_balanced_json, _last_balanced_json,
_normalize_finding, _normalize_finding,
_render_collapsible_usage, _render_collapsible_usage,
_severity_badge,
build_user_prompt, build_user_prompt,
compute_attribution, compute_attribution,
findings_table, findings_table,
@@ -321,7 +322,7 @@ def test_inline_comment_body_severity_emoji_mapping():
("medium", "🟡 [MEDIUM]"), ("medium", "🟡 [MEDIUM]"),
("low", "🔵 [LOW]"), ("low", "🔵 [LOW]"),
("info", "⚪ [INFO]"), ("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 ("bogus", "⚪ [INFO]"), # unknown severity falls back to INFO
] ]
for sev, badge in cases: 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["trivial"] == ""
assert _SEVERITY_EMOJI["info"] == "" 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)