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

fix: non-zero exit code when a workflow run ends failed or aborted

Open doquanghuy opened this issue 5 months ago • 2 comments

Description

Fixes #2958.

workflow run and workflow resume ended with exit code 0 even when the run finished Status: failed, so scripts/CI had to parse stdout to detect failure. This PR adds a single status→exit-code mapping (_run_outcome_exit_code: failed/aborted → 1; completed/paused → 0 — paused is a waiting state, not a failure) and applies it at the four epilogues (run/resume × text/--json). The --json payload itself is unchanged — it still prints first; only the process exit code changes.

Behavior change, flagged plainly: the old behavior was deliberately pinned by tests/test_workflow_run_without_project.py::test_workflow_run_failing_yaml_without_project (exit_code == 0 asserted on a failed run). That pin is updated to the new contract with an explanatory comment. Anyone scripting against exit-0-on-failed would be affected — the issue discusses the trade-off; happy to gate this behind a flag instead if you'd rather not change the default.

Testing

  • [x] Ran existing tests with uv sync && uv run pytest — full suite 3728 passed
  • [x] New TestWorkflowRunExitCodes (3 CLI-level tests): failed→1 (text + --json), completed→0; the two failure-path tests are red against current main, green with the fix (verified both directions)
  • [x] uvx ruff check src/ — clean
  • [x] Tested locally with uv run specify --help
  • [ ] Tested with a sample project (covered by the CLI-level tests, which drive real workflow YAML files end-to-end through CliRunner)

AI Disclosure

  • [ ] I did not use AI assistance for this contribution
  • [x] I did use AI assistance (describe below)

Code, tests, and this description were authored with AI assistance (Claude); verified by running the repo's test suite and ruff locally in both red (unfixed) and green (fixed) directions.

doquanghuy avatar Jun 12 '26 17:06 doquanghuy

@mnriem when you have a moment, would appreciate a review — happy to adjust anything.

doquanghuy avatar Jun 12 '26 17:06 doquanghuy

Please address Copilot feedback

mnriem avatar Jun 16 '26 20:06 mnriem

@mnriem Thanks for the review — addressed the Copilot feedback:

  • Replaced the non-portable run: "true"/"false" with exit 0/exit 1 (Windows cmd.exe has no true/false builtins under shell=True).
  • Added an end-to-end workflow resume test asserting a resumed failed run exits non-zero, so the resume exit-code mapping is covered too.

Full suite green; ruff check src/ clean. Ready for another look.

doquanghuy avatar Jun 17 '26 02:06 doquanghuy

Thank you!

mnriem avatar Jun 17 '26 13:06 mnriem