# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-refuse-a-federated-peer-s-re-signed-capability-warrant-when-trust-anchor-rotation-outpaces-policy-negotiation.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-refuse-a-federated-peer-s-re-signed-capability-warrant-when-trust-anchor-rotation-outpaces-policy-negotiation.warrant.json
# Markdown SHA-256:   8fc80a2e01455323bb54be54530a6a467dd11e75d01715a9e296d61fc0fc5bbd
# Code AST SHA-256:   701eecd1c16d7e4e707c38609918ef324026cfa2f875edd33950d45985308aec
# Verified Classes:   StaleGenerationWarrantError, Warrant, AnchorMetadata
# Defensive Guards:   4 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class StaleGenerationWarrantError(RuntimeError):
    """Raised when a re-signed warrant's asserted policy_generation predates
    the governing generation of the anchor that terminates its chain."""
    pass


@dataclass(frozen=True)
class Warrant:
    subject: str
    asserted_generation: int
    terminating_anchor: str
    signature_chain_valid: bool


@dataclass(frozen=True)
class AnchorMetadata:
    anchor_id: str
    governing_generation: int


def admit_warrant(warrant: Warrant, anchor: AnchorMetadata) -> None:
    if warrant.terminating_anchor != anchor.anchor_id:
        raise StaleGenerationWarrantError(
            f"anchor mismatch: warrant terminates at {warrant.terminating_anchor}, "
            f"verifier holds metadata for {anchor.anchor_id}"
        )
    if not warrant.signature_chain_valid:
        raise StaleGenerationWarrantError(
            f"signature chain invalid for subject {warrant.subject}"
        )
    # The load-bearing invariant: cryptographic validity is not admissibility.
    if warrant.asserted_generation < anchor.governing_generation:
        raise StaleGenerationWarrantError(
            f"privilege laundering blocked: warrant for {warrant.subject} asserts "
            f"policy_generation={warrant.asserted_generation}, but anchor "
            f"{anchor.anchor_id} now governs generation={anchor.governing_generation}. "
            f"Force re-negotiation and invalidate derived sub-warrants."
        )
    if warrant.asserted_generation > anchor.governing_generation:
        raise StaleGenerationWarrantError(
            f"anchor metadata lag: warrant generation={warrant.asserted_generation} "
            f"exceeds known generation={anchor.governing_generation}; refresh metadata"
        )
    # Generation equality: admissible.
