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

fix(workflows): if-step validate accepts falsy non-list else

Open jawwad-ali opened this issue 5 months ago • 1 comments

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_else parametrizes else ∈ {False, 0, '', {}, 42}: the four falsy values fail before / pass after; 42 was already caught (regression guard).
  • New test_validate_accepts_valid_else keeps missing/None/[]/list-of-steps valid.
  • TestIfThenStep passes (11 tests); uvx ruff check clean.

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.

jawwad-ali avatar Jun 30 '26 16:06 jawwad-ali

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.)

jawwad-ali avatar Jun 30 '26 20:06 jawwad-ali

d*****[email protected]

aabomouawya-cmd avatar Jul 14 '26 20:07 aabomouawya-cmd