fix(opencode_review): harden _synthesize_summary_fields (none-safe, dedupe emoji map)

This commit is contained in:
claude
2026-08-22 00:52:35 +00:00
parent e5a6e8923d
commit 66628aae8d
2 changed files with 50 additions and 11 deletions
+44
View File
@@ -905,3 +905,47 @@ def test_synthesize_test_coverage_missing_tests():
_, _, tc = oc._synthesize_summary_fields(
[], "+diff\n", changed_paths=["pilot/foo.py"])
assert "No tests for behavioral change" in tc
def test_synthesize_walkthrough_picks_peak_severity_per_path():
# Three findings on the same path, with mixed severities. The walkthrough
# headline should use the PEAK severity's emoji (critical = 🔴), not the
# lexicographic-first severity (low).
findings = [
{"path": "x.py", "line": 1, "severity": "low",
"problem": "minor nit"},
{"path": "x.py", "line": 5, "severity": "critical",
"problem": "sql injection"},
{"path": "x.py", "line": 9, "severity": "high",
"problem": "auth bypass"},
]
w, _, _ = oc._synthesize_summary_fields(findings, "")
assert len(w) == 1
line = w[0]
assert "`x.py`" in line
assert "🔴" in line # critical = 🔴
assert "🟡" not in line
assert "🔵" not in line
assert "sql injection" in line # critical finding's problem, not low's
def test_synthesize_summary_fields_none_findings_safe():
# Old code crashed in risk_verdict with `for f in findings:` on None.
# After the `findings = findings or []` guard, None behaves like [].
w, rv, tc = oc._synthesize_summary_fields(None, "")
assert isinstance(w, list)
assert rv.startswith("Low risk")
# walkthrough should fall through to the diff-derived path list — empty
# diff produces no lines, but no crash is the point.
assert tc == ""
def test_synthesize_walkthrough_empty_problem_does_not_crash():
# An empty `problem` should render as "`a.py` — emoji" with a trailing
# space, not raise. Regression guard for splitlines()[0][:80].strip().
findings = [{"path": "a.py", "line": 1,
"severity": "low", "problem": ""}]
w, _, _ = oc._synthesize_summary_fields(findings, "")
assert len(w) == 1
assert "`a.py`" in w[0]
assert "🔵" in w[0] # low severity emoji