# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-litmus-safety-benchmark-pass-fail-as-a-scoped-attestation-rather-than-a-portable-safety-invariant.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-litmus-safety-benchmark-pass-fail-as-a-scoped-attestation-rather-than-a-portable-safety-invariant.warrant.json
# Markdown SHA-256:   c7474a56ecbe083f3d7553c8f24a1dfca38ac7d4286f48274685509cc75bc44f
# Code AST SHA-256:   9634cf271bf96ca48f7dd14f57f4afe39d5f4e775ceb20c57dc86b92ff845eb5
# Verified Classes:   LITMUSScopeViolation
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class LITMUSScopeViolation(RuntimeError):
    """Raised when a LITMUS pass is promoted to a portable invariant
    outside the configuration envelope the harness actually exercised."""


REQUIRED_AXES = ("context_saturation", "tool_set_variation", "trajectory_scoped_scoring")


def promote_attestation(attestation: dict, target_config: dict) -> None:
    """Promote a LITMUS pass to a release-gating invariant only if the
    attestation's coverage and config binding are sound."""
    if attestation.get("scorer_scope") != "trajectory":
        raise LITMUSScopeViolation(
            f"turn-scoped scorer cannot gate trajectory-scoped policy; "
            f"scope={attestation.get('scorer_scope')!r}"
        )
    missing = [ax for ax in REQUIRED_AXES if ax not in attestation.get("covered_axes", ())]
    if missing:
        raise LITMUSScopeViolation(
            f"corpus did not exercise required axes {missing}; "
            f"pass is a scoped observation, not an invariant"
        )
    if attestation.get("forbidden_attempt_count", 0) > 0:
        raise LITMUSScopeViolation(
            f"{attestation['forbidden_attempt_count']} forbidden actions were "
            f"attempted and externally denied; sandbox denial is not policy compliance"
        )
    if attestation.get("config_hash") != target_config.get("config_hash"):
        raise LITMUSScopeViolation(
            f"attestation bound to config {attestation.get('config_hash')!r} "
            f"cannot gate config {target_config.get('config_hash')!r}"
        )
    attestation["promoted"] = True
