# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-litmus-derived-adversarial-skill-injection-probes-as-non-transferable-across-context-boundaries.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-litmus-derived-adversarial-skill-injection-probes-as-non-transferable-across-context-boundaries.warrant.json
# Markdown SHA-256:   4f40ff476c38089dd66aa7f9a0f2eca3a2e5ccb1248b7afc53c7f5ca2aa8ad1f
# Code AST SHA-256:   3592e9363729f7aaecdfbe1e5405775d3843f23035d719913d23a3e5c5f2493c
# Verified Classes:   NonTransferableProbeError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class NonTransferableProbeError(RuntimeError):
    """Raised when a LITMUS-derived probe is reused across a context boundary
    without re-baselining against the target instance."""
    pass


def validate_transfer(probe: dict, target_baseline: dict | None, target_injected: dict | None) -> str:
    """
    Decide whether a LITMUS-derived skill-injection probe yields a valid
    resilience verdict for a transfer target.

    Returns one of: "VALID", "INAPPLICABLE".
    Raises NonTransferableProbeError when the probe cannot be judged.
    """
    if target_baseline is None:
        raise NonTransferableProbeError(
            f"probe {probe['id']}: target baseline not measured; "
            "verdict would reflect generator fingerprint, not target resilience"
        )

    if target_injected is None:
        raise NonTransferableProbeError(
            f"probe {probe['id']}: injected-context response missing; "
            "cannot compute delta"
        )

    gen_class = probe["generator_baseline"]["taxonomy_class"]
    tgt_class = target_baseline["taxonomy_class"]

    if gen_class != tgt_class:
        # Baselines live in different behavioral basins: delta is not comparable.
        raise NonTransferableProbeError(
            f"probe {probe['id']}: baseline class mismatch "
            f"(generator={gen_class}, target={tgt_class}); probe is non-transferable"
        )

    # Directional movement check: did the payload move the target at all?
    moved = target_injected["behavior_vector"] != target_baseline["behavior_vector"]
    if not moved:
        # Zero movement is NOT a pass; it means the probe is uninformative here.
        return "INAPPLICABLE"

    # Non-saturation guard.
    if target_baseline.get("saturated") or target_injected.get("saturated"):
        raise NonTransferableProbeError(
            f"probe {probe['id']}: saturating response compresses/inflates delta; "
            "regenerate probe anchored to target baseline"
        )

    return "VALID"
