Skip to content

fix: normalize multi-skill risk_score before threshold check - #368

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/cli-normalize-multi-skill-risk-score
Open

fix: normalize multi-skill risk_score before threshold check#368
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/cli-normalize-multi-skill-risk-score

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

No issue filed — this is a correctness fix for aggregate risk scoring in multi-skill scans.

Description

_scan_multi_skill in src/skillspector/cli.py checked isinstance(score, int) before comparing a skill's risk_score against the running maximum. When the score is stored as a string (e.g., deserialized from JSON), the check failed and the value was ignored, so the aggregate exit code did not reflect a high-risk skill. This change converts the score to int safely with a fallback to 0, then compares it unconditionally.

Changes

  • src/skillspector/cli.py: safely coerce risk_score to int before the threshold comparison in _scan_multi_skill.
  • tests/unit/test_cli.py: add regression tests for numeric-string scores and malformed-value fallback.

Testing

Added two regression tests:

  • test_recursive_scan_string_risk_score_counts_toward_exit_code — mocks two skills with string risk scores ("25" and "75") and asserts the aggregate exits with code 1 because the max coerced score (75) crosses the threshold.
  • test_recursive_scan_malformed_risk_score_falls_back_to_zero — mocks a skill with risk_score="not-a-number" and asserts the aggregate max score falls back to 0 without raising.

Both pass locally with uv run pytest tests/unit/test_cli.py::test_recursive_scan_string_risk_score_counts_toward_exit_code tests/unit/test_cli.py::test_recursive_scan_malformed_risk_score_falls_back_to_zero -xvs.

@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/cli-normalize-multi-skill-risk-score branch from fb7980f to 0970996 Compare August 18, 2026 00:17

@rng1995 rng1995 left a comment

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.

[SkillSpector Review]

Requesting changes because this head cannot be assessed confidently as the claimed focused fix. It contains 18,513 additions and 1,868 deletions across 143 files, has no completed checks on the current head, and conflicts with main. Please rebase/split to a reviewable patch and obtain green CI; manual review is required before approval.

@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/cli-normalize-multi-skill-risk-score branch from 0970996 to 11b2cb4 Compare August 20, 2026 23:03
Comment thread src/skillspector/cli.py
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.

@rng1995 rng1995 left a comment

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.

[SkillSpector Review]

Re-review: still requesting changes. The prior scope/conflict blocker is resolved—the current diff is focused and CI is green—but the new string-to-integer risk-score path has no regression test. Add coverage proving a numeric string affects the aggregate score/exit status and malformed input falls back safely; see the inline blocker.

@andrewwhitecdw

Copy link
Copy Markdown
Contributor Author

@rng1995 added the regression test you requested in tests/unit/test_cli.py:

  • test_recursive_scan_string_risk_score_counts_toward_exit_code — mocks two skills with string risk scores ("25" and "75") and asserts the aggregate exits with code 1 because the max coerced score (75) crosses the threshold.
  • test_recursive_scan_malformed_risk_score_falls_back_to_zero — mocks a skill with risk_score="not-a-number" and asserts the aggregate max score falls back to 0 without raising.

Both tests pass locally:

uv run pytest tests/unit/test_cli.py::test_recursive_scan_string_risk_score_counts_toward_exit_code tests/unit/test_cli.py::test_recursive_scan_malformed_risk_score_falls_back_to_zero -xvs

@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/cli-normalize-multi-skill-risk-score branch 2 times, most recently from 03bfed7 to 2749a9c Compare August 21, 2026 19:38
`_scan_multi_skill` checked `isinstance(score, int)` before comparing a
skill's `risk_score` against the running maximum. When the score is stored as
a string (e.g., deserialized from JSON), the check failed and the value was
ignored, so the aggregate exit code did not reflect a high-risk skill.

Convert the score to `int` safely with a fallback to `0`, then compare it
unconditionally. Add regression tests covering numeric-string scores and the
malformed-value fallback.

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/cli-normalize-multi-skill-risk-score branch from f564fc6 to 401c20e Compare August 21, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants