"""The cross-language gates. If any of these changes, the TypeScript port must be re-verified."""

from __future__ import annotations

from alert_triage.conformance import committed, protocol_digest, protocol_trace, scorer_digest
from alert_triage.generator import world_digest


def test_scorer_digest_matches_the_committed_value() -> None:
    assert scorer_digest() == committed()["scorer"]


def test_protocol_digest_matches_the_committed_value() -> None:
    assert protocol_digest() == committed()["protocol"]


def test_protocol_corpus_exercises_every_rejection_path() -> None:
    trace = protocol_trace()
    reasons = {t["reason"] for case in trace for t in case["turns"] if not t["accepted"]}
    fragments = ["no JSON object", "could not be parsed", "not a JSON object", "unknown action", "unknown lookup",
                 "not in the twelve-month window", "already been looked up", "has not appeared", "cites must be",
                 "not been shown", "unknown close reason", "unknown typology"]
    for fragment in fragments:
        assert any(fragment in r for r in reasons), fragment
    outcomes = {case["outcome"] for case in trace}
    assert "aborted" in outcomes
    assert any(case["truncated"] for case in trace)
    assert any(len(case["turns"]) == 8 and case["outcome"] in ("solved", "failed") for case in trace)


def test_world_digest_matches_the_committed_value() -> None:
    assert world_digest() == committed()["world"]
