spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

fix(workflows): validate non-mapping `options` in command step

Open thejesh23 opened this issue 4 months ago • 0 comments

Fixes #3493.

What

CommandStep.execute() merges step-level options into the workflow-level defaults via dict.update(), but CommandStep.validate() did not check the type of options, and the merge itself was gated only on truthiness (if step_options:). Any truthy non-mapping value therefore passed validation and crashed at run time:

options: [1, 2]   -> TypeError: cannot convert dictionary update sequence element #0 to a sequence
options: "foo"    -> ValueError: dictionary update sequence element #0 has length 1; 2 is required

Sibling of #3492 (same file, same class of type-validation gap in the command step).

Fix

Same shape as the fix already applied in the shell / while-loop / do-while validators and in #3492:

  • validate() rejects a non-mapping options with a message that names the field.
  • execute() guards the .update() with isinstance(step_options, dict) so a caller that bypasses WorkflowEngine.validate() (e.g. ad-hoc step.execute(...)) still fails cleanly and the workflow-level defaults survive.

Tests

Two new regression tests in TestCommandStep:

  • test_validate_rejects_non_mapping_options — a list and a string both report a clear 'options' must be a mapping error.
  • test_execute_non_mapping_options_does_not_crash — the validate-bypass path returns StepStatus.FAILED and the workflow-level defaults are preserved unchanged (a malformed step-level override is discarded, not partially applied).

Targeted run:

$ .venv/bin/python -m pytest tests/test_workflows.py::TestCommandStep -q
============================== 12 passed in 0.35s ==============================

Manual test results

Agent: N/A — workflow-engine-only fix, no slash-command surface changed. | OS/Shell: macOS 15 / zsh

Command tested Notes
/speckit.plan Not affected — CLI dispatch surface unchanged. TestCommandStep::test_options_merge still passes (well-formed step options are still merged over defaults).

Only touches src/specify_cli/workflows/steps/command/__init__.py; no templates/commands/*, no scripts/bash|powershell/*, no src/specify_cli/* CLI entry point. Per CONTRIBUTING.md's mapping rules, no slash command's behavior changes.

Relation to #3495

#3495 (input validation, closes #3492) is an independent sibling fix in the same file. Both share the pattern the recent fix(workflows) commits have been applying elsewhere. They land cleanly on top of each other; happy to rebase either way.

AI disclosure

Per CONTRIBUTING.md#ai-contributions-in-spec-kit: this PR (bug identification, patch, and tests) was prepared with Claude (Anthropic) assistance in an autonomous agent session. Reproducer executed against a fresh clone of main; the fix follows the existing type-validation pattern in sibling step validators; the workflow test suite was run green before submission. The change is minimal — one isinstance guard in execute(), one check in validate(), two focused tests.

🤖 Generated with Claude Code

thejesh23 avatar Jul 13 '26 17:07 thejesh23