The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(update): killed recovery re-adopted, partner-claimed update merges an orphan, profile-form hosts
Teknium533359a11b3e
diff --git a/tests/e2e/core/upgrade/hosts/test_hostile_pause_record.py b/tests/e2e/core/upgrade/hosts/test_hostile_pause_record.pynew file mode 100644index 00000000000..a3e461cf677--- /dev/null+++ b/tests/e2e/core/upgrade/hosts/test_hostile_pause_record.py@@ -0,0 +1,77 @@+"""The paused-gateway record survives an update that runs under a partner's claim.++A real checkout (a clone of the commit under test) and real processes: a ``hermes update``+stand-in that recorded a paused set is SIGKILLed; the next update runs the way Desktop/Tauri+drives it — the orchestrator holds the marker and the ``hermes update`` child takes the checkout+lock and adopts the orchestrator's claim. That update must adopt the orphaned set and fold it into+its own record, never treat its own partner as "another update" and overwrite the record.+"""++from __future__ import annotations++import json+import signal+import subprocess+import sys+import textwrap+from pathlib import Path++import pytest++from tests.e2e.core.upgrade import _helpers as H+from tests.e2e.core.upgrade import _install_helpers as I++pytestmark = [pytest.mark.platforms("linux"), pytest.mark.live_system_guard_bypass]++_ORPHAN = """+import time+from hermes_cli import update_pause_record as r+r.write(r.stamp_tree({"resume_needed": True, "profiles": {"orphan": 4242}}), owner=r.identity())+print("written", flush=True)+time.sleep(120)+"""+# The orchestrator (Tauri ``hermes-setup --update``) claims the marker, then runs the update child.+_ORCHESTRATOR = """+import subprocess, sys+from hermes_cli.update_lock import UpdateLock+lock = UpdateLock()+assert lock.acquire() and lock.acquired+sys.exit(subprocess.call([sys.executable, "-c", sys.argv[1], sys.argv[2]]))+"""+_UPDATE_CHILD = """+import json, sys+from hermes_cli import update_pause_record as r+from hermes_cli.update_lock import UpdateLock+lock = UpdateLock(install_root=sys.argv[1])+adopted_claim = lock.acquire() and not lock.acquired+saw_orphan = r.orphaned_record() is not None+r.write(r.stamp_tree({"resume_needed": True, "profiles": {"mine": 1}}), owner=r.identity())+print(json.dumps({"adopted_claim": adopted_claim, "saw_orphan": saw_orphan,+ "recorded": sorted(r.read()["token"]["profiles"])}))+lock.release()+"""+++def _py(code: str, *args: str, env: dict, cwd: Path) -> subprocess.Popen:+ return subprocess.Popen([sys.executable, "-c", textwrap.dedent(code), *args], env=env, cwd=cwd,+ stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)+++def test_update_under_a_partner_claim_merges_an_orphaned_pause(tmp_path):+ origin = I.make_origin(tmp_path, I.head_sha())+ checkout = tmp_path / "checkout"+ I.git("clone", "-q", "--shared", "-b", "main", str(origin), str(checkout), cwd=tmp_path)+ env = H.isolated_env(tmp_path / "env", pythonpath=checkout)++ owner = _py(_ORPHAN, env=env, cwd=checkout)+ assert owner.stdout.readline().strip() == "written", owner.stderr.read()+ owner.send_signal(signal.SIGKILL) # windows-footgun: ok — linux-only cell+ owner.wait(timeout=10)++ run = _py(_ORCHESTRATOR, textwrap.dedent(_UPDATE_CHILD), str(checkout), env=env, cwd=checkout)+ out, err = run.communicate(timeout=120)+ assert run.returncode == 0, f"{out}\n{err}"+ result = json.loads(out.strip().splitlines()[-1])+ assert result["adopted_claim"], f"premise: the update child did not run under the orchestrator's claim: {result}"+ assert result["saw_orphan"], "the update treated its own orchestrator as another update and skipped the orphan"+ assert result["recorded"] == ["mine", "orphan"], f"the orphaned paused set was overwritten: {result}"diff --git a/tests/hermes_cli/test_update_pause_record.py b/tests/hermes_cli/test_update_pause_record.pyindex a60d2df7163..1b284c083cd 100644--- a/tests/hermes_cli/test_update_pause_record.py+++ b/tests/hermes_cli/test_update_pause_record.py@@ -74,8 +74,60 @@ def test_resume_waits_for_a_whole_tree(tmp_path):marker.unlink()_git(root, "commit", "-qam", "v2") # HEAD moved: only a dependency sync for it makes it whole+ (root / "b.py").write_text("rewritten by a build step\n", encoding="utf-8")whole, why = pause_record.tree_is_whole(token, root)- assert not whole and "dependencies" in why+ # A committed update is judged on its dependencies alone; a tracked file the build rewrote+ # must not keep the gateways stopped on every later launch.+ assert not whole and "dependencies" in why, why+++def _orphan(tmp_path: Path, profiles: dict) -> None:+ """A record whose owner — a real ``hermes update`` stand-in — was SIGKILLed after writing it."""+ owner = _child("""+ import time+ from hermes_cli import update_pause_record as r+ r.write(r.stamp_tree({"resume_needed": True, "profiles": %r}), owner=r.identity())+ print("written", flush=True)+ time.sleep(120)+ """ % profiles, env={"HERMES_HOME": str(tmp_path)})+ assert owner.stdout.readline().strip() == "written"+ owner.send_signal(signal.SIGKILL) # windows-footgun: ok — module skips on Windows+ owner.wait(timeout=10)+++# The Windows resume cannot run here: the stand-in for it prints the set it was handed and+# (mode "hang") parks like a resume waiting on relaunch verification.+_RECOVER = """+ import sys, time+ import hermes_cli.update_cmd_windows as w+ def resume(token):+ print("resume", sorted(token.get("profiles") or {}), flush=True)+ if sys.argv[1] == "hang":+ time.sleep(120)+ token["resume_needed"] = False+ w._resume_windows_gateways_after_update = resume+ from hermes_cli import update_pause_record as r+ r.recover(["status"])+ print("done", flush=True)+"""++[email protected]_system_guard_bypass+def test_a_launch_killed_mid_recovery_leaves_the_set_to_the_next_launch(tmp_path):+ _orphan(tmp_path, {"default": 4242})+ env = {"HERMES_HOME": str(tmp_path)}+ first = _child(_RECOVER, "hang", env=env)+ try:+ assert first.stdout.readline().strip() == "resume ['default']"+ finally:+ first.send_signal(signal.SIGKILL) # windows-footgun: ok — taskkill / console close mid-resume+ first.wait(timeout=10)+ second = _child(_RECOVER, "ok", env=env)+ out, _ = second.communicate(timeout=60)+ assert out.splitlines()[:1] == ["resume ['default']"], out+ third = _child(_RECOVER, "ok", env=env)+ out, _ = third.communicate(timeout=60)+ assert out.strip() == "done", f"a resumed set was resumed again: {out}"_HOLDER = """@@ -83,7 +135,7 @@ _HOLDER = """from hermes_cli.update_lock import UpdateLocklock = UpdateLock()assert lock.acquire() and lock.acquired- host = subprocess.Popen([sys.executable, sys.argv[1], "hermes_cli.main", *sys.argv[2:]], stdout=subprocess.PIPE, text=True)+ host = subprocess.Popen([sys.executable, *sys.argv[1:]], stdout=subprocess.PIPE, text=True)print(host.stdout.read().strip(), flush=True)host.wait()"""@@ -98,7 +150,13 @@ print(subprocess.run([sys.executable, "-c", probe], capture_output=True, text=Tr# The intermediate is a stand-in script, not a real gateway/update: nothing touches the checkout.@pytest.mark.live_system_guard_bypass[email protected]("host_argv, adopts", [(("gateway", "run"), False), (("status",), True)])[email protected]("host_argv, adopts", [+ (("hermes_cli.main", "gateway", "run"), False),+ (("hermes_cli.main", "--profile", "work", "gateway", "run"), False),+ (("/opt/hermes/hermes_cli/main.py", "-p", "work", "gateway", "run"), False),+ (("-m", "hermes_cli.main", "--profile", "work", "dashboard"), False),+ (("hermes_cli.main", "status"), True),+])def test_update_started_from_a_relaunched_gateway_does_not_share_the_claim(tmp_path, host_argv, adopts):script = tmp_path / "host.py"script.write_text(_HOST, encoding="utf-8")