Skip to content

Commit 66113ee

Browse files
committed
fix(report): preserve exact SARIF severity metadata (NVIDIA#229)
Signed-off-by: Rod Boev <[email protected]>
1 parent eb7d221 commit 66113ee

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/skillspector/nodes/report.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _build_sarif_properties(finding: Finding) -> dict[str, object] | None:
103103
"""Project selected finding metadata into a SARIF properties dictionary."""
104104
finding_dict = finding.to_dict()
105105
metadata: dict[str, object] = {
106+
"severity": finding_dict["severity"],
106107
"category": finding_dict["category"],
107108
"pattern": finding_dict["pattern"],
108109
"confidence": finding_dict["confidence"],

‎tests/nodes/test_report.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def test_report_output_format_sarif_includes_finding_properties(self) -> None:
526526
}
527527
result = report(state)
528528
result_row = result["sarif_report"]["runs"][0]["results"][0]
529+
assert result_row["properties"]["severity"] == "HIGH"
529530
assert result_row["properties"]["category"] == "environment"
530531
assert result_row["properties"]["pattern"] == r"os\.environ"
531532
assert result_row["properties"]["confidence"] == 0.85
@@ -611,6 +612,7 @@ def test_report_baseline_suppresses_finding_and_lowers_score() -> None:
611612
suppressed_result = sarif_results[0]
612613
assert suppressed_result["suppressions"][0]["kind"] == "external"
613614
assert suppressed_result["suppressions"][0]["justification"] == "false positive"
615+
assert suppressed_result["properties"]["severity"] == "CRITICAL"
614616
assert suppressed_result["properties"]["category"] == "critical_path"
615617
assert suppressed_result["properties"]["pattern"] == r"exec\("
616618
assert suppressed_result["properties"]["confidence"] == 1.0
@@ -743,3 +745,24 @@ def test_report_doc_findings_no_multiplier() -> None:
743745
# Without the multiplier: 2 HIGH = 50, not 65
744746
assert result["risk_score"] == 50
745747
assert result["risk_severity"] == "MEDIUM"
748+
749+
750+
def test_report_sarif_preserves_high_vs_critical_severity() -> None:
751+
"""HIGH and CRITICAL both map to SARIF error, but properties keep the exact severity."""
752+
state: SkillspectorState = {
753+
"filtered_findings": [
754+
_finding("R1", "HIGH", message="high finding", file="high.py"),
755+
_finding("R2", "CRITICAL", message="critical finding", file="critical.py"),
756+
],
757+
"component_metadata": [],
758+
"has_executable_scripts": False,
759+
"manifest": {},
760+
"skill_path": None,
761+
"output_format": "sarif",
762+
}
763+
results = report(state)["sarif_report"]["runs"][0]["results"]
764+
by_rule = {item["ruleId"]: item for item in results}
765+
assert by_rule["R1"]["level"] == "error"
766+
assert by_rule["R2"]["level"] == "error"
767+
assert by_rule["R1"]["properties"]["severity"] == "HIGH"
768+
assert by_rule["R2"]["properties"]["severity"] == "CRITICAL"

‎tests/nodes/test_sarif_rules_and_empty_findings.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def test_active_finding_metadata_in_properties(self) -> None:
176176
)
177177
sarif = _build_sarif([finding])
178178
result = sarif["runs"][0]["results"][0]
179+
assert result["properties"]["severity"] == "HIGH"
179180
assert result["properties"]["category"] == "network_security"
180181
assert result["properties"]["pattern"] == r"socket\.connect"
181182
assert result["properties"]["confidence"] == 0.77
@@ -207,6 +208,7 @@ def test_suppressed_finding_keeps_properties_and_suppression_marker(self) -> Non
207208
result = sarif["runs"][0]["results"][0]
208209
assert result["suppressions"][0]["kind"] == "external"
209210
assert result["suppressions"][0]["justification"] == "false positive"
211+
assert result["properties"]["severity"] == "HIGH"
210212
assert result["properties"]["category"] == "authn_security"
211213
assert result["properties"]["pattern"] == r"api[_-]?key"
212214
assert result["properties"]["confidence"] == 1.0

0 commit comments

Comments
 (0)