From 0d5e846660d5d4fded55945cca353030e10c47ee Mon Sep 17 00:00:00 2001 From: abhinavgautam01 Date: Tue, 30 Jun 2026 14:00:26 +0530 Subject: [PATCH] Make smoke JSON output consistent --- src/maxed_cli/cli.py | 4 ++-- tests/test_cli.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/maxed_cli/cli.py b/src/maxed_cli/cli.py index bd26034..274e0c8 100644 --- a/src/maxed_cli/cli.py +++ b/src/maxed_cli/cli.py @@ -321,7 +321,7 @@ def smoke( if not connectors: if as_json: - typer.echo(json.dumps({"results": []})) + _emit_json({"ok": True, "results": []}) else: typer.secho("No connectors defined in config.", fg=typer.colors.YELLOW) return @@ -359,7 +359,7 @@ def smoke( ) if as_json: - typer.echo(json.dumps({"results": results}, indent=2)) + _emit_json({"ok": failures == 0, "results": results}) else: for r in results: mark = "PASS" if r["ok"] else "FAIL" diff --git a/tests/test_cli.py b/tests/test_cli.py index 3c2c765..e361159 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -129,7 +129,9 @@ def test_smoke_json(tmp_path: Path) -> None: cfg = _yaml(tmp_path / "c.yaml", VALID_CONFIG) result = runner.invoke(app, ["smoke", str(cfg), "--json"]) assert result.exit_code == 0 + assert result.stdout.startswith('{\n "ok": true,\n') payload = json.loads(result.stdout) + assert payload["ok"] is True assert len(payload["results"]) == 2 assert all(r["ok"] for r in payload["results"]) @@ -142,6 +144,15 @@ def test_smoke_no_connectors(tmp_path: Path) -> None: assert "No connectors" in result.stdout +def test_smoke_json_no_connectors(tmp_path: Path) -> None: + no_conn = {k: v for k, v in VALID_CONFIG.items() if k != "connectors"} + cfg = _yaml(tmp_path / "c.yaml", no_conn) + result = runner.invoke(app, ["smoke", str(cfg), "--json"]) + assert result.exit_code == 0 + assert result.stdout == '{\n "ok": true,\n "results": []\n}\n' + assert json.loads(result.stdout) == {"ok": True, "results": []} + + def test_schema_default_is_workpaper() -> None: result = runner.invoke(app, ["schema"]) assert result.exit_code == 0