import json from pathlib import Path from composer_ans.reporting import build_run_report, save_run_report_json from composer_ans.types import CompositionRecord def test_build_run_report_combines_timing_and_analysis() -> None: record = CompositionRecord( notes=(1, 2, 1, 2), per_note_seconds=(0.1, 0.2, 0.3, 0.4), total_seconds=1.0, ) report = build_run_report(record, parameters={"object_threshold": 3}) assert report.note_count == 4 assert report.total_seconds == 1.0 assert len(report.per_note_seconds) == 4 assert report.parameters["object_threshold"] == 3 assert 0.0 <= report.predictability <= 1.0 def test_save_run_report_json_writes_expected_fields(tmp_path: Path) -> None: record = CompositionRecord(notes=(1, 2, 3), per_note_seconds=(0.1, 0.2, 0.3), total_seconds=0.6) report = build_run_report(record) path = tmp_path / "report.json" save_run_report_json(report, str(path)) data = json.loads(path.read_text(encoding="utf-8")) assert data["notes"] == [1, 2, 3] assert data["total_seconds"] == 0.6