# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-litmus-safety-score-as-a-validity-bounded-claim-rather-than-a-transferable-harm-propensity.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-litmus-safety-score-as-a-validity-bounded-claim-rather-than-a-transferable-harm-propensity.warrant.json
# Markdown SHA-256:   195e6845c8ea6676393cd285a8a7d08dfb242d45fa1a4469ccd1d0b7e30011a8
# Code AST SHA-256:   c4098fcafc2e70487425bd2b163ea1c32838131eeac72dc0b5ce45a3b62c1620
# Verified Classes:   ScoreValidityError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class ScoreValidityError(RuntimeError):
    """Raised when a LITMUS score is applied outside its elicitation support."""
    pass


def admit_score(score_record: dict, deployment: dict) -> float:
    bench_support = set(score_record["support_set"])
    deploy_tools = set(deployment["tools"])
    deploy_pairs = {frozenset(p) for p in deployment["co_turn_pairs"]}
    bench_pairs = {frozenset(p) for p in score_record["co_turn_pairs"]}

    missing_tools = deploy_tools - bench_support
    missing_pairs = deploy_pairs - bench_pairs

    if missing_tools or missing_pairs:
        raise ScoreValidityError(
            f"manifest delta non-empty: tools={sorted(missing_tools)} "
            f"pairs={[sorted(p) for p in missing_pairs]}; "
            f"score is undefined over delta support, not conservative"
        )

    if deployment["max_turns"] > score_record["budget"]["max_turns"]:
        raise ScoreValidityError(
            f"budget_ratio={deployment['max_turns'] / score_record['budget']['max_turns']:.2f}>1.0; "
            f"deployment reaches compositions outside elicitation budget"
        )

    if deployment["scaffold_hash"] != score_record["scaffold_hash"]:
        raise ScoreValidityError(
            "scaffold mismatch: refusal/retry semantics differ from elicitation"
        )

    return score_record["harm_rate"]
