The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(update): a launch refuses the tail while another process holds the checkout lock
Tekniumf13ca9fb1f48
diff --git a/tests/e2e/core/upgrade/git/test_hostile_lock.py b/tests/e2e/core/upgrade/git/test_hostile_lock.pyindex 38f17e87308..f19387fb29f 100644--- a/tests/e2e/core/upgrade/git/test_hostile_lock.py+++ b/tests/e2e/core/upgrade/git/test_hostile_lock.py@@ -44,19 +44,12 @@ from pathlib import Pathroot, checkout, mode = Path(sys.argv[1]), sys.argv[2], sys.argv[3]envs = json.loads((root / "envs.json").read_text(encoding="utf-8"))ARGV = [sys.executable, "-m", "hermes_cli.main", "update", "--yes", "--branch", "main", "--no-gateway-restart"]-# The readers a launch / a running server consult, in a fresh process of another home.+# A running server's "is an update in flight" probe, in a fresh process of another home.READER = """import json, sys-from pathlib import Pathsys.path.insert(0, sys.argv[1])from hermes_cli.web_server_skew_exit import _update_in_progress-from hermes_cli.venv_sync import prepare_launch-out = {"skew_reader": _update_in_progress()}-try:- out["launch"] = repr(prepare_launch(Path(sys.argv[1]), ["status"]))-except RuntimeError as exc:- out["launch"] = "refused: " + str(exc)-print(json.dumps(out))+print(json.dumps({"skew_reader": _update_in_progress()}))"""@@ -265,5 +258,3 @@ def test_orphaned_update_tree_reads_as_in_progress(rig):assert r["child_seen"] and r["child_alive_after"], f"premise: no completion child outlived the owner: {r}"assert r["reader"] is not None, f"reader process failed:\n{r['reader_out']}"assert r["reader"]["skew_reader"] is True, f"the server's update probe missed the live update tree: {r}"- assert r["reader"]["launch"].startswith("refused: an update is still running"), (- f"a launch ran the completion tail beside the live update tree: {r}")diff --git a/tests/hermes_cli/test_venv_sync_update_tree.py b/tests/hermes_cli/test_venv_sync_update_tree.pynew file mode 100644index 00000000000..e7bd191f427--- /dev/null+++ b/tests/hermes_cli/test_venv_sync_update_tree.py@@ -0,0 +1,56 @@+"""A launch never runs the completion tail beside a live update tree whose marker is gone.++A killed ``hermes update`` leaves its completion child holding the checkout lock; its marker is+dead (and any reader deletes it). ``prepare_launch`` must read the checkout lock, not just the+marker, or it claims the free marker and runs a second tail beside the live one.+"""++from __future__ import annotations++import subprocess+import sys+from pathlib import Path++import pytest++from hermes_cli import venv_sync++REPO = Path(__file__).resolve().parents[2]++_HOLDER = """+import sys, time+from pathlib import Path+sys.path.insert(0, sys.argv[1])+from hermes_cli.update_lock import UpdateLock+assert UpdateLock(path=Path(sys.argv[3]), install_root=sys.argv[2]).acquire()+print("held", flush=True)+time.sleep(120)+"""+++def test_launch_refuses_while_another_process_holds_the_checkout(tmp_path, monkeypatch):+ import pm++ root = tmp_path / "checkout"+ (root / ".git").mkdir(parents=True)+ (root / "pyproject.toml").write_text("[project]\nname='example'\n", encoding="utf-8")+ (root / "install-stamp.json").write_text('{"updateMechanism": "self"}', encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))+ monkeypatch.delenv("HERMES_DISABLE_LAZY_INSTALLS", raising=False)+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: False) # an interrupted update's tree+ finished = []+ monkeypatch.setattr(venv_sync, "_finish_source_update", lambda *a, **k: finished.append(a))++ # The orphaned completion child: a real process holding the checkout lock; its marker+ # lives elsewhere, so this home's marker is free.+ holder = subprocess.Popen([sys.executable, "-c", _HOLDER, str(REPO), str(root), str(tmp_path / "gone")],+ stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, text=True, encoding="utf-8")+ try:+ assert holder.stdout is not None and holder.stdout.readline().strip() == "held"+ with pytest.raises(RuntimeError, match="an update is still running"):+ venv_sync.prepare_launch(root, [])+ assert finished == [], "a second completion tail ran beside the live update tree"+ assert not (tmp_path / "home" / ".hermes-update-in-progress").exists(), "a refused launch left a claim"+ finally:+ holder.kill()+ holder.wait()