Skip to content

Commit b45b4ee

Browse files
fix(cli): count post-suppression findings in recursive multi-skill report
The recursive summary table and combined JSON report computed finding_count as `filtered_findings or findings`, which falls through to the unfiltered findings when suppression empties filtered_findings, since an empty list is falsy. A fully baselined sub-skill then showed score 0 but a non-zero finding_count. Add _result_finding_count(), which falls back to raw findings only when filtered_findings is absent (the report node always sets it, possibly empty after suppression), and use it at both the summary table and the combined JSON report. Add a regression test asserting the combined JSON finding_count is 0 for a fully suppressed sub-skill. Surfaced by an independent review of NVIDIA#205. Refs NVIDIA#201 Signed-off-by: Werner Kasselman <[email protected]>
1 parent 3511351 commit b45b4ee

2 files changed

Lines changed: 67 additions & 5 deletions

File tree

‎src/skillspector/cli.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,21 @@ def _build_trace_config(input_path: str, format: FormatChoice, no_llm: bool) ->
365365
}
366366

367367

368+
def _result_finding_count(result: dict[str, object]) -> int:
369+
"""Count post-suppression findings, treating an empty filtered list as zero.
370+
371+
The report node always sets ``filtered_findings`` (possibly empty after
372+
baseline suppression), so fall back to the raw ``findings`` only when the
373+
filtered key is genuinely absent. A plain ``filtered or findings`` miscounts a
374+
fully-suppressed skill, since an empty list is falsy and the ``or`` then
375+
reports the unfiltered findings.
376+
"""
377+
filtered = result.get("filtered_findings")
378+
if filtered is None:
379+
filtered = result.get("findings")
380+
return len(filtered) if isinstance(filtered, list) else 0
381+
382+
368383
def _scan_multi_skill(
369384
detection: MultiSkillDetectionResult,
370385
format: FormatChoice,
@@ -419,8 +434,7 @@ def _scan_multi_skill(
419434
continue
420435
score = result.get("risk_score", 0)
421436
severity = result.get("risk_severity", "LOW")
422-
filtered = result.get("filtered_findings") or result.get("findings")
423-
finding_count = len(filtered) if isinstance(filtered, list) else 0
437+
finding_count = _result_finding_count(result)
424438
console.print(f" {skill.name:<30} {score:<8} {severity:<12} {finding_count:<10}")
425439

426440
console.print("")
@@ -442,9 +456,7 @@ def _scan_multi_skill(
442456
"path": skill.relative_path,
443457
"risk_score": result.get("risk_score", 0),
444458
"risk_severity": result.get("risk_severity", "LOW"),
445-
"finding_count": len(
446-
result.get("filtered_findings") or result.get("findings") or []
447-
),
459+
"finding_count": _result_finding_count(result),
448460
}
449461
)
450462
Path(output).write_text(json.dumps(combined, indent=2), encoding="utf-8")

‎tests/unit/test_cli.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,53 @@ def fake_invoke(state: dict[str, object], config: object = None) -> dict[str, ob
178178
for state in captured:
179179
assert "baseline" in state # the baseline was loaded and threaded in
180180
assert state.get("show_suppressed") is True
181+
182+
183+
def test_cli_recursive_json_finding_count_excludes_suppressed(
184+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
185+
) -> None:
186+
"""The combined JSON report must count post-suppression findings, not raw ones.
187+
188+
Regression for the empty-filtered-list fallback: when baseline suppression
189+
empties ``filtered_findings``, ``filtered or findings`` falls through to the
190+
unfiltered ``findings`` and over-reports finding_count. A fully-suppressed
191+
sub-skill (score 0, filtered_findings == []) must report finding_count 0.
192+
"""
193+
import skillspector.cli as cli_mod
194+
195+
collection = tmp_path / "collection"
196+
for name in ("alpha", "beta"):
197+
sub = collection / name
198+
sub.mkdir(parents=True)
199+
(sub / "SKILL.md").write_text(f"---\nname: {name}\n---\n# {name}\n", encoding="utf-8")
200+
201+
def fake_invoke(state: dict[str, object], config: object = None) -> dict[str, object]:
202+
# Three raw findings, all suppressed (empty filtered set, score 0).
203+
return {
204+
"risk_score": 0,
205+
"risk_severity": "LOW",
206+
"findings": ["raw1", "raw2", "raw3"],
207+
"filtered_findings": [],
208+
"report_body": "{}",
209+
}
210+
211+
monkeypatch.setattr(cli_mod.graph, "invoke", fake_invoke)
212+
213+
out_file = tmp_path / "combined.json"
214+
scan = runner.invoke(
215+
app,
216+
[
217+
"scan",
218+
str(collection),
219+
"--recursive",
220+
"--no-llm",
221+
"--format",
222+
"json",
223+
"--output",
224+
str(out_file),
225+
],
226+
)
227+
228+
assert scan.exit_code == 0
229+
data = json.loads(out_file.read_text())
230+
assert [s["finding_count"] for s in data["skills"]] == [0, 0]

0 commit comments

Comments
 (0)