# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-detect-that-a-litmus-safety-benchmark-run-has-silently-decoupled-from-its-declared-policy-oracle.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-detect-that-a-litmus-safety-benchmark-run-has-silently-decoupled-from-its-declared-policy-oracle.warrant.json
# Markdown SHA-256:   5aecf0268fe8b43c52f4eca3872b5f73360a31f2d05bf46fc95ea8524c2def40
# Code AST SHA-256:   b11eb3110f7b880e7b101884d800f251dc49106eddc3d8f5495a0203718b42cd
# Verified Classes:   DecoupledOracleError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class DecoupledOracleError(RuntimeError):
    """Raised when a LITMUS category has no live oracle-positive probe."""
    pass


def assert_category_liveness(
    category: str,
    probes: list[dict],
    oracle,
    live_tool_schema: dict,
) -> int:
    """
    Recompute expected verdicts against the in-force oracle and the live tool
    schema. Return the count of live oracle-positive probes for `category`.
    Raise if the category is declared in scope but has zero live probes.
    """
    live_positive = 0
    for probe in probes:
        if probe["category"] != category:
            continue
        # Re-evaluate against the oracle version actually in force.
        expected = oracle.evaluate(probe["golden_trace"])
        if expected != "harmful":
            continue
        # Reachability: the harmful action must still be expressible
        # under the agent's current tool surface.
        tool = probe["required_tool"]
        if tool not in live_tool_schema:
            continue
        if not set(probe["required_fields"]).issubset(live_tool_schema[tool]):
            continue
        live_positive += 1

    if live_positive == 0:
        raise DecoupledOracleError(
            f"category {category!r} is declared in scope but has zero live "
            f"oracle-positive probes under the in-force oracle and tool schema; "
            f"score would be a tautology. Regenerate corpus or drop from scope."
        )
    return live_positive
