Skip to content

Commit de544bc

Browse files
jawwad-aliclaude
andcommitted
test(workflows): cover the ValueError handler in workflow status --json purity
The stderr-routing fix reroutes both the FileNotFoundError and ValueError run_id handlers, but the test only exercised FileNotFoundError — a regression of the ValueError path back to stdout would have gone uncaught. Add a ValueError case (RunState.load raising) asserting the same stderr-only / empty-stdout behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e0cae31 commit de544bc

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/test_workflows.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12543,6 +12543,35 @@ def test_status_json_not_found_error_goes_to_stderr(
1254312543
# stdout carries no partial/corrupt JSON on the error path.
1254412544
assert captured.out.strip() == ""
1254512545

12546+
def test_status_json_invalid_run_error_goes_to_stderr(
12547+
self, project_dir, monkeypatch, capsys
12548+
):
12549+
"""The ValueError handler (a malformed/invalid run state) must ALSO route
12550+
to stderr under --json, not just the FileNotFoundError one — otherwise a
12551+
regression there would silently corrupt the JSON stream and this suite
12552+
wouldn't catch it."""
12553+
import typer
12554+
from specify_cli.workflows import _commands
12555+
from specify_cli.workflows.engine import RunState
12556+
12557+
(project_dir / ".specify" / "workflows").mkdir(parents=True, exist_ok=True)
12558+
monkeypatch.setattr(
12559+
_commands, "_require_specify_project", lambda: project_dir
12560+
)
12561+
12562+
def _raise_value_error(*args, **kwargs):
12563+
raise ValueError("corrupt run state: bad status")
12564+
12565+
monkeypatch.setattr(RunState, "load", _raise_value_error)
12566+
12567+
with pytest.raises(typer.Exit) as exc:
12568+
_commands.workflow_status("some-run", json_output=True)
12569+
assert exc.value.exit_code == 1
12570+
captured = capsys.readouterr()
12571+
assert "corrupt run state" in captured.err
12572+
assert "corrupt run state" not in captured.out
12573+
assert captured.out.strip() == ""
12574+
1254612575
def test_status_no_run_id_list_path_unaffected(self, project_dir, monkeypatch):
1254712576
"""The no-run-id list-all-runs path must remain unaffected by the
1254812577
new single-run ValueError boundary."""

0 commit comments

Comments
 (0)