fix(reporting): reject unpersisted findings

This commit is contained in:
Alex Schapiro 2026-09-04 20:24:25 +00:00
parent cdbb2ff4cf
commit 9eb3199d10
2 changed files with 21 additions and 3 deletions

View file

@ -407,14 +407,14 @@ class ReportState:
if agent_name:
report["agent_name"] = agent_name
if self.vulnerability_found_callback:
self.vulnerability_found_callback(report)
self.vulnerability_reports.append(report)
logger.info(f"Added vulnerability report: {report_id} - {title}")
posthog.finding(severity, cwe=cwe, is_cve=bool(cve))
scarf.finding(severity, cwe=cwe, is_cve=bool(cve))
if self.vulnerability_found_callback:
self.vulnerability_found_callback(report)
self.save_run_data()
return report_id

View file

@ -131,6 +131,24 @@ async def test_create_report_persists_new_fields(report_state: ReportState) -> N
assert report["http_exchange_ids"] == ["1042", "1088"]
def test_create_report_does_not_commit_when_callback_fails(
report_state: ReportState,
) -> None:
def fail_persistence(_report: dict[str, Any]) -> None:
raise RuntimeError("persistence failed")
report_state.vulnerability_found_callback = fail_persistence
with pytest.raises(RuntimeError, match="persistence failed"):
report_state.add_vulnerability_report(
title="Unstored finding",
severity="high",
http_exchange_ids=["1042"],
)
assert report_state.vulnerability_reports == []
async def test_create_report_requires_evidence_and_assumptions(
report_state: ReportState,
) -> None: