"""task-2660 Phase 2 regression — sys.path bootstrap (worktree 우선).

tests/conftest.py 가 /home/jay/workspace 를 sys.path 에 등록하기 때문에
worktree 의 변경 사항을 그대로 검증하려면 worktree REPO_ROOT 를 sys.path[0] 에 두고
이미 로드된 dispatch 캐시를 제거하여 worktree 의 helper.py 를 우선 import 한다.
"""
import pathlib
import sys

REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
_repo_root_str = str(REPO_ROOT)
# 메인 워크스페이스보다 우선 등록 (sys.path[0])
if sys.path and sys.path[0] != _repo_root_str:
    try:
        sys.path.remove(_repo_root_str)
    except ValueError:
        pass
    sys.path.insert(0, _repo_root_str)
# 메인 워크스페이스에서 미리 로드된 dispatch 캐시 무효화 → 다음 import 시 worktree 로 해석
for _mod in list(sys.modules.keys()):
    if _mod == "dispatch" or _mod.startswith("dispatch."):
        del sys.modules[_mod]
