Fix CLI stdout count report + add regression test

Devin Review caught that `--out -` discarded the sample count, so
the stderr summary always said 'wrote 0 sample(s)' even when bytes
were streamed. Capture the return value like the file-output branch
does, and add a regression test that exercises the stdout path.

Co-Authored-By: adrian kuman firmansah <adriancuman@gmail.com>
This commit is contained in:
Devin AI
2026-04-25 20:27:47 +00:00
parent 6003d96a94
commit 1b026ec6f4
2 changed files with 17 additions and 2 deletions

View File

@@ -101,9 +101,8 @@ def main(argv: list[str] | None = None) -> int:
)
out: Path = args.out
count = 0
if str(out) == "-":
_write_stream(sys.stdout.buffer, filters)
count = _write_stream(sys.stdout.buffer, filters)
else:
out.parent.mkdir(parents=True, exist_ok=True)
with out.open("wb") as fh:

View File

@@ -65,6 +65,22 @@ def test_cli_respects_limit(db_ready: None, tmp_path: Path) -> None:
assert len(lines) == 1
def test_cli_stdout_reports_correct_count(
db_ready: None, capsys: pytest.CaptureFixture[str]
) -> None:
"""``--out -`` writes JSONL to stdout; the "wrote N" message must
reflect what actually streamed, not 0."""
_seed_two_approved_jobs()
exit_code = export_main(["--out", "-"])
assert exit_code == 0
captured = capsys.readouterr()
stdout_lines = [line for line in captured.out.splitlines() if line.strip()]
assert len(stdout_lines) == 2
for line in stdout_lines:
assert json.loads(line)["approved"] is True
assert "wrote 2 sample(s)" in captured.err
def test_cli_print_stats_emits_json_to_stderr(
db_ready: None, tmp_path: Path, capsys: pytest.CaptureFixture[str]
) -> None: