Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/secfoo/storage/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/secfoo/web/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down
50 changes: 50 additions & 0 deletions tests/test_storage/test_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import sqlite3

import pytest

from secfoo.storage.repository import RunRepository


Expand Down Expand Up @@ -1117,3 +1119,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()
24 changes: 24 additions & 0 deletions tests/test_web/test_assessment_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading