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

feat(workflows): opt-in output_format: json exposes parsed shell stdout as output.data

Open doquanghuy opened this issue 5 months ago • 2 comments

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 (no data key); validate rejects unknown formats — the three behavior tests are red against current main, 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.

doquanghuy avatar Jun 12 '26 17:06 doquanghuy

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

doquanghuy avatar Jun 12 '26 17:06 doquanghuy

Please address Copilot feedback. Please make sure to include negative and positive tests

mnriem avatar Jun 16 '26 20:06 mnriem

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

  • The output_format tests now emit JSON via sys.executable + a temp script (the established '"{py}" "{script}"' pattern used elsewhere in the suite) instead of echo '{...}', so they're portable to the Windows cmd.exe CI matrix.

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

doquanghuy avatar Jun 17 '26 02:06 doquanghuy

@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 as output.data (raw stdout/exit_code still present).
  • Negative (parse): test_output_format_json_invalid_stdout_fails — non-JSON stdout fails the step with an output_format: json error.
  • Negative (validation): test_validate_rejects_unknown_output_format — a non-json output_format is rejected at validate time.
  • Back-compat: test_no_output_format_keeps_raw_output_only — no output_format ⇒ no data key.

All four emit any JSON via sys.executable now (cross-platform). Happy to add more cases if you'd like a specific one covered.

doquanghuy avatar Jun 17 '26 03:06 doquanghuy

Thank you!

mnriem avatar Jun 17 '26 13:06 mnriem