fix(workflows): if-step validate accepts falsy non-list else
Description
IfThenStep.validate() validates the then branch strictly (if not isinstance(then_branch, list)) but guards else with a leading truthiness check:
else_branch = config.get("else", [])
if else_branch and not isinstance(else_branch, list): # bug
errors.append("...'else' must be a list of steps.")
else_branch and ... short-circuits whenever else is falsy — else: false, else: 0, else: "", else: {}. Those malformed values pass validation, then at runtime execute() does config.get("else", []) and the falsy non-list branch is silently skipped (no error, no else steps run). Only a truthy non-list (e.g. else: 42) was caught.
Fix
Switch to an is not None guard so else is validated exactly like then while keeping a missing/None else valid:
else_branch = config.get("else")
if else_branch is not None and not isinstance(else_branch, list):
errors.append("...'else' must be a list of steps.")
This matches the sibling switch default: / fan_out step: validation pattern.
Testing
- New
test_validate_rejects_non_list_elseparametrizeselse∈ {False, 0, '', {}, 42}: the four falsy values fail before / pass after; 42 was already caught (regression guard). - New
test_validate_accepts_valid_elsekeeps missing/None/[]/list-of-steps valid. TestIfThenSteppasses (11 tests);uvx ruff checkclean.
AI Disclosure
- [x] I did use AI assistance (describe below)
Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI flagged the then-vs-else validation asymmetry; I confirmed the falsy short-circuit, verified fail-before/pass-after, and reviewed the diff before submitting.
Thanks @mnriem — addressed the Copilot feedback in cb24673. The valid-else test now sets else explicitly (so else: None is covered, not just the missing-key case), and there's a dedicated test_validate_accepts_missing_else for the omitted-key case. TestIfThenStep green (12), ruff clean. (AI-assisted: Claude Code under my direction and review.)
d*****[email protected]