Skip to content

The agent that grows with you

test+docs: installer reruns and rollbacks on a chosen update channel (#137714)

Teknium65c40e5e9efe
diff --git a/tests/hermes_cli/test_source_check.py b/tests/hermes_cli/test_source_check.py
index 6a757b33f39..7d20412da7f 100644
--- a/tests/hermes_cli/test_source_check.py
+++ b/tests/hermes_cli/test_source_check.py
@@ -545,3 +545,26 @@ def test_branch_tip_failure_names_the_cause(installation):
status = check_for_updates(install_root=root, home=home, force=True)
assert status["error"] == "fetch-failed"
assert "HTTP 503" in status["message"]
+
+
[email protected]("on,release,rollback", [("head", "base", True), ("base", "head", False)])
+def test_stable_release_the_checkout_already_contains_is_a_rollback(installation, tmp_path, on, release, rollback):
+ """A release HEAD contains is a move back (#137714); an older checkout is a real update."""
+ from hermes_cli.source_check import check_for_updates
+
+ root, _linked, home, base, head, responses, _requests, git = installation
+ shas = {"base": base, "head": head}
+ bare = tmp_path / "origin.git"
+ git("clone", "-q", "--bare", str(root), str(bare), cwd=tmp_path)
+ git("tag", "v1.2.3", shas[release], cwd=bare)
+ git("remote", "set-url", "origin", str(bare))
+ git("checkout", "-q", "--detach", shas[on])
+ api = "/repos/NousResearch/hermes-agent"
+ responses[f"{api}/releases/latest"] = (200, {"draft": False, "prerelease": False, "tag_name": "v1.2.3"})
+ responses[f"{api}/commits/v1.2.3"] = (200, {"sha": shas[release]})
+
+ status = check_for_updates(install_root=root, home=home, channel="stable", force=True)
+
+ assert status.get("targetSha") == shas[release], status
+ assert status["updateAvailable"] is True
+ assert status["rollback"] is rollback
diff --git a/tests/scripts/test_install_ps1_chosen_channel.py b/tests/scripts/test_install_ps1_chosen_channel.py
new file mode 100644
index 00000000000..9c03b1f7022
--- /dev/null
+++ b/tests/scripts/test_install_ps1_chosen_channel.py
@@ -0,0 +1,41 @@
+"""install.ps1 reads the update channel a checkout chose, as Hermes wrote it (#137714).
+
+The Windows twin of test_install_sh_chosen_channel: the record comes from Hermes's
+own writer, and the installer's pre-Python reader must find it by this install's id.
+"""
+from pathlib import Path
+import shutil
+import subprocess
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[2]
+
+pytestmark = pytest.mark.platforms("windows")
+
+
[email protected]("channel", ["stable", "main"])
+def test_installer_reads_the_channel_hermes_recorded(tmp_path, monkeypatch, channel):
+ from hermes_cli.update_channel import set_install_channel
+
+ powershell = shutil.which("powershell")
+ if not powershell:
+ pytest.skip("Windows PowerShell is required")
+ home = tmp_path / "home"
+ install = home / "hermes-agent"
+ install.mkdir(parents=True)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ set_install_channel(channel, install)
+ script = (f". '{ROOT / 'scripts' / 'install.ps1'}' -InstallDir '{install}' -HermesHome '{home}'\n"
+ "Write-Output \"channel=$(Get-ChosenChannel)\"\n")
+ wrapper = tmp_path / "read.ps1"
+ wrapper.write_text(script, encoding="utf-8")
+
+ result = subprocess.run(
+ [powershell, "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(wrapper)],
+ check=False, capture_output=True, text=True, encoding="utf-8", errors="replace",
+ stdin=subprocess.DEVNULL, timeout=120,
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert f"channel={channel}" in result.stdout.splitlines(), result.stdout + result.stderr
diff --git a/tests/scripts/test_install_sh_chosen_channel.py b/tests/scripts/test_install_sh_chosen_channel.py
new file mode 100644
index 00000000000..570ade2c9cc
--- /dev/null
+++ b/tests/scripts/test_install_sh_chosen_channel.py
@@ -0,0 +1,51 @@
+"""An installer rerun keeps a checkout on the update channel it chose (#137714).
+
+Hermes-Setup reruns install.sh with its baked ``--branch main``. A checkout whose
+config.yaml record (written by Hermes itself) names ``stable`` must stay where
+``hermes update`` put it; a ``main`` record still follows the branch.
+"""
+from pathlib import Path
+import os
+import subprocess
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[2]
+
+pytestmark = pytest.mark.platforms("posix")
+
+
+def _git(cwd, *args):
+ return subprocess.run(
+ ["git", "-c", "user.name=Fixture", "-c", "[email protected]",
+ "-c", "commit.gpgsign=false", *args],
+ cwd=cwd, check=True, capture_output=True, text=True, stdin=subprocess.DEVNULL,
+ ).stdout.strip()
+
+
[email protected]("channel,moves", [("stable", False), ("main", True)])
+def test_rerun_keeps_a_chosen_channel_checkout(tmp_path, monkeypatch, channel, moves):
+ from hermes_cli.update_channel import set_install_channel
+
+ origin, home = tmp_path / "origin", tmp_path / "home"
+ install = home / "hermes-agent"
+ origin.mkdir()
+ home.mkdir()
+ _git(origin, "init", "-b", "main")
+ for label in ("release", "newer"):
+ _git(origin, "commit", "--allow-empty", "-m", label)
+ release, tip = _git(origin, "rev-parse", "HEAD~1"), _git(origin, "rev-parse", "HEAD")
+ _git(tmp_path, "clone", "-q", str(origin), str(install))
+ _git(install, "checkout", "-q", "--detach", release)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ set_install_channel(channel, install)
+
+ result = subprocess.run(
+ ["bash", str(ROOT / "scripts" / "install.sh"), "--stage", "repository",
+ "--branch", "main", "--dir", str(install), "--hermes-home", str(home), "--non-interactive"],
+ check=False, capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=120,
+ env={"PATH": os.environ["PATH"], "HOME": str(tmp_path), "NO_COLOR": "1"},
+ )
+
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert _git(install, "rev-parse", "HEAD") == (tip if moves else release), result.stdout
diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.md
index 6d49349b1a9..3786223a91b 100644
--- a/website/docs/getting-started/updating.md
+++ b/website/docs/getting-started/updating.md
@@ -47,7 +47,12 @@ The choice is stored per install under `update.installs` in `config.yaml`. An
install that never chose a channel only moves forward: a checkout already newer
than the latest release (for example one that tracked `main` before this default)
stays where it is until a newer release ships. Running `--set-channel stable`
-pins the checkout to the exact release commit, even when that is older.
+pins the checkout to the exact release commit, even when that is older; the
+Desktop names that move as a rollback to the release, and `hermes update --check`
+says the checkout is newer, instead of announcing a new update. Re-running the
+installer (`install.sh`, `install.ps1` or Hermes-Setup) over an install that chose
+a channel other than `main` keeps its checkout where it is: only `hermes update`
+moves it. An explicit `--commit` pin still applies.
Windows Store, MSIX and bundled desktop installs are unaffected; their channel
is baked into the package (see below).