Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/steerbench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import annotations

import argparse
import json
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -101,6 +102,11 @@ def _build_parser() -> argparse.ArgumentParser:
metavar="FUNCTION",
help="run a Modal harness function (needs steerbench[gpu]) instead of rendering",
)
parser.add_argument(
"--json",
action="store_true",
help="print the written artifact paths as a single JSON object (suppresses human text)",
)
return parser


Expand All @@ -126,9 +132,12 @@ def main(argv: list[str] | None = None) -> int:
out_dir=args.out,
stem=args.stem,
)
print("[steerbench] wrote:")
for kind, path in outputs.items():
print(f" {kind:9s} {path}")
if args.json:
print(json.dumps({kind: str(path) for kind, path in outputs.items()}))
else:
print("[steerbench] wrote:")
for kind, path in outputs.items():
print(f" {kind:9s} {path}")
return 0


Expand Down
27 changes: 27 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
from pathlib import Path

import pytest
Expand Down Expand Up @@ -37,6 +38,32 @@ def test_cli_renders_from_real_artifacts(tmp_path: Path) -> None:
assert (out / "side_effects.csv").read_text().startswith("benchmark,")


def test_cli_json_emits_artifact_paths(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
pytest.importorskip("matplotlib")
out = tmp_path / "card"
rc = cli.main(
[
"--dose-csv",
str(_DOSE),
"--layer-csv",
str(_LAYER),
"--out",
str(out),
"--stem",
"report",
"--json",
]
)
assert rc == 0
stdout = capsys.readouterr().out
# human "wrote:" lines are suppressed under --json.
assert "[steerbench] wrote:" not in stdout
payload = json.loads(stdout)
for key in ("markdown", "html", "dose_png", "layer_png"):
assert key in payload, f"missing artifact key: {key}"
assert Path(payload[key]).exists(), f"artifact path does not exist: {payload[key]}"


def test_cli_errors_on_missing_csv(tmp_path: Path) -> None:
with pytest.raises(SystemExit):
cli.main(["--dose-csv", str(tmp_path / "nope.csv"), "--out", str(tmp_path / "o")])