Skip to content

FIX: Coerce typed scenario parameters in scan CLI#2092

Merged
romanlutz merged 3 commits into
microsoft:mainfrom
biefan:fix/scan-scenario-param-coercion
Jun 29, 2026
Merged

FIX: Coerce typed scenario parameters in scan CLI#2092
romanlutz merged 3 commits into
microsoft:mainfrom
biefan:fix/scan-scenario-param-coercion

Conversation

@biefan

@biefan biefan commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

  • Fix pyrit_scan handling of scenario-declared CLI parameters so invalid boolean tokens are rejected instead of silently becoming false.
  • Coerce list parameter elements, such as list[int], before sending scenario_params to the backend.
  • Coerce typed choices before argparse validation so numeric choices are compared using the correct type.

Tests and Documentation

  • uv run -m pytest tests/unit/cli/test_pyrit_scan.py tests/unit/cli/test_pyrit_shell.py -q
  • uv run -m pytest tests/unit/cli -q
  • uv run -m ty check pyrit/cli/pyrit_scan.py tests/unit/cli/test_pyrit_scan.py
  • uv run pre-commit run --files pyrit/cli/pyrit_scan.py tests/unit/cli/test_pyrit_scan.py

Documentation changes are not needed for this CLI bug fix.

@romanlutz romanlutz self-assigned this Jun 28, 2026
Comment thread pyrit/cli/pyrit_scan.py Outdated
Replace the bespoke _SCALAR_TYPE_COERCERS / _coerce_bool table in pyrit_scan with the canonical pyrit.models.parameter.Parameter.coerce_value, reached via the shared build_parameters_from_api helper that the shell front-end already uses.

This removes a duplicate coercion vocabulary and fixes a cross-CLI divergence: scan previously accepted y/n/on/off boolean tokens that pyrit_shell and the backend reject, so the same scenario flag behaved differently depending on entry point. Scalars, list elements, and Literal choice membership now all go through one code path.

Tests updated: choice errors now surface as 'invalid value' (coerce_value) instead of argparse 'invalid choice', and bool typos like 'on' are asserted rejected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz enabled auto-merge June 29, 2026 14:18
@romanlutz romanlutz added this pull request to the merge queue Jun 29, 2026
Merged via the queue into microsoft:main with commit b48085b Jun 29, 2026
52 checks passed
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.

3 participants