# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-distrust-a-static-skill-descriptor-audit-when-runtime-capability-diffing-shows-no-diff.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-distrust-a-static-skill-descriptor-audit-when-runtime-capability-diffing-shows-no-diff.warrant.json
# Markdown SHA-256:   6f8e42f57f9f1b6fe88bea75071c6e788b24fa305545b7394a720b783364db9e
# Code AST SHA-256:   5c41406c992add710f9bf402fc48299d384fc5681314dac64430b79eea74ccac
# Verified Classes:   CapabilityDiffVacuityError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class CapabilityDiffVacuityError(RuntimeError):
    """Raised when an admission decision treats an empty runtime capability diff
    as evidence of safety despite insufficient branch coverage of skill code."""
    pass


def admit_skill(
    declared_caps: set[str],
    reachable_caps: set[str],
    exercised_caps: set[str],
    branch_coverage: float,
    policy: set[str],
    coverage_threshold: float = 0.85,
) -> str:
    # Static reachability is a superset witness: decisive if it exceeds policy.
    unexpected_reachable = reachable_caps - policy
    if unexpected_reachable:
        return f"REJECT: reachable capability outside policy: {sorted(unexpected_reachable)}"

    # Runtime diff is a subset witness. An empty diff is only corroborating
    # when coverage is high enough that non-observation is meaningful.
    diff = exercised_caps - declared_caps
    if diff:
        return f"REJECT: exercised capability not declared: {sorted(diff)}"

    if branch_coverage < coverage_threshold:
        # Empty diff + low coverage is the dangerous middle: looks like a pass.
        # Do NOT admit on the strength of the empty diff.
        raise CapabilityDiffVacuityError(
            f"empty capability diff is vacuous: branch_coverage={branch_coverage:.2f} "
            f"< {coverage_threshold:.2f}; skill code paths were not exercised, "
            f"so non-observation of {sorted(policy - exercised_caps)} is not evidence. "
            f"Route to shadow tier with syscall enforcement."
        )

    return "ADMIT: reachable within policy and diff corroborated by high coverage"
