"""tests/dev1 conftest.py — worktree dispatch.py 우선 로드 보장."""
import sys
from pathlib import Path

# worktree 루트를 sys.path 최상위에 삽입하여
# 메인 workspace(/home/jay/workspace) dispatch.py보다 먼저 로드되도록 함
_WORKTREE_ROOT = Path(__file__).resolve().parents[2]
if str(_WORKTREE_ROOT) != sys.path[0]:
    # 이미 다른 conftest에서 삽입되었을 수 있으므로 앞에 재삽입
    if str(_WORKTREE_ROOT) in sys.path:
        sys.path.remove(str(_WORKTREE_ROOT))
    sys.path.insert(0, str(_WORKTREE_ROOT))

# 이미 캐시된 dispatch 모듈이 메인 workspace 것이면 제거 후 재로드
if "dispatch" in sys.modules:
    cached = sys.modules["dispatch"]
    if hasattr(cached, "__file__") and cached.__file__ and str(_WORKTREE_ROOT) not in cached.__file__:
        del sys.modules["dispatch"]
