From 2562856c2e77de51c6a07323656358c48e896e6c Mon Sep 17 00:00:00 2001 From: Satyanarayana Vuppala Date: Sun, 15 Nov 2026 22:05:12 +0000 Subject: [PATCH 1/2] fix(responsible-ai): map each report rating to its own risk tier The Responsible AI badge was derived with `"high-risk" if rating == "high" else "moderate"`, so a system the skill rated Low showed as "moderate" risk on the Responsible AI page, the assessment page, the assessments list and `secfoo assessment show`. Found on a real run against openai/openai-quickstart-python: "Overall risk rating: Low", badge "moderate". A Critical rating would have been downgraded the same way, and an unparsable rating became a tier instead of "not rated". Map critical/high -> high-risk, medium -> moderate, low -> low-risk (green badge), anything else -> not rated. Tests cover every tier, the unknown rating, the coverage count, and the dashboard pages for a Low run. Co-Authored-By: Claude Fable 5.1 --- src/secfoo/storage/repository.py | 17 +++++++- src/secfoo/web/templating.py | 2 +- tests/test_storage/test_assessments.py | 49 ++++++++++++++++++++++++ tests/test_web/test_assessment_routes.py | 24 ++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src/secfoo/storage/repository.py b/src/secfoo/storage/repository.py index 959b5d6..a400fa0 100644 --- a/src/secfoo/storage/repository.py +++ b/src/secfoo/storage/repository.py @@ -122,6 +122,19 @@ def _now() -> str: return datetime.now(timezone.utc).isoformat() +# The skill's rubric (skills/definitions/responsible-ai-compliance.md) rates a +# system High / Medium / Low; the dashboard shows that as a risk tier. Each +# tier must map to its own badge: a Low-rated demo app and a Medium-rated +# eligibility system are not the same "moderate" risk, and an unparsable +# rating is "not rated", never a tier. +RESPONSIBLE_AI_RISK_BY_RATING = { + "critical": "high-risk", + "high": "high-risk", + "medium": "moderate", + "low": "low-risk", +} + + class RunRepository: def __init__(self, db_path: Path | None = None) -> None: ensure_store_dirs() @@ -703,9 +716,9 @@ def _responsible_ai_badges(self, assessment_id: int, status: str) -> tuple[str | if not path.exists(): return None, None rating = extract_overall_risk_rating(path.read_text(encoding="utf-8", errors="replace")) - if rating is None: + risk = RESPONSIBLE_AI_RISK_BY_RATING.get(rating or "") + if risk is None: return None, None - risk = "high-risk" if rating == "high" else "moderate" ra_status = "confirmed" if status == "completed" else "provisional" return risk, ra_status diff --git a/src/secfoo/web/templating.py b/src/secfoo/web/templating.py index a19045e..185585b 100644 --- a/src/secfoo/web/templating.py +++ b/src/secfoo/web/templating.py @@ -140,7 +140,7 @@ def ordered_skills() -> list: "blocked": "badge--error", } -_RESPONSIBLE_AI_RISK_BADGE = {"high-risk": "badge--error", "moderate": "badge--warning"} +_RESPONSIBLE_AI_RISK_BADGE = {"high-risk": "badge--error", "moderate": "badge--warning", "low-risk": "badge--success"} _RESPONSIBLE_AI_STATUS_BADGE = {"provisional": "badge--neutral", "confirmed": "badge--success"} diff --git a/tests/test_storage/test_assessments.py b/tests/test_storage/test_assessments.py index 718ab58..0bd751f 100644 --- a/tests/test_storage/test_assessments.py +++ b/tests/test_storage/test_assessments.py @@ -1,3 +1,4 @@ +import pytest from __future__ import annotations import sqlite3 @@ -1117,3 +1118,51 @@ def test_list_sast_findings_scoped_by_project(tmp_path): assert len(repo.list_sast_findings()) == 2 repo.close() repo.close() + + +@pytest.mark.parametrize( + "rating,expected", + [("Critical", "high-risk"), ("High", "high-risk"), ("Medium", "moderate"), ("Low", "low-risk")], +) +def test_responsible_ai_risk_tier_follows_the_report_rating(tmp_path, rating, expected): + """Every rating the skill can emit gets its own tier. Before this, a + Low-rated system showed as "moderate" because only High was mapped.""" + repo = _repo(tmp_path) + project_id = repo.upsert_project("id-1", "P1", "local") + assessment_id = repo.create_assessment(project_id=project_id, assessment_type="internal", status="ready") + run_uuid = repo.create_run( + project_id=project_id, skill_id="responsible-ai-compliance", skill_name="Responsible AI Compliance", + agent_id="claude", confluence_urls=[], assessment_id=assessment_id, + ) + report_path = tmp_path / "report.md" + report_path.write_text(f"# Report\n\n## Summary\n**Overall risk rating:** {rating}\n") + repo.complete_run( + run_uuid, status="success", exit_code=0, duration_seconds=1, report_path=str(report_path), + prompt_path=None, stderr_excerpt=None, + ) + assessment = repo.get_assessment(assessment_id) + assert assessment.responsible_ai_risk == expected + assert assessment.responsible_ai_status == "provisional" + assert repo.count_assessments_with_responsible_ai_risk() == 1 + repo.close() + + +def test_responsible_ai_unknown_rating_means_not_rated(tmp_path): + repo = _repo(tmp_path) + project_id = repo.upsert_project("id-1", "P1", "local") + assessment_id = repo.create_assessment(project_id=project_id, assessment_type="internal", status="ready") + run_uuid = repo.create_run( + project_id=project_id, skill_id="responsible-ai-compliance", skill_name="Responsible AI Compliance", + agent_id="claude", confluence_urls=[], assessment_id=assessment_id, + ) + report_path = tmp_path / "report.md" + report_path.write_text("# Report\n\n## Summary\n**Overall risk rating:** Severe\n") + repo.complete_run( + run_uuid, status="success", exit_code=0, duration_seconds=1, report_path=str(report_path), + prompt_path=None, stderr_excerpt=None, + ) + assessment = repo.get_assessment(assessment_id) + assert assessment.responsible_ai_risk is None + assert assessment.responsible_ai_status is None + assert repo.count_assessments_with_responsible_ai_risk() == 0 + repo.close() diff --git a/tests/test_web/test_assessment_routes.py b/tests/test_web/test_assessment_routes.py index 1357514..e0f90ac 100644 --- a/tests/test_web/test_assessment_routes.py +++ b/tests/test_web/test_assessment_routes.py @@ -562,6 +562,30 @@ def test_responsible_ai_page_shows_derived_risk(client, tmp_path): assert "provisional" in resp.text +def test_responsible_ai_page_shows_low_risk_for_a_low_rated_run(client, tmp_path): + """A Low rating is a green low-risk badge, not the amber "moderate" one.""" + project_id, assessment_id = _create_assessment() + repo = RunRepository() + run_uuid = repo.create_run( + project_id=project_id, skill_id="responsible-ai-compliance", skill_name="Responsible AI Compliance", + agent_id="claude", confluence_urls=[], assessment_id=assessment_id, + ) + report_path = tmp_path / "report.md" + report_path.write_text("# Responsible AI Compliance Report\n\n## Summary\n**Overall risk rating:** Low\n") + repo.complete_run( + run_uuid, status="success", exit_code=0, duration_seconds=1.0, report_path=str(report_path), + prompt_path=None, stderr_excerpt=None, + ) + repo.close() + + resp = client.get("/responsible-ai") + assert resp.status_code == 200 + assert 'badge--success">low-risk' in resp.text + assert "moderate" not in resp.text + detail = client.get(f"/assessments/{assessment_id}") + assert 'badge--success">low-risk' in detail.text + + def _row_order(html: str) -> list[str]: import re From e253352ea976374585214fbb64612f4fc88418ab Mon Sep 17 00:00:00 2001 From: Satyanarayana Vuppala Date: Sun, 15 Nov 2026 22:06:44 +0000 Subject: [PATCH 2/2] test: keep the __future__ import first in test_assessments.py Co-Authored-By: Claude Fable 5.1 --- tests/test_storage/test_assessments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_storage/test_assessments.py b/tests/test_storage/test_assessments.py index 0bd751f..cae345d 100644 --- a/tests/test_storage/test_assessments.py +++ b/tests/test_storage/test_assessments.py @@ -1,8 +1,9 @@ -import pytest from __future__ import annotations import sqlite3 +import pytest + from secfoo.storage.repository import RunRepository