feat(workflows): opt-in output_format: json exposes parsed shell stdout as output.data
Description
Reference implementation for #2962 — for discussion, direction welcome.
Adds an opt-in output_format: json to shell steps: when declared, stdout is parsed and exposed under output.data (the raw stdout/stderr/exit_code keys are unchanged, so there is no merge/clobber ambiguity), letting later steps consume typed values — e.g. a fan-out's items: "{{ steps.emit.output.data.items }}". A parse failure fails the step with a clear error (declaring the format is a contract; silence would hide wiring bugs). Without the key, behavior is byte-identical — fully backward-compatible. validate() rejects unknown formats.
The issue lists output_file: and a declared named-outputs: schema as alternatives — happy to rework toward either if you prefer that direction.
Coordination: aware of #2443 touching the same file; this diff is isolated to the structured-output addition and I'm happy to rebase in whichever order suits.
Testing
- [x] Ran existing tests with
uv sync && uv run pytest— full suite 3729 passed - [x] Four new tests in
TestShellStep: data exposed on valid JSON; invalid stdout fails the step; no-flag backcompat (nodatakey); validate rejects unknown formats — the three behavior tests are red against currentmain, green with the change (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 step-level tests)
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 and green directions.
@mnriem when you have a moment, would appreciate your thoughts on the direction here — the issue lists the alternatives considered, and I'm happy to rework toward whichever shape fits Spec Kit best.
Please address Copilot feedback. Please make sure to include negative and positive tests
@mnriem Thanks for the review — addressed the Copilot feedback:
- The
output_formattests now emit JSON viasys.executable+ a temp script (the established'"{py}" "{script}"'pattern used elsewhere in the suite) instead ofecho '{...}', so they're portable to the Windowscmd.exeCI matrix.
Full suite green; ruff check src/ clean. Ready for another look.
@mnriem on the positive/negative coverage you asked for — it's in TestShellStep:
- Positive:
test_output_format_json_exposes_data— valid JSON stdout is parsed and surfaced asoutput.data(rawstdout/exit_codestill present). - Negative (parse):
test_output_format_json_invalid_stdout_fails— non-JSON stdout fails the step with anoutput_format: jsonerror. - Negative (validation):
test_validate_rejects_unknown_output_format— a non-jsonoutput_formatis rejected at validate time. - Back-compat:
test_no_output_format_keeps_raw_output_only— nooutput_format⇒ nodatakey.
All four emit any JSON via sys.executable now (cross-platform). Happy to add more cases if you'd like a specific one covered.
Thank you!