# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-honor-a-delegated-consent-chain-in-the-aaif-scoped-capability-token-model.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-honor-a-delegated-consent-chain-in-the-aaif-scoped-capability-token-model.warrant.json
# Markdown SHA-256:   8ff2dde72ef2e575973e67f38e62216796114ab3c78ab85573c5462187882667
# Code AST SHA-256:   6a5d0f5f968c35af66d348f7190c29c54cc817ceb915cdf51964f7fd5063a497
# Verified Classes:   DelegationDenialOmissionError, Scope, ChainLink
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class DelegationDenialOmissionError(RuntimeError):
    """Raised when a delegated chain drops a parent's negative scope clauses."""
    pass


class Scope:
    def __init__(self, verb: str, pattern: str, negated: bool = False):
        self.verb = verb
        self.pattern = pattern
        self.negated = negated

    def covers(self, verb: str, path: str) -> bool:
        if self.verb != verb and self.verb != "*":
            return False
        prefix = self.pattern.rstrip("*")
        return path.startswith(prefix)


class ChainLink:
    def __init__(self, scopes, propagate_denials: bool):
        self.scopes = scopes
        self.propagate_denials = propagate_denials

    def negatives(self):
        return [s for s in self.scopes if s.negated]


def authorize(chain, verb: str, path: str, parent_resolvable: bool) -> bool:
    # Condition 5: detect dropped denials at any boundary.
    for i, link in enumerate(chain):
        if i == 0:
            continue
        parent = chain[i - 1]
        if parent.negatives() and not link.propagate_denials:
            if any(s.covers(verb, path) for s in parent.negatives()):
                if not parent_resolvable:
                    raise DelegationDenialOmissionError(
                        f"link {i} dropped denials from link {i-1}; "
                        f"cannot resolve parent chain for {verb} {path}"
                    )
    # Positive intersection and negative union.
    positives = [s for link in chain for s in link.scopes if not s.negated]
    negatives = [s for link in chain for s in link.scopes if s.negated]
    allowed = any(s.covers(verb, path) for s in positives)
    denied = any(s.covers(verb, path) for s in negatives)
    return allowed and not denied
