# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-detect-delegated-authority-attenuation-failure-at-a-federation-trust-boundary-before-executing-a-policy-bounded-tool-call.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-detect-delegated-authority-attenuation-failure-at-a-federation-trust-boundary-before-executing-a-policy-bounded-tool-call.warrant.json
# Markdown SHA-256:   2df8e2e7f95c09e0df2a87fa23d3d3c3f9ced7e50d3c0405d750023dce17194e
# Code AST SHA-256:   aa0c90e1a223e5629fb05238d920de3285667e11fc7c10a992d43ae59d7013de
# Verified Classes:   AuthorityAmplificationError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class AuthorityAmplificationError(RuntimeError):
    """Raised when a delegated warrant's scope exceeds the delegator's residual scope."""
    pass


def validate_delegation_edge(
    parent_residual_scope: frozenset[str],
    child_warrant_scope: frozenset[str],
    child_warrant_signature_valid: bool,
    capability_in_registry: bool,
) -> None:
    # Signature validity is necessary but not sufficient.
    if not child_warrant_signature_valid:
        raise AuthorityAmplificationError(
            "warrant signature invalid; cannot establish delegator identity"
        )

    # Registry membership proves shape, never authority.
    if not capability_in_registry:
        raise AuthorityAmplificationError(
            "requested capability absent from federation registry; schema mismatch"
        )

    # The invariant: child scope must be a subset of parent residual scope.
    amplified = child_warrant_scope - parent_residual_scope
    if amplified:
        raise AuthorityAmplificationError(
            f"authority amplification at delegation edge: "
            f"capabilities {sorted(amplified)} exceed delegator residual scope "
            f"{sorted(parent_residual_scope)}; refusing to propagate warrant"
        )
