Something went wrong. Try again.
Integrated repository, worktree, git stacker, and project manager
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import pytest
from project_manager.errors import ProjectErrorfrom project_manager.paths import Pathsfrom project_manager.project import add as add_modfrom project_manager.project import currentfrom project_manager.project import detach as detach_modfrom tests.helpers import git_pool
def _mk_pool(paths: Paths, repo: str, uuids: list[str]) -> None: (paths.worktrees / repo).mkdir() for u in uuids: (paths.worktrees / repo / u).mkdir()
def _just(wts: list[str]) -> list[tuple[str, str]]: return [(w, w) for w in wts]
def _chdir(monkeypatch: pytest.MonkeyPatch, path) -> None: monkeypatch.chdir(path) monkeypatch.setenv("PWD", str(path))
def test_detects_from_forward_path(pm_env: Paths, monkeypatch: pytest.MonkeyPatch) -> None: _mk_pool(pm_env, "foo", ["a"]) add_mod.add(pm_env, "demo", _just(["foo"])) _chdir(monkeypatch, pm_env.projects / "demo" / "foo") assert current.detect_current_project(pm_env) == "demo"
def test_detects_from_physical_worktree_via_pool_db( pm_env: Paths, monkeypatch: pytest.MonkeyPatch,) -> None: _mk_pool(pm_env, "foo", ["a"]) add_mod.add(pm_env, "demo", _just(["foo"])) _chdir(monkeypatch, pm_env.worktrees / "foo" / "a") assert current.detect_current_project(pm_env) == "demo"
def test_detach_while_inside_worktree_clears_detection( pm_env: Paths, monkeypatch: pytest.MonkeyPatch,) -> None: """After detach the pool row is gone, so worktree-path detection can't recover the project name. Users in this corner case must pass the name explicitly. """ slots = git_pool(pm_env, "foo", n=1) add_mod.add(pm_env, "demo", _just(["foo"])) detach_mod.detach(pm_env, "demo", wts=None) _chdir(monkeypatch, slots[0].path) assert current.detect_current_project(pm_env) is None
def test_resolve_project_prefers_explicit( pm_env: Paths, monkeypatch: pytest.MonkeyPatch,) -> None: _mk_pool(pm_env, "foo", ["a"]) add_mod.add(pm_env, "demo", _just(["foo"])) _chdir(monkeypatch, pm_env.projects / "demo" / "foo") assert current.resolve_project(pm_env, "other") == "other"
def test_resolve_project_raises_when_nothing_to_detect( pm_env: Paths, tmp_path, monkeypatch: pytest.MonkeyPatch,) -> None: _chdir(monkeypatch, tmp_path) with pytest.raises(ProjectError, match="no project specified"): current.resolve_project(pm_env, None)