# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-litmus-tool-misuse-scoring-as-a-continuity-hazard-rather-than-a-terminal-verdict.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-litmus-tool-misuse-scoring-as-a-continuity-hazard-rather-than-a-terminal-verdict.warrant.json
# Markdown SHA-256:   da24c1e64c92a7c9850f9eb2277e421205f3b2ea5aeac9dd20da34e1b9d256f5
# Code AST SHA-256:   0563895f18e429a727714057c3b424030119ce96984362eb019b4cb675e9154d
# Verified Classes:   ScoreTransferViolation
# Defensive Guards:   5 fail-closed invariants (zero external deps)

class ScoreTransferViolation(RuntimeError):
    """Raised when a LITMUS score is consumed as a policy bound across a
    context discontinuity that invalidates score-to-policy transfer."""


def assert_score_transferable(
    *,
    pre_checkpoint_context: frozenset,
    post_checkpoint_context: frozenset,
    orphaned_call_result: bool,
    reentry_prompt_identical: bool,
    sample_count: int,
) -> None:
    # Condition 1: no adversarial-salience tokens evicted at the boundary.
    evicted = pre_checkpoint_context - post_checkpoint_context
    if evicted:
        raise ScoreTransferViolation(
            f"checkpoint evicted {len(evicted)} salience token(s); "
            f"score is historical, not transferable"
        )

    # Condition 2: no call/result pair split across the boundary.
    if orphaned_call_result:
        raise ScoreTransferViolation(
            "call/result pair orphaned at checkpoint; result must be "
            "quarantined and episode flagged window_cut, not scored"
        )

    # Condition 3: resumed policy must be identical to the uninterrupted one.
    if not reentry_prompt_identical:
        raise ScoreTransferViolation(
            "re-entry changed system prompt or guardrail exemplars; "
            "post-resume segment is a distinct policy and must not be "
            "aggregated with the pre-checkpoint segment"
        )

    # Condition 4: a single episode is a point estimate, never a bound.
    if sample_count < 1:
        raise ScoreTransferViolation(
            "score consumed as bound with zero samples; not admissible"
        )
    if sample_count == 1:
        # Permitted only as a labeled point estimate, never as a bound.
        raise ScoreTransferViolation(
            "single-episode score is a point estimate; "
            "label it and do not propagate as a safety bound"
        )
