"""Pure-logic tests for the commentary review loop (review_commentary.score_review)."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from review_commentary import score_review  # noqa: E402


def _row(t, verdict, better="", tag="", text="said", role="Caller", typ="play"):
    return {"t_sec": t, "verdict": verdict, "better": better, "tag": tag,
            "text": text, "role": role, "type": typ}


def test_report_card_counts_and_percentages():
    rows = [_row(1, "ok"), _row(2, "ok"), _row(3, "wrong"), _row(4, "dull")]
    res = score_review(rows)
    assert res["judged"] == 4
    assert res["counts"] == {"ok": 2, "wrong": 1, "dull": 1, "irrelevant": 0}
    assert res["pct"]["ok"] == 50 and res["pct"]["wrong"] == 25


def test_corrections_exclude_ok_and_carry_the_gold_line():
    rows = [_row(1, "ok", better="ignored"),
            _row(2, "wrong", better="the right call", tag="fact"),
            _row(3, "dull")]
    corr = score_review(rows)["corrections"]
    assert [c["t_sec"] for c in corr] == [2, 3]              # the ok row is NOT a correction
    bad = next(c for c in corr if c["t_sec"] == 2)
    assert bad["verdict"] == "wrong" and bad["better"] == "the right call" and bad["tag"] == "fact"
    assert bad["said"] == "said"                              # what was actually spoken (for the eval set)


def test_unjudged_and_unknown_verdicts_are_ignored():
    rows = [_row(1, ""), _row(2, "maybe"), _row(3, "OK"), _row(4, "Wrong")]   # blanks/junk dropped; case-insensitive
    res = score_review(rows)
    assert res["judged"] == 2                                 # only the OK + Wrong rows count
    assert res["counts"]["ok"] == 1 and res["counts"]["wrong"] == 1
