"""Verify CP-10 namespace cleanup — recoil/lib/ is gone, no stale imports."""

import sys
from pathlib import Path
import importlib

# Bootstrap sys.path so `from core.X` and `from lib.X` resolve.
_RECOIL_ROOT = Path(__file__).resolve().parents[3]
_PIPELINE_ROOT = _RECOIL_ROOT / "pipeline"
if str(_RECOIL_ROOT) not in sys.path:
    sys.path.insert(0, str(_RECOIL_ROOT))
if str(_PIPELINE_ROOT) not in sys.path:
    sys.path.insert(0, str(_PIPELINE_ROOT))


def test_recoil_lib_directory_deleted():
    recoil_root = Path(__file__).resolve().parents[3]
    assert not (recoil_root / "lib").is_dir(), "recoil/lib/ must be deleted in CP-10"


def test_canonical_imports_resolve():
    # All five moved modules resolve from recoil/core/.
    for mod in (
        "config_loader",
        "config_schema",
        "exceptions",
        "prompt_compiler",
        "prompt_validators",
    ):
        importlib.import_module(f"core.{mod}")


def test_pipeline_lib_canonical_modules_resolve():
    # The three remaining canonical modules resolve from pipeline/_lib/.
    # (_phase_a_exceptions shim was deleted in Phase 16 deprecation cleanup.)
    for mod in (
        "sanctioned_fallbacks",
        "take_keys",
        "schema_versions",
    ):
        importlib.import_module(f"recoil.pipeline._lib.{mod}")


def test_core_exceptions_resolves():
    # recoil.core.exceptions is the canonical home for the Phase A.1 family.
    importlib.import_module("recoil.core.exceptions")


def test_client_bridge_resolves():
    # Smoke-test client_bridge isn't broken-on-import.
    from recoil.pipeline._lib.client_bridge import load_client_storyboard  # noqa: F401
