"""sys.path bootstrap + shared path-shim fixture for orchestrator tests."""

from __future__ import annotations

import sys
import pathlib

# parent.parent.parent.parent of orchestrator/tests/conftest.py == recoil/
_RECOIL_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent
sys.path.insert(0, str(_RECOIL_ROOT.parent))  # worktree root → `recoil.*` imports
from recoil.core.paths import ensure_pipeline_importable  # noqa: E402

ensure_pipeline_importable()

# REC-18: reuse the path-shim helper that pipeline/core/tests uses so
# orchestrator tests pointing RECOIL_PROJECTS_ROOT at a pytest tmp dir get the
# same .recoil-data-root sentinel + project-dir auto-create treatment. The
# helper lives under pipeline/core/tests/; add that dir to sys.path to import
# it by module name.
sys.path.insert(0, str(_RECOIL_ROOT / "pipeline" / "core" / "tests"))

import pytest  # noqa: E402

from _test_paths_support import install_shims, set_basetemp  # noqa: E402


@pytest.fixture(autouse=True)
def recoil_data_root_sentinel(tmp_path_factory):
    """REC-18: make a test's tmp projects-root look like the real data root.

    See recoil/pipeline/core/tests/_test_paths_support.py for the full
    rationale. The shims fabricate the sentinel + project dirs ONLY for roots
    under pytest's session basetemp; production roots and the Law-4 guard are
    untouched.
    """
    set_basetemp(tmp_path_factory.getbasetemp())
    install_shims()
    yield
