feat(workflows): support file-backed inputs#2420
feat(workflows): support file-backed inputs#2420Adr1an04 wants to merge 4 commits intogithub:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds generic CLI support for providing workflow inputs from files (single values via key=@path and bulk values via --input-file JSON), keeping existing inline --input key=value behavior and defining clear precedence/validation at the CLI boundary.
Changes:
- Added
_parse_workflow_inputs(plus helpers) to normalize--inputand--input-fileinto the workflow engine input dict. - Extended
workflow runCLI options with--input-fileand--input key=@pathsemantics (CLI values override file values). - Added regression tests for parsing/precedence/error cases and updated workflow CLI documentation examples.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/specify_cli/__init__.py |
Implements file-backed input parsing helpers and wires them into workflow run via new CLI options. |
tests/test_workflows.py |
Adds targeted tests covering @file inputs, --input-file JSON loading, precedence, and failure modes. |
docs/reference/workflows.md |
Updates CLI reference docs with the new options and usage examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if file_ref and _resolve_workflow_cli_path(file_ref).exists(): | ||
| _, value = _read_workflow_cli_file(file_ref, f"input {key!r}") |
There was a problem hiding this comment.
@path handling checks only Path.exists() before treating the value as a file reference. This means values like --input x=@. or --input x=@some_dir (existing directories) will be interpreted as file refs and then fail with “is not a file”, instead of staying literal as intended for non-file @ values. Consider requiring is_file() (or catching the non-file case and leaving the value unchanged) before calling _read_workflow_cli_file().
| if file_ref and _resolve_workflow_cli_path(file_ref).exists(): | |
| _, value = _read_workflow_cli_file(file_ref, f"input {key!r}") | |
| if file_ref: | |
| candidate_path = _resolve_workflow_cli_path(file_ref) | |
| if candidate_path.exists() and candidate_path.is_file(): | |
| _, value = _read_workflow_cli_file( | |
| file_ref, f"input {key!r}" | |
| ) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | `--input-file` | Load workflow inputs/parameters from a JSON object file; repeatable `--input` values override file values | | ||
|
|
||
| Runs a workflow from a catalog ID, URL, or local file path. Inputs declared by the workflow can be provided via `--input` or will be prompted interactively. | ||
| Runs a workflow from a catalog ID, URL, or local file path. Inputs/parameters declared by the workflow can be provided via `--input` or will be prompted interactively. |
There was a problem hiding this comment.
The docs claim specify workflow run accepts a "URL", but the current implementation routes source to WorkflowEngine.load_workflow(), which only supports an installed workflow ID or a local .yml/.yaml path. Consider updating this sentence to avoid implying URL support for workflow run (URL support appears to apply to workflow add, not run).
| Runs a workflow from a catalog ID, URL, or local file path. Inputs/parameters declared by the workflow can be provided via `--input` or will be prompted interactively. | |
| Runs a workflow from an installed workflow ID or a local `.yml`/`.yaml` file path. Inputs/parameters declared by the workflow can be provided via `--input` or will be prompted interactively. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| None, | ||
| "--input", | ||
| "-i", | ||
| help="Input values as key=value pairs; use key=@path to read a text file", |
There was a problem hiding this comment.
The --input help text implies key=@path will read a file, but the implementation only reads when the referenced file exists; otherwise the value stays literal (by design for values like @alice). Consider reflecting that nuance in the help string to avoid silent surprises when users typo a path.
| help="Input values as key=value pairs; use key=@path to read a text file", | |
| help=( | |
| "Input values as key=value pairs; use key=@path to read a text " | |
| "file when the path exists, otherwise the value is treated " | |
| "literally" | |
| ), |
| | `-i` / `--input` | Pass workflow inputs/parameters as `key=value` (repeatable); use `key=@path` to read text files | | ||
| | `--input-file` | Load workflow inputs/parameters from a JSON object file; repeatable `--input` values override file values | | ||
|
|
||
| Runs a workflow from a catalog ID, URL, or local file path. Inputs declared by the workflow can be provided via `--input` or will be prompted interactively. | ||
| Runs a workflow from an installed workflow ID or a local `.yml`/`.yaml` file path. Inputs/parameters declared by the workflow can be provided via `--input` or will be prompted interactively. |
There was a problem hiding this comment.
Docs describe key=@path as reading text files, but the CLI only reads from a file when that path exists; otherwise the value is treated as a literal string. Also, the paragraph below the table mentions only --input even though --input-file is now supported—consider mentioning both for clarity.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@mnriem I handled Copilots feedback and made sure to take into account your message in the issue. Let me know if you need me to edit anything! :D |
Refs #2405
Summary
This PR adds support for passing workflow inputs from files.
You can still pass inputs inline with repeated
--input key=valueflags. For longer values, you can now usekey=@path, and for multiple values you can use a JSON file with--input-file.This is handled generically for workflow inputs/parameters, not just for
spec.What changed
--input key=@pathfor any workflow input key.--input-file payload.jsonto load multiple inputs from a JSON object.--inputvalues override values loaded from--input-file.Examples
Notes
File references are not
spec-specific. They work for any workflow input key.Values starting with
@are only read from a file when that file exists. This keeps literal values like@aliceor@working as normal strings.--input-filevalues are loaded first, then direct--inputvalues are applied after that. This lets command-line values override the JSON file.What did not change
WorkflowEnginebehavior.--input-fileonly accepts a JSON object.--input key=@pathvalues are read as UTF-8 text.Testing
I ran focused workflow input regression tests:
uv run python -m pytest tests/test_workflows.py -k WorkflowCliInputs -v # 12 passed, 126 deselected in 0.15sI also ran the full workflow test file:
uv run python -m pytest tests/test_workflows.py -v # 138 passed in 0.30sI used the existing agent config consistency test:
uv run python -m pytest tests/test_agent_config_consistency.py -q # 24 passed in 0.13sI ran the full test suite:
uv run python -m pytest -q # 1833 passed, 29 skipped, 18 warnings in 20.25sCLI-level validation
I tested the workflow CLI directly in a temporary Spec Kit project.
Covered cases:
--input key=@pathreads an existing UTF-8 text file.promptanddescription, not onlyspec.--input key=valuevalues still work.@aliceand bare@stay unchanged.@pathvalues stay literal.--input-file payload.jsonloads multiple inputs from a JSON object.--inputvalues override values loaded from--input-file.key=@path.--input-fileexits cleanly with code 1.Smoke test output:
I also checked the command help and confirmed the new CLI options are exposed:
AI assistance note
I used ChatGPT to help think through edge cases and wording. I wrote, reviewed, and tested the code locally before opening this PR.