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

fix(workflows): fail switch step on non-mapping cases instead of crashing

Open Noor-ul-ain001 opened this issue 4 months ago • 0 comments

Summary

SwitchStep.validate() already rejects a non-mapping cases, but the engine's execute() path does not auto-validate — WorkflowEngine.load_workflow's docstring explicitly notes the returned definition is "not yet validated; call validate_workflow() or engine.validate() separately."

On such an unvalidated run, SwitchStep.execute iterated the raw value with cases.items(), so a list or scalar cases (an easy authoring mistake) raised AttributeError. The engine calls step_impl.execute() with no surrounding try/except, so that exception took down the entire run rather than failing just the step.

>>> SwitchStep().execute({"id": "sw", "expression": "x", "cases": ["a", "b"]}, ctx)
AttributeError: 'list' object has no attribute 'items'

Fix

Guard execute to return a FAILED StepResult naming the type error instead of crashing — mirroring the existing fan-out step behavior for a non-list items (test_execute_non_list_items_fails_loudly) and the "report validation errors instead of crashing" direction of #3421. The expression is still evaluated first, so its value is surfaced in the step output for downstream context.

This is the same bug class as the recent max_iterations / timeout / fan-in output guards: a validator catches the bad value, but the runtime path crashes on it when validation is skipped.

Testing

  • Added TestSwitchStep::test_execute_non_dict_cases_fails_loudly (list, str, int cases).
  • Full tests/test_workflows.py passes except the 11 pre-existing Windows symlink-guard tests, which fail identically on a clean base (require elevation on Windows).
  • ruff check clean on the changed files.

🤖 Generated with Claude Code

Noor-ul-ain001 avatar Jul 12 '26 15:07 Noor-ul-ain001