The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): name a shared checkout's owner by the interpreter its launcher execs
unsupportedpastels282a729cd12a
diff --git a/pm/environments.py b/pm/environments.pyindex 48562228a60..95423b67e43 100644--- a/pm/environments.py+++ b/pm/environments.py@@ -50,17 +50,20 @@ def owning_home_root(project_root: Path) -> Path | None:such root has state for this checkout -- a fresh install, or a custom root that owns its owntree -- so those keep today's behaviour (#123238).- The root the checkout sits in outranks the platform default: a borrowing launch's own sync- leaves ``facts.json`` under the borrower too, and that must never make it the owner.+ A borrowing launch's own sync leaves ``facts.json`` under the borrower too, so state alone+ cannot name the owner. The checkout's ``hermes`` launcher can: only the owner publishes it,+ and it execs the owner's store Python. With no live launcher to ask, the root the checkout+ sits in outranks the platform default."""from hermes_constants import _get_platform_default_hermes_homeroot = Path(project_root).resolve()key = install_key(root)- owner = next((candidate for candidate in (root.parent, _get_platform_default_hermes_home())- if (candidate / "installs" / key / "facts.json").is_file()), None)- if owner is None:+ candidates = [candidate for candidate in dict.fromkeys((root.parent, _get_platform_default_hermes_home()))+ if (candidate / "installs" / key / "facts.json").is_file()]+ if not candidates:return None+ owner = _launcher_bound_root(root, candidates) or candidates[0]try:if (owner / "installs" / key).resolve() == install_state_dir(root).resolve():return None@@ -69,6 +72,25 @@ def owning_home_root(project_root: Path) -> Path | None:return owner+def _launcher_bound_root(project_root: Path, candidates: list[Path]) -> Path | None:+ """The candidate whose ``tools/`` holds the live interpreter the checkout's launcher execs."""+ from hermes_cli._launchers import _launcher_python++ local = project_root / ".hermes" / "bin"+ for name in (("hermes.exe", "hermes.cmd") if os.name == "nt" else ("hermes",)):+ python = _launcher_python(local / name)+ if python is None or not python.is_file():+ continue+ for candidate in candidates:+ try:+ store = (candidate / "tools").resolve()+ if any(parent.resolve() == store for parent in python.parents):+ return candidate+ except (OSError, RuntimeError, ValueError):+ continue+ return None++def install_state_permission_message(project_root: Path, exc: PermissionError) -> str | None:"""Describe an access failure inside this install's dependency state."""if not exc.filename:diff --git a/tests/hermes_cli/test_borrowed_home_launch.py b/tests/hermes_cli/test_borrowed_home_launch.pyindex 1ce07bd21a7..f90c0eae24e 100644--- a/tests/hermes_cli/test_borrowed_home_launch.py+++ b/tests/hermes_cli/test_borrowed_home_launch.py@@ -95,6 +95,38 @@ def test_a_borrowers_own_dependency_state_never_makes_it_the_owner(tmp_path, monassert store_root(root) == custom / "tools"+def test_a_borrower_holding_the_checkout_never_becomes_its_owner(tmp_path, monkeypatch):+ """`install.sh --dir <dir>` puts the default root's checkout in <dir>. Launching it with+ HERMES_HOME=<dir> borrows, and still borrows after that root's own sync leaves state."""+ import os++ import pm+ from hermes_cli import _launchers++ default = tmp_path / ".hermes"+ holder = tmp_path / "data" / "dir"+ root = _checkout(tmp_path, monkeypatch, parent=holder)+ entry = default / "tools" / "python-owner"+ python = entry / ("python.exe" if os.name == "nt" else "bin/python3")+ python.parent.mkdir(parents=True)+ python.touch()+ (default / "tools" / "facts.json").write_text(json.dumps(+ {"schema": 1, "packages": {"python": {"version": "fixture", "entry": entry.name}}}), encoding="utf-8")+ _state(default, root)+ _home(monkeypatch, default)+ local = root / ".hermes" / "bin"+ published = {path: Path(path).read_bytes() for path in _launchers.ensure_install_launchers(root, local)}+ assert published++ _home(monkeypatch, holder)+ _state(holder, root) # the borrowing launch's own sync+ assert owning_home_root(root) == default+ assert store_root(root) == default / "tools"+ monkeypatch.setattr(pm, "venv_is_current", lambda **kwargs: True)+ assert venv_sync.prepare_launch(root, []) == python+ assert {path: Path(path).read_bytes() for path in published} == published++def test_a_borrowing_launch_syncs_its_own_dependencies_and_nothing_of_the_checkout(tmp_path, monkeypatch, completion_tail):