Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/skillspector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,11 @@ def _scan_multi_skill(
elif not child_failed:
complete_skill_count += 1
score = result.get("risk_score") or 0
if isinstance(score, int) and score > max_score:
try:
score = int(score)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Add a regression for the string-score exit-code path

This is the only behavior change, but no test exercises it. Add a multi-skill regression where risk_score is a numeric string and assert the aggregate score/exit status honors it; also cover the malformed-value fallback. Otherwise this correctness fix can silently regress.

except (TypeError, ValueError):
score = 0
if score > max_score:
max_score = score
child_transitive_count = result.get("transitive_finding_count")
if isinstance(child_transitive_count, int):
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,60 @@ def test_recursive_scan_exception_marks_combined_execution_as_failed(tmp_path: P
assert payload["skills"][1] == {"name": "two", "error": "child scan crashed"}


def test_recursive_scan_string_risk_score_counts_toward_exit_code(tmp_path: Path) -> None:
"""Numeric-string risk_score values are coerced and affect aggregate exit code."""
s1 = SkillDirectory(path=tmp_path / "low", name="low", relative_path="low")
s2 = SkillDirectory(path=tmp_path / "high", name="high", relative_path="high")
detection = MultiSkillDetectionResult(
is_multi_skill=True, skills=[s1, s2], has_root_skill=False
)
output = tmp_path / "combined.json"

with patch(
"skillspector.cli.graph.invoke",
side_effect=[
{"report_body": '{"skill": {"name": "low"}}', "risk_score": "25"},
{"report_body": '{"skill": {"name": "high"}}', "risk_score": "75"},
],
):
with pytest.raises(typer.Exit) as exit_info:
_scan_multi_skill(
detection,
FormatChoice.json,
output,
no_llm=True,
yara_rules_dir=None,
verbose=False,
)

assert exit_info.value.exit_code == 1
payload = json.loads(output.read_text())
assert payload["max_risk_score"] == 75


def test_recursive_scan_malformed_risk_score_falls_back_to_zero(tmp_path: Path) -> None:
"""Non-numeric risk_score values fall back to 0 and do not raise."""
s1 = SkillDirectory(path=tmp_path / "bad", name="bad", relative_path="bad")
detection = MultiSkillDetectionResult(is_multi_skill=True, skills=[s1], has_root_skill=False)
output = tmp_path / "combined.json"

with patch(
"skillspector.cli.graph.invoke",
return_value={"report_body": '{"skill": {"name": "bad"}}', "risk_score": "not-a-number"},
):
_scan_multi_skill(
detection,
FormatChoice.json,
output,
no_llm=True,
yara_rules_dir=None,
verbose=False,
)

payload = json.loads(output.read_text())
assert payload["max_risk_score"] == 0


def test_cli_scan_slack_p6_pe3_regression(tmp_path: Path) -> None:
"""Benign context stays distinguishable without deleting deterministic CLI evidence."""
(tmp_path / "references").mkdir()
Expand Down
Loading