The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(cli): keep the #123238 tests to their invariant contracts
unsupportedpastelsd09fdec5fa21
diff --git a/tests/hermes_cli/test_borrowed_home_launch.py b/tests/hermes_cli/test_borrowed_home_launch.pyindex 7511a3330ae..153561af712 100644--- a/tests/hermes_cli/test_borrowed_home_launch.py+++ b/tests/hermes_cli/test_borrowed_home_launch.py@@ -8,7 +8,6 @@ dependency sync leaves.from __future__ import annotationsimport json-import osfrom pathlib import Pathimport sys@@ -67,30 +66,6 @@ def _home(monkeypatch, path: Path) -> Path:return path-def test_a_temporary_home_borrows_the_default_roots_checkout(tmp_path, monkeypatch):- root = _checkout(tmp_path, monkeypatch)- owner = tmp_path / ".hermes"- _state(owner, root)- _home(monkeypatch, tmp_path / "tmp" / "hermes-test-a")-- assert owning_home_root(root) == owner- assert store_root(root) == owner / "tools"--[email protected]("home", ["default", "profile"])-def test_the_owner_and_its_profiles_are_not_borrowers(tmp_path, monkeypatch, home):- root = _checkout(tmp_path, monkeypatch)- owner = tmp_path / ".hermes"- _state(owner, root)- if home == "profile":- _home(monkeypatch, owner / "profiles" / "work")- else:- monkeypatch.delenv("HERMES_HOME", raising=False)-- assert owning_home_root(root) is None- assert store_root(root) == owner / "tools"--def test_a_fresh_install_and_a_custom_root_keep_their_own_store(tmp_path, monkeypatch):# Nobody has state yet: the launching root is about to become the owner.root = _checkout(tmp_path, monkeypatch, parent=tmp_path / "data" / "h")@@ -106,38 +81,6 @@ def test_a_fresh_install_and_a_custom_root_keep_their_own_store(tmp_path, monkeyassert store_root(root) == tmp_path / "data" / "h" / "tools"-def test_a_service_home_borrows_the_root_the_checkout_sits_in(tmp_path, monkeypatch):- """A CI runner whose HOME is its own tool-home runs the host's checkout from PATH: the host's- root is the checkout's parent, not this process's platform default."""- host = tmp_path / "host" / ".hermes"- root = _checkout(tmp_path / "runner", monkeypatch, parent=host)- _state(host, root)- _home(monkeypatch, tmp_path / "runner" / ".hermes" / "pytest-1")-- assert owning_home_root(root) == host- assert store_root(root) == host / "tools"--[email protected](not hasattr(os, "symlink") or sys.platform == "win32", reason="POSIX symlink")-def test_a_home_whose_installs_link_back_to_the_owner_is_the_owner(tmp_path, monkeypatch):- root = _checkout(tmp_path, monkeypatch)- owner = tmp_path / ".hermes"- _state(owner, root)- task = _home(monkeypatch, tmp_path / "tasks" / "t1")- (task / "installs").symlink_to(owner / "installs")-- assert owning_home_root(root) is None---def test_an_explicit_runtime_dir_still_wins(tmp_path, monkeypatch):- root = _checkout(tmp_path, monkeypatch)- _state(tmp_path / ".hermes", root)- _home(monkeypatch, tmp_path / "tmp" / "a")- monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "runtime"))-- assert store_root(root) == (tmp_path / "runtime").resolve()--def test_a_borrowing_launch_syncs_its_own_dependencies_and_nothing_of_the_checkout(tmp_path, monkeypatch, completion_tail):@@ -149,6 +92,9 @@ def test_a_borrowing_launch_syncs_its_own_dependencies_and_nothing_of_the_checkoroot = _checkout(tmp_path, monkeypatch)_state(tmp_path / ".hermes", root)_home(monkeypatch, tmp_path / "tmp" / "hermes-flash-compat-x" / "a")+ # The owner's store, so no tool store is downloaded into the temporary home.+ assert owning_home_root(root) == tmp_path / ".hermes"+ assert store_root(root) == tmp_path / ".hermes" / "tools"stamp = (root / "install-stamp.json").read_bytes()owner_marker = root / ".update-incomplete"owner_marker.write_text("owner's update\n", encoding="utf-8")@@ -179,23 +125,6 @@ def test_a_borrowing_launch_syncs_its_own_dependencies_and_nothing_of_the_checkoassert len(syncs) == 1 and completion_tail == []-def test_a_borrowing_launch_ignores_a_tail_armed_before_the_fix(tmp_path, monkeypatch, completion_tail):- import pm- from hermes_cli import _launchers-- root = _checkout(tmp_path, monkeypatch)- _state(tmp_path / ".hermes", root)- _home(monkeypatch, tmp_path / "tmp" / "a")- pending = venv_sync.completion_pending_path(root)- pending.parent.mkdir(parents=True)- pending.write_text("source update tail not finished\n", encoding="utf-8")- monkeypatch.setattr(pm, "venv_is_current", lambda **kw: True)- monkeypatch.setattr(_launchers, "resolve_store_python", lambda _: Path(sys.executable))-- assert venv_sync.prepare_launch(root, []) is None- assert completion_tail == []--def test_the_owner_still_owes_and_runs_its_tail(tmp_path, monkeypatch, completion_tail):"""Unchanged for the owner: a stale environment syncs, arms and runs the tail."""import pmdiff --git a/tests/hermes_cli/test_hermes_home_shared_launchers.py b/tests/hermes_cli/test_hermes_home_shared_launchers.pyindex a0f39056561..d0599d0d487 100644--- a/tests/hermes_cli/test_hermes_home_shared_launchers.py+++ b/tests/hermes_cli/test_hermes_home_shared_launchers.py@@ -10,7 +10,6 @@ import osfrom pathlib import Pathimport pm-import pytestfrom hermes_cli import _launchersfrom hermes_cli import venv_sync@@ -73,25 +72,6 @@ def _publish(repo: Path) -> dict[str, bytes]:return {Path(p).name: Path(p).read_bytes() for p in written}-def test_temp_home_ensure_leaves_shared_launchers_alone(tmp_path, monkeypatch):- default_home, _ = _make_home(tmp_path, "default")- temp_home, temp_python = _make_home(tmp_path, "temp")- repo = _make_repo(tmp_path)-- _isolate(tmp_path, monkeypatch, default_home)- before = _publish(repo)-- _isolate(tmp_path, monkeypatch, temp_home)- # The cross-home condition really holds: this root resolves temp's Python.- temp_resolved = _launchers.resolve_store_python(repo)- assert temp_resolved is not None- assert temp_resolved.resolve() == temp_python.resolve()- again = _launchers.ensure_install_launchers(repo, repo / ".hermes" / "bin")- assert len(again) == len(_launchers.ENTRY_POINTS)- for path in again:- assert Path(path).read_bytes() == before[Path(path).name]--def test_temp_home_prepare_launch_relaunches_without_rebinding(tmp_path, monkeypatch):default_home, _ = _make_home(tmp_path, "default")temp_home, temp_python = _make_home(tmp_path, "temp")@@ -136,74 +116,3 @@ def test_missing_dead_and_same_store_launchers_still_publish(tmp_path, monkeypatfor path in local.iterdir():path.unlink()assert _launchers.ensure_install_launchers(repo, local) == []---def test_launcher_python_reads_posix_shell_wrapper(tmp_path):- target = tmp_path / "hermes"- target.write_text(- '#!/bin/sh\nexec /tmp/fake-home/tools/python-A/bin/python3 -I -c "x" "$@"\n',- encoding="utf-8",- )- assert _launchers._launcher_python(target) == Path("/tmp/fake-home/tools/python-A/bin/python3")- assert _launchers._launcher_python(tmp_path / "missing") is None---def test_launcher_python_reads_windows_cmd_fallback(tmp_path):- target = tmp_path / "hermes.cmd"- target.write_text(- '@echo off\r\n"C:\\fake home\\tools\\py\\python.exe" -I -c "eA==" %*\r\n',- encoding="utf-8",- )- assert _launchers._launcher_python(target) == Path("C:\\fake home\\tools\\py\\python.exe")---def test_no_store_interpreter_never_keeps_launchers(tmp_path, monkeypatch):- """A store with no recorded interpreter stays a failure, not a keep."""- default_home, _ = _make_home(tmp_path, "default")- temp_home, _ = _make_home(tmp_path, "temp")- repo = _make_repo(tmp_path)- local = repo / ".hermes" / "bin"-- _isolate(tmp_path, monkeypatch, default_home)- _publish(repo)-- # Default's launchers are live and outside temp's store, so temp's launch- # would keep them. With no interpreter recorded for temp, keeping would- # report a half-finished store as a successful publication.- _isolate(tmp_path, monkeypatch, temp_home)- (temp_home / "tools" / "facts.json").write_text(- json.dumps({"schema": 1, "packages": {}}), encoding="utf-8")- assert _launchers.resolve_store_python(repo) is None- assert _launchers.ensure_install_launchers(repo, local) == []---def _write_dead_exe(target: Path, missing_python: Path) -> None:- """distlib-shaped launcher: loader stub, '#!<python> -I' shebang, zip."""- import io- import zipfile-- payload = io.BytesIO()- with zipfile.ZipFile(payload, "w") as archive:- archive.writestr("__main__.py", "raise SystemExit(0)\n")- target.write_bytes(b"MZ" + b"\x00" * 64 + b"#!" + str(missing_python).encode()- + b" -I" + payload.getvalue())--[email protected](os.name != "nt", reason="PATHEXT picks .exe before .cmd on Windows only")-def test_dead_exe_never_shadows_kept_cmd(tmp_path, monkeypatch):- default_home, default_python = _make_home(tmp_path, "default")- temp_home, _ = _make_home(tmp_path, "temp")- repo = _make_repo(tmp_path)- local = repo / ".hermes" / "bin"- local.mkdir(parents=True)- _write_dead_exe(local / "hermes.exe", tmp_path / "gone" / "python.exe")- (local / "hermes.cmd").write_text(- '@echo off\r\n"%s" -I -c "eA==" %%*\r\n' % default_python, encoding="utf-8")- assert _launchers._launcher_python(local / "hermes.exe") == tmp_path / "gone" / "python.exe"-- _isolate(tmp_path, monkeypatch, temp_home)- written = [Path(path) for path in _launchers.ensure_install_launchers(repo, local)]- # The shared .cmd is live and foreign, so it is kept — and the dead .exe- # that would have run instead of it is gone.- assert local / "hermes.cmd" in written- assert not (local / "hermes.exe").exists()