The agent that turns websites into APIs!
fix(cli): report failed provider runs as errors
kalil03212fbdbb4ef032
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.pyindex cae77fc..740cfb5 100644--- a/src/reverse_api/cli.py+++ b/src/reverse_api/cli.py@@ -1766,7 +1766,7 @@ def agent(prompt, url, model, output_dir, no_interactive, as_json, json_stream,interactive = not no_interactiveif not machine_output:- run_agent_capture(+ result = run_agent_capture(prompt=prompt,url=url,model=model,@@ -1774,6 +1774,8 @@ def agent(prompt, url, model, output_dir, no_interactive, as_json, json_stream,interactive=interactive,headless=headless,)+ if isinstance(result, dict) and result.get("error"):+ sys.exit(1)returnfrom .json_stream import make_json_stream_sink@@ -2203,7 +2205,13 @@ def run_auto_capture("mode": mode_label,"script_path": (result or {}).get("script_path"),"usage": (result or {}).get("usage", {}),- **({"error": "interrupted"} if interrupted else {}),+ **(+ {"error": "interrupted"}+ if interrupted+ else {"error": "Agent analysis produced no result. Check the provider error above."}+ if result is None+ else {}+ ),}except Exception as e:diff --git a/tests/test_cli_agent_json.py b/tests/test_cli_agent_json.pyindex 6ccafe1..6cc478a 100644--- a/tests/test_cli_agent_json.py+++ b/tests/test_cli_agent_json.py@@ -514,3 +514,29 @@ class TestAgentJsonStdoutPurity:assert "noisy" not in stdout# The noise landed on stderr insteadassert "noisy" in result.stderr++[email protected]("output_flag", ["--json", "--json-stream", "--no-interactive"])+def test_provider_failure_is_not_reported_as_success(tmp_path, output_flag):+ """Exercise the real capture wrapper, where a failed SDK returns None."""+ from unittest.mock import AsyncMock++ from reverse_api.config import ConfigManager++ config = ConfigManager(tmp_path / "config.json")+ config.config.update({"sdk": "claude", "agent_provider": "chrome-mcp", "real_time_sync": False})+ engine = MagicMock()+ engine.analyze_and_generate = AsyncMock(return_value=None)+ with (+ patch("reverse_api.cli.config_manager", config),+ patch("reverse_api.cli.session_manager", SessionManager(tmp_path / "history.json")),+ patch("reverse_api.auto_engineer.ClaudeAutoEngineer", return_value=engine),+ ):+ result = CliRunner().invoke(main, ["agent", "-p", "test provider failure", "--headless", "-o", str(tmp_path), output_flag])+ assert result.exit_code == 1, result.output+ if output_flag != "--no-interactive":+ payload = json.loads(result.stdout.strip().splitlines()[-1])+ assert payload["status"] == "error"+ assert payload["error_kind"] == "engine_failure"+ assert payload["script_path"] is None+ engine.stop_sync.assert_called_once()