# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-draw-the-line-between-a-benchmark-s-adversarial-fixture-and-its-own-live-tool-surface-during-litmus-regression-gating.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-draw-the-line-between-a-benchmark-s-adversarial-fixture-and-its-own-live-tool-surface-during-litmus-regression-gating.warrant.json
# Markdown SHA-256:   9c496fc72627099c49c314778680a1720edee8176f3dc3f4468e7b7a488c3bb1
# Code AST SHA-256:   2fc41c6adf8847a8e1a6d0347e27fe21a6cb3a01562a217acc1416bef32e20ec
# Verified Classes:   FixtureBleedError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class FixtureBleedError(RuntimeError):
    """Raised when an adversarial fixture's verdict is contaminated by harness control-plane state."""
    pass


CONTROL_PLANE_PREFIXES = ("harness.", "litmus.", "_verdict.")


def admit_verdict(case_id: str, tool_calls: list[dict], scratch_was_clean: bool,
                  replay_verdicts: list[str]) -> str:
    # Invariant 1: no control-plane symbol reachable from the instance namespace.
    for call in tool_calls:
        name = call.get("name", "")
        if any(name.startswith(p) for p in CONTROL_PLANE_PREFIXES):
            raise FixtureBleedError(
                f"{case_id}: instance invoked control-plane symbol {name!r}; "
                f"manifest exemption leaked harness authority into the test surface"
            )

    # Invariant 2: no cross-case state contamination.
    if not scratch_was_clean:
        raise FixtureBleedError(
            f"{case_id}: scratch namespace not cleared before replay; "
            f"verdict is non-deterministic with respect to prior-case residue"
        )

    # Invariant 3: signal integrity — provenance must be fixture-declared.
    for call in tool_calls:
        if call.get("provenance") == "harness_instrumentation":
            raise FixtureBleedError(
                f"{case_id}: tool result produced by harness instrumentation "
                f"({call.get('name')}), not the declared fixture mock; suppress verdict"
            )

    # Invariant 4: cold replays must agree before admission to the baseline.
    if len(set(replay_verdicts)) != 1:
        raise FixtureBleedError(
            f"{case_id}: cold replays disagree {replay_verdicts}; "
            f"verdict cannot be admitted to the regression gate"
        )

    return replay_verdicts[0]
