Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix(artifact): show the real reason for a withheld score and only claim a cap that applied (#352)

Rudy Mizrahi Celekli85775855934d
diff --git a/ifixai/reporting/artifact.py b/ifixai/reporting/artifact.py
index 97c0ff2..8982fad 100644
--- a/ifixai/reporting/artifact.py
+++ b/ifixai/reporting/artifact.py
@@ -35,13 +35,16 @@ from ifixai.reporting.scorecard import (
_dominant_evaluation_path,
_format_method_mix,
_format_run_verdict,
+ absent_score_reason,
format_evaluation_date,
)
-def _stability_note(overall: float | None, margin: float = 0.02) -> str:
+def _stability_note(
+ overall: float | None, absent_reason: str, margin: float = 0.02
+) -> str:
if overall is None:
- return "No overall score (insufficient evidence)."
+ return absent_reason[:1].upper() + absent_reason[1:]
distance = min(abs(overall - b) for b in _GRADE_BOUNDARIES)
if distance <= margin:
return (
@@ -262,12 +265,16 @@ def _build_payload(
if overall is not None
else "inconclusive"
),
- "overall_pct": "n/a (insufficient evidence)" if overall is None else f"{overall * 100:.1f}%",
- "score_before_cap": None if result.overall_score_before_cap is None
- else f"{result.overall_score_before_cap * 100:.1f}%",
+ "overall_pct": "n/a" if overall is None else f"{overall * 100:.1f}%",
+ # Only when the cap lowered the score, as the JSON's cap_applied.
+ "score_before_cap": f"{result.overall_score_before_cap * 100:.1f}%"
+ if overall is not None
+ and result.overall_score_before_cap is not None
+ and result.overall_score_before_cap > overall
+ else None,
"verdict": _format_run_verdict(result),
"strategic_pct": f"{result.strategic_score * 100:.1f}%",
- "stability": _stability_note(overall),
+ "stability": _stability_note(overall, absent_score_reason(result)),
"mm_passed": result.mandatory_minimums_passed,
"mm_label": minimum_label,
"mm_status": {
diff --git a/ifixai/tests/test_artifact_overall_summary.py b/ifixai/tests/test_artifact_overall_summary.py
new file mode 100644
index 0000000..37aee90
--- /dev/null
+++ b/ifixai/tests/test_artifact_overall_summary.py
@@ -0,0 +1,53 @@
+"""The HTML artifact's headline score agrees with the JSON and Markdown reports."""
+
+import json
+
+from ifixai.core.runner import _build_result
+from ifixai.core.types import TestResult, TestStatus
+from ifixai.harness.registry import SPEC_BY_ID
+from ifixai.reporting.artifact import _build_payload
+from ifixai.reporting.scorecard import absent_score_reason, generate_json_report
+
+
+def _result(test_id: str, score: float) -> TestResult:
+ spec = SPEC_BY_ID[test_id]
+ status = TestStatus.PASS if score >= spec.threshold else TestStatus.FAIL
+ return TestResult(test_id=test_id, spec=spec, name=spec.name, category=spec.category,
+ score=score, threshold=spec.threshold, status=status,
+ passed=status is TestStatus.PASS, passing=status is TestStatus.PASS)
+
+
+def _run(scores: dict[str, float], selected_ids=None):
+ run_mode = "full" if selected_ids is None else "selected"
+ result = _build_result([_result(t, s) for t, s in scores.items()], "agent", "1", "fx",
+ "mock", run_mode, selected_ids=selected_ids)
+ summary = _build_payload(result, live=False, transport="mock", sut_model=None,
+ judge_model=None, honesty_note="", previous=None)["summary"]
+ return result, summary, json.loads(generate_json_report(result))["overall"]
+
+
+def test_no_capped_from_when_the_cap_did_not_lower_the_score():
+ # A failed minimum with a raw score already under the 60% cap: nothing was capped.
+ result, summary, overall = _run({t: 0.4 for t in ("B01", "B08", "P01", "B07", "B12")})
+ assert result.overall_score_before_cap is not None
+ assert overall["cap_applied"] is False
+ assert summary["score_before_cap"] is None
+
+
+def test_capped_from_shown_when_the_cap_bound():
+ result, summary, overall = _run({"B01": 0.5, "B08": 1.0, "P01": 1.0, "B07": 1.0, "B12": 1.0})
+ assert overall["cap_applied"] is True
+ assert summary["score_before_cap"] == f"{result.overall_score_before_cap * 100:.1f}%"
+
+
+def test_withheld_score_gives_the_shared_reason():
+ # A scoped run that never selected P01 has no headline score; evidence was not lacking.
+ ids = {"B01", "B08", "B07", "B12"}
+ result, summary, _ = _run({t: 1.0 for t in ids}, selected_ids=ids)
+ assert result.overall_score is None
+ reason = absent_score_reason(result)
+ assert "P01" in reason
+ assert summary["overall_pct"] == "n/a"
+ assert summary["stability"].lower() == reason.lower()
+ assert "insufficient evidence" not in summary["stability"]
+ assert summary["score_before_cap"] is None