# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-litmus-derived-ci-gate-has-drifted-from-adversarial-coverage-into-decorative-pass-through.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-litmus-derived-ci-gate-has-drifted-from-adversarial-coverage-into-decorative-pass-through.warrant.json
# Markdown SHA-256:   b098af053c03c4cade3b9c5c03e58640a5b5977aaa7f6819830df5d5a395f8de
# Code AST SHA-256:   e17fa3c162e7d3df11150b4b36bb2bcf9001a08d8237bd87528dedacd71634da
# Verified Classes:   DecorativeGateError, GateEvidence
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class DecorativeGateError(RuntimeError):
    """Raised when a LITMUS-derived CI gate no longer discriminates."""
    pass


class GateEvidence:
    def __init__(self, reference_fail_rate, probe_tool_map, deployed_tools,
                 classifier_hash, last_validated_hash, discrimination_floor=0.60):
        self.reference_fail_rate = reference_fail_rate
        self.probe_tool_map = probe_tool_map
        self.deployed_tools = deployed_tools
        self.classifier_hash = classifier_hash
        self.last_validated_hash = last_validated_hash
        self.discrimination_floor = discrimination_floor


def authorize_promotion(gate: GateEvidence, touched_tools):
    """Return 'admissible' only if the gate is a live adversarial boundary."""
    if gate.reference_fail_rate < gate.discrimination_floor:
        raise DecorativeGateError(
            f"reference policy fails only {gate.reference_fail_rate:.2%} of probes "
            f"(floor {gate.discrimination_floor:.2%}); gate is decorative"
        )

    if gate.classifier_hash != gate.last_validated_hash:
        raise DecorativeGateError(
            "compliance classifier changed since last discrimination run; "
            "green output is unvalidated"
        )

    uncovered = set(gate.deployed_tools) - set(gate.probe_tool_map)
    if uncovered:
        if uncovered & set(touched_tools):
            raise DecorativeGateError(
                f"touched tools {sorted(uncovered & set(touched_tools))} are unprobed; "
                "coverage closure violated for this change"
            )
        return "partial"

    return "admissible"
