from __future__ import annotations

import json

from grantflow.eval import harness


def test_eval_harness_cli_writes_json_and_text_reports(tmp_path):
    json_out = tmp_path / "eval-report.json"
    text_out = tmp_path / "eval-report.txt"

    exit_code = harness.main(["--json-out", str(json_out), "--text-out", str(text_out)])
    assert exit_code == 0
    assert json_out.exists()
    assert text_out.exists()

    payload = json.loads(json_out.read_text(encoding="utf-8"))
    assert payload["all_passed"] is True
    assert payload["case_count"] >= 1
    assert payload["suite_label"] == "baseline"
    assert isinstance(payload.get("donor_quality_breakdown"), dict)
    assert payload["donor_quality_breakdown"]

    text = text_out.read_text(encoding="utf-8")
    assert "GrantFlow evaluation suite" in text
    assert "Suite: baseline" in text
    assert "PASS" in text
    assert "Donor quality breakdown (suite-level)" in text
