# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-propagate-a-capability-attestation-it-cannot-locally-re-verify-the-transitive-trust-decay-boundary-in.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-propagate-a-capability-attestation-it-cannot-locally-re-verify-the-transitive-trust-decay-boundary-in.warrant.json
# Markdown SHA-256:   cfbd6ea88df8ad82046a930d45fb3f9f0e7db26077a7022f2939a82fd7da79cc
# Code AST SHA-256:   89a3369def20c13f1a9405acb0c759b6dd6dbf3ead959df8a1cf310ab330bd01
# Verified Classes:   UnboundedRevocationPath, Attestation
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class UnboundedRevocationPath(RuntimeError):
    """Raised when a transitive attestation's relay path has no independently
    observed upper bound on revocation-propagation latency, or when the relay's
    revocation-forwarding fidelity is unscored. Such an attestation must not be
    propagated; it may be quarantined and locally re-verified."""


class Attestation:
    def __init__(self, claim: str, relay_path: list[str], locally_reverifiable: bool):
        self.claim = claim
        self.relay_path = relay_path
        self.locally_reverifiable = locally_reverifiable


def propagation_decision(
    attestation: Attestation,
    revocation_latency_bound: dict[str, float | None],
    forwarding_fidelity_score: dict[str, float | None],
    fidelity_floor: float = 0.5,
) -> str:
    """Return one of 'propagate', 'propagate_dependent', 'quarantine'.

    Collapses 'unknown' (None) and 'unbounded' to the same branch: quarantine.
    """
    unbounded_hops = []
    for hop in attestation.relay_path:
        bound = revocation_latency_bound.get(hop)
        fidelity = forwarding_fidelity_score.get(hop)
        if bound is None:
            unbounded_hops.append((hop, "no observed latency bound"))
        elif fidelity is None:
            unbounded_hops.append((hop, "no forwarding-fidelity history"))
        elif fidelity < fidelity_floor:
            unbounded_hops.append((hop, f"fidelity {fidelity:.2f} below floor"))

    if unbounded_hops:
        if attestation.locally_reverifiable:
            # Holding instance may use it, but must not extend its reach.
            return "quarantine"
        hop, reason = unbounded_hops[0]
        raise UnboundedRevocationPath(
            f"refusing to propagate {attestation.claim!r}: relay hop {hop!r} "
            f"has unbounded revocation path ({reason}); local re-verification "
            f"unavailable, so the attestation cannot be safely extended."
        )

    if not attestation.locally_reverifiable:
        return "propagate_dependent"
    return "propagate"


def enforce(
    attestation: Attestation,
    revocation_latency_bound: dict[str, float | None],
    forwarding_fidelity_score: dict[str, float | None],
) -> None:
    decision = propagation_decision(
        attestation, revocation_latency_bound, forwarding_fidelity_score
    )
    if decision == "quarantine":
        # Emit fault upward; do not forward.
        print(f"quarantined {attestation.claim!r} at this instance")
    elif decision == "propagate_dependent":
        print(f"propagating {attestation.claim!r} with dependent=true tag")
    else:
        print(f"propagating {attestation.claim!r}")
