Skip to content

The agent that grows with you

fix: exercise historical source upgrades with PM-selected runtime

ethernet1eefbd10e211
diff --git a/tests/e2e/core/upgrade/_helpers.py b/tests/e2e/core/upgrade/_helpers.py
index 2b15dd6b22e..3534c2b26af 100644
--- a/tests/e2e/core/upgrade/_helpers.py
+++ b/tests/e2e/core/upgrade/_helpers.py
@@ -31,7 +31,7 @@ WORKTREE = Path(__file__).resolve().parents[4]
REAL_HOME = Path(pwd.getpwuid(os.getuid()).pw_dir)
UID = os.getuid()
-_ENV_ALLOW = ("LANG", "LC_ALL", "TZ", "TERM", "SHELL", "USER", "LOGNAME", "TMPDIR")
+_ENV_ALLOW = ("LANG", "LC_ALL", "TZ", "TERM", "SHELL", "USER", "LOGNAME", "TMPDIR", "SSL_CERT_FILE")
_SHIMMED = ("systemctl", "launchctl", "sudo", "loginctl", "journalctl")
diff --git a/tests/e2e/core/upgrade/test_upgrade_path.py b/tests/e2e/core/upgrade/test_upgrade_path.py
index 7bc519d08c1..f8b0808c812 100644
--- a/tests/e2e/core/upgrade/test_upgrade_path.py
+++ b/tests/e2e/core/upgrade/test_upgrade_path.py
@@ -12,7 +12,9 @@ Class C6 (bricked installs, stale code, lost state after `hermes update`). Each
job, and a hand-edited config.yaml at the N-1 schema version with comments, long quoted
unicode values and a legacy MCP ``disabled: true`` entry (the one documented N-1 -> HEAD
migration);
-4. moves ``origin/main`` to HEAD and runs the real ``hermes update --yes`` non-interactively.
+4. moves ``origin/main`` to HEAD and runs the real ``hermes update --yes --branch main``
+ non-interactively. A branch-explicit update follows the historical git-source path,
+ without depending on the separately published R2 channel record.
Legs: ``clean``; ``autostash`` (local edits + an orphan update autostash from an earlier run);
``kill_mid_pull`` (SIGKILL while the fast-forward holds ``index.lock``, then the user retries
@@ -139,9 +141,14 @@ for name in tops + ["hermes_cli.main", "run_agent", "hermes_state"] + added:
except BaseException as exc:
bad.append(f"{name}: {type(exc).__name__}: {exc}")
continue
- where = getattr(mod, "__file__", None) or str(list(getattr(mod, "__path__", [""]))[0])
- if not str(Path(where).resolve()).startswith(str(root.resolve())):
- bad.append(f"{name}: resolved outside the checkout: {where}")
+ where = Path(getattr(mod, "__file__", None) or str(list(getattr(mod, "__path__", [""]))[0])).resolve()
+ if where.is_relative_to(root.resolve()):
+ continue # N-1's editable venv serves the source tree directly.
+ workspace = Path(sys.prefix).resolve().parent / "workspace"
+ if not where.is_relative_to(workspace) or not (root / where.relative_to(workspace)).is_file():
+ bad.append(f"{name}: resolved outside the checkout and PM workspace: {where}")
+ elif where.read_bytes() != (root / where.relative_to(workspace)).read_bytes():
+ bad.append(f"{name}: PM workspace differs from the updated checkout: {where}")
if bad:
sys.exit("\n".join(bad))
"""
@@ -252,10 +259,17 @@ class Leg:
@property
def hermes(self) -> str:
- return str(self.install / "venv" / "bin" / "hermes")
+ published = self.install / ".hermes" / "bin" / "hermes"
+ return str(published if published.exists() else self.install / "venv" / "bin" / "hermes")
@property
def python(self) -> str:
+ from pm.environments import install_key
+
+ facts = self.hermes_home / "installs" / install_key(self.install) / "facts.json"
+ if facts.exists():
+ selected = json.loads(facts.read_text(encoding="utf-8"))["packages"]["venv"]["environment"]
+ return str(Path(selected) / "bin" / "python")
return str(self.install / "venv" / "bin" / "python")
def run(self, *args: str, timeout: float = CLI_TIMEOUT, argv0: str | None = None,
@@ -279,7 +293,7 @@ class Leg:
# the killed run's updater is pid 3 (a non-exec shell is pid 2) and every retry's updater is
# pid 2 with pid 3 a process that already exited.
_KILLED_RUN_PREFIX = ["/bin/sh", "-c", '"$0" "$@"; exit $?']
-_RETRY_PREFIX = ["/bin/sh", "-c", '/bin/true; exec "$0" "$@"']
+_RETRY_PREFIX = ["/bin/sh", "-c", 'true; exec "$0" "$@"']
def _make_origin(root: Path) -> Path:
@@ -292,7 +306,7 @@ def _make_origin(root: Path) -> Path:
def _write_wrappers(leg_root: Path, install: Path, hermes_home: Path) -> Path:
- """Managed uv (as the installer provisions it) and a PATH git wrapper; both armable to freeze."""
+ """Managed uv (as the installer provisions it) and an armable PATH git wrapper."""
real_uv = _real_uv()
real_git = shutil.which("git")
bin_dir = hermes_home / "bin"
@@ -302,9 +316,6 @@ def _write_wrappers(leg_root: Path, install: Path, hermes_home: Path) -> Path:
"#!/bin/sh\n"
# `uv self update` would reach the network and the real binary; the pinned copy is current.
'if [ "$1" = self ]; then exit 0; fi\n'
- f'if [ "$1" = pip ] && [ "$2" = install ] && [ -f "{leg_root}/arm-deps" ]; then\n'
- f' rm -f "{leg_root}/arm-deps"; : > "{leg_root}/frozen-deps"; exec sleep 3600\n'
- "fi\n"
f'exec "{real_uv}" "$@"\n',
encoding="utf-8",
)
@@ -314,6 +325,9 @@ def _write_wrappers(leg_root: Path, install: Path, hermes_home: Path) -> Path:
git = wrap / "git"
git.write_text(
"#!/bin/sh\n"
+ # `git remote get-url` expands insteadOf before the updater classifies a
+ # fork. Report the configured official URL; only transport is redirected.
+ f'if [ "$1" = remote ] && [ "$2" = get-url ] && [ "$3" = origin ]; then printf "%s\\n" "{OFFICIAL_URL}"; exit 0; fi\n'
f'if [ -f "{leg_root}/arm-pull" ] && echo " $* " | grep -q " merge --ff-only "; then\n'
f' rm -f "{leg_root}/arm-pull"\n'
# Model a SIGKILL half-way through the fast-forward: git writes the tree in index order,
@@ -322,6 +336,12 @@ def _write_wrappers(leg_root: Path, install: Path, hermes_home: Path) -> Path:
f' xargs -r -a "{leg_root}/torn-paths" "{real_git}" -C "{install}" checkout origin/main -- >/dev/null 2>&1\n'
f' : > "{install}/.git/index.lock"; : > "{leg_root}/frozen-pull"; exec sleep 3600\n'
"fi\n"
+ # N-1 ran `uv pip install`, but HEAD's PM sync uses its pinned uv directly.
+ # The first post-swap HEAD probe is a stable seam before PM starts syncing.
+ f'if [ -f "{leg_root}/arm-deps" ] && [ "$1" = rev-parse ] && [ "$2" = HEAD ] '
+ f'&& [ "$("{real_git}" -C "{install}" rev-parse HEAD)" = "{_refs().head}" ]; then\n'
+ f' rm -f "{leg_root}/arm-deps"; : > "{leg_root}/frozen-deps"; exec sleep 3600\n'
+ "fi\n"
f'exec "{real_git}" "$@"\n',
encoding="utf-8",
)
@@ -442,15 +462,15 @@ def assert_healthy_at_head(leg: Leg, provider: FakeLLMServer, final: subprocess.
assert final.returncode == 0, "final `hermes update` failed:\n" + H.describe(final)
assert _git("rev-parse", "HEAD", cwd=leg.install) == _refs().head, "update exited 0 but HEAD is not the target"
assert not (leg.install / ".git" / "index.lock").exists(), "update left .git/index.lock behind"
- # The editable install must serve the pulled tree (stale editable finder, #119466): every
- # top-level package HEAD ships plus a module that only exists at HEAD import from the venv's
- # own interpreter in a fresh process whose cwd is OUTSIDE the checkout (no implicit sys.path).
+ # The active interpreter must serve the pulled tree (stale editable finder, #119466):
+ # every top-level package and a HEAD-only module import from PM's selected interpreter.
+ # PM snapshots the checkout into its workspace; compare imported source bytes.
cp = leg.run("-c", IMPORT_PROBE, str(leg.install), _refs().base, argv0=leg.python, cwd=leg.root)
assert cp.returncode == 0, "the updated venv does not serve HEAD's tree:\n" + H.describe(cp)
# The venv satisfies HEAD's declared dependency set (not just "the old release still imports"):
# every core requirement in the pulled pyproject is installed at a satisfying version, and the
# installed hermes-agent distribution was built from the pulled pyproject.
- cp = leg.run("-c", DEPS_PROBE, str(leg.install / "pyproject.toml"), argv0=leg.python)
+ cp = leg.run("-c", DEPS_PROBE, str(leg.install / "pyproject.toml"), argv0=leg.python, cwd=leg.root)
assert cp.returncode == 0, "venv does not satisfy HEAD's dependencies:\n" + H.describe(cp)
# 2. state integrity: nothing lost, nothing corrupted (measured BEFORE any new turn)
for name, home in _profile_homes(leg).items():
@@ -563,11 +583,12 @@ def _publish_head(leg: Leg) -> None:
def _update(leg: Leg) -> subprocess.CompletedProcess:
- return leg.run(*_RETRY_PREFIX[1:], leg.hermes, "update", "--yes", argv0=_RETRY_PREFIX[0], timeout=UPDATE_TIMEOUT)
+ return leg.run(*_RETRY_PREFIX[1:], leg.hermes, "update", "--yes", "--branch", "main",
+ argv0=_RETRY_PREFIX[0], timeout=UPDATE_TIMEOUT)
def _freeze_update_at(leg: Leg, marker: str) -> None:
- proc = leg.popen("update", "--yes")
+ proc = leg.popen("update", "--yes", "--branch", "main")
try:
H.wait_for(lambda: (leg.root / marker).exists() or proc.poll() is not None,
timeout=UPDATE_TIMEOUT, interval=0.5, what=marker)