# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-litmus-multi-turn-pressure-scores-as-non-transferable-evidence-of-agent-harm-tolerance.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-litmus-multi-turn-pressure-scores-as-non-transferable-evidence-of-agent-harm-tolerance.warrant.json
# Markdown SHA-256:   b203cbd40bf182e47096fe20d70869113f88b3f7b4ea2c20636d94c449b28036
# Code AST SHA-256:   01b796b59fa93342461e10c5b398d26ea3d2daf021a3ffe45952d66a3f47c6b9
# Verified Classes:   ScheduleIncommensurableError, LitmusScore, DeploymentRegime
# Defensive Guards:   5 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class ScheduleIncommensurableError(RuntimeError):
    """Raised when a LITMUS score is consumed or compared without a
    schedule tuple that dominates the deployment's pressure horizon."""


@dataclass(frozen=True)
class LitmusScore:
    aggregate: float
    schedule_length: int          # turns the suite actually ran
    max_pressure_turn: int        # schedule position of strongest probe
    shared_context: bool          # accumulated-framing vs. reset-per-turn
    per_turn_refusal: tuple       # must be non-empty; length == schedule_length


@dataclass(frozen=True)
class DeploymentRegime:
    max_session_turns: int
    shared_context: bool


def admit_score(score: LitmusScore, regime: DeploymentRegime) -> float:
    if not score.per_turn_refusal or len(score.per_turn_refusal) != score.schedule_length:
        raise ScheduleIncommensurableError(
            f"per-turn refusal curve missing or length-mismatched: "
            f"len={len(score.per_turn_refusal)} schedule={score.schedule_length}"
        )
    if score.shared_context != regime.shared_context:
        raise ScheduleIncommensurableError(
            "context regime mismatch: suite measured a different construct "
            f"(suite shared_context={score.shared_context}, "
            f"deployment shared_context={regime.shared_context})"
        )
    if score.schedule_length < regime.max_session_turns:
        raise ScheduleIncommensurableError(
            f"suite horizon {score.schedule_length} does not dominate "
            f"deployment horizon {regime.max_session_turns}; score is an "
            "upper bound on safety, not an estimate"
        )
    if score.max_pressure_turn < 1 or score.max_pressure_turn > score.schedule_length:
        raise ScheduleIncommensurableError(
            f"max_pressure_turn {score.max_pressure_turn} outside schedule "
            f"[1, {score.schedule_length}]"
        )
    return score.aggregate


def compare_scores(a: LitmusScore, b: LitmusScore) -> float:
    if (a.schedule_length, a.max_pressure_turn, a.shared_context) != (
        b.schedule_length, b.max_pressure_turn, b.shared_context
    ):
        raise ScheduleIncommensurableError(
            "refusing to compare scores with differing schedule tuples; "
            "differences reflect schedule position, not agent harm tolerance"
        )
    return a.aggregate - b.aggregate
