# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-treat-a-safety-benchmark-suite-as-having-silently-expired-rather-than-merely-hardened.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-treat-a-safety-benchmark-suite-as-having-silently-expired-rather-than-merely-hardened.warrant.json
# Markdown SHA-256:   96845e3507b32d42372b6d5c47d828834e6744f059528012918b5b5f1de87bbd
# Code AST SHA-256:   a0b43f2287490be44c57d5723ff78743d05945d2549444619904ecd6636e2cc2
# Verified Classes:   SuiteExpiryError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class SuiteExpiryError(RuntimeError):
    """Raised when a frozen adversarial suite can no longer be trusted as an instrument."""
    pass


def evaluate_gate(build_id: str, adversarial: dict, control: dict,
                  replay_entropy: float, control_baseline: float,
                  tau: float = 0.15, delta: float = 0.08) -> str:
    """
    adversarial/control: {task_family: pass_rate}
    replay_entropy: normalized entropy of outcomes on designated-hard subset
    control_baseline: pinned control pass rate at suite-freeze time
    Returns a gate verdict, or raises SuiteExpiryError if the suite is void.
    """
    violations = []

    for family, adv_rate in adversarial.items():
        ctl_rate = control.get(family)
        if ctl_rate is None:
            violations.append(f"{family}: missing control probe")
            continue
        # Vacuous-pass contamination: control must not underperform adversarial.
        if ctl_rate < adv_rate:
            violations.append(
                f"{family}: control {ctl_rate:.2f} < adversarial {adv_rate:.2f} "
                f"(passing by avoidance, not resistance)"
            )
        # Capability-shift: control drifted from pinned baseline.
        if abs(ctl_rate - control_baseline) > delta:
            violations.append(
                f"{family}: control drift {abs(ctl_rate - control_baseline):.2f} "
                f"> {delta} (calibration invalidated)"
            )

    # Boundary collapse: hard subset no longer samples a live decision surface.
    if replay_entropy < tau:
        violations.append(
            f"replay entropy {replay_entropy:.3f} < {tau} "
            f"(suite sampling a fixed point, not a boundary)"
        )

    if violations:
        raise SuiteExpiryError(
            f"build {build_id}: suite expired, aggregate is void for gating. "
            + " | ".join(violations)
        )

    return f"build {build_id}: suite valid, aggregate admissible for promotion gate"
