The agent that turns websites into APIs!
fix(cli): engineer --json must emit JSON when RUN_ID is missing
Kalil Bouzigues70d5b57f950d
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.pyindex 1bb86e3..7a8c8c2 100644--- a/src/reverse_api/cli.py+++ b/src/reverse_api/cli.py@@ -1803,7 +1803,7 @@ Exit codes:2 misuse""")[email protected]("run_id")[email protected]("run_id", required=False)@click.option("--prompt","-p",@@ -1838,6 +1838,26 @@ Exit codes:)def engineer(run_id, prompt, fresh, model, output_dir, no_interactive, as_json):"""Run reverse engineering on a previous run."""+ # `run_id` is declared optional at the click level so that wrappers using+ # --json get a JSON misuse payload instead of Click's plain-text "missing+ # argument" error. We re-validate inline to preserve the same exit-2 UX+ # for non-JSON invocations.+ if not run_id:+ if as_json:+ misuse = _build_engineer_payload(+ None,+ run_id="",+ prompt=prompt,+ fresh=fresh,+ error="RUN_ID is required",+ error_kind_hint="misuse",+ )+ click.echo(json.dumps(misuse))+ else:+ click.echo("Usage: reverse-api-engineer engineer [OPTIONS] RUN_ID", err=True)+ click.echo("\nError: Missing argument 'RUN_ID'.", err=True)+ sys.exit(2)+# --fresh treats --prompt as a full replacement of the original goal;# without --fresh, --prompt is additive so the captured run's context is preserved.main_prompt = prompt if fresh else Nonediff --git a/tests/test_cli_followups.py b/tests/test_cli_followups.pyindex a3933e4..8c03cb3 100644--- a/tests/test_cli_followups.py+++ b/tests/test_cli_followups.py@@ -199,6 +199,41 @@ class TestEngineerCommandJson:assert result.exit_code == 0, result.output+class TestEngineerJsonMissingRunId:+ """`engineer --json` without RUN_ID must emit a JSON misuse payload, not+ Click's plain-text 'missing argument' error.++ Regression for kind-agent observation on PR #66.+ """++ def test_json_emits_misuse_payload_when_run_id_missing(self):+ from reverse_api.cli import engineer++ runner = CliRunner()+ result = runner.invoke(engineer, ["--json"])+ assert result.exit_code == 2+ # stdout MUST be valid JSON (wrappers expect it)+ payload = json.loads(result.stdout.strip())+ assert payload["status"] == "error"+ assert payload["error_kind"] == "misuse"+ assert "RUN_ID" in payload["error"]+ # And the JSON shape is the full engineer schema+ assert "schema_version" in payload+ assert "fresh" in payload++ def test_plain_invocation_still_emits_click_style_error(self):+ """Non-JSON path keeps Click's familiar Usage + Error format on stderr."""+ from reverse_api.cli import engineer++ runner = CliRunner()+ result = runner.invoke(engineer, [])+ assert result.exit_code == 2+ # The Click-style error goes to stderr, NOT JSON+ combined = (result.stderr or "") + (result.stdout or "")+ assert "Usage" in combined+ assert "RUN_ID" in combined++class TestSchemaV2Normalization:"""v2 helpers: _normalize_usage, _classify_error, --json-schema-version."""