The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): a rerun moves a checkout only forward onto the release
Teknium6d631407823f
diff --git a/scripts/install.ps1 b/scripts/install.ps1index 0516bfe72a3..951b062e3c9 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -1058,17 +1058,19 @@ function Stage-Repository {return}if ($release) {- # Without a choice the default only moves forward, as `hermes update`'s does: a- # checkout that already contains the release (one that followed main) stays. A- # shallow checkout cannot prove it does not, so it stays for `hermes update` too.- if ($Channel -cne 'stable') {- Invoke-Native { git -C $InstallDir merge-base --is-ancestor $release HEAD 2>$null } | Out-Null- $contains = -not $LASTEXITCODE- $shallow = "$(Invoke-Native { git -C $InstallDir rev-parse --is-shallow-repository 2>$null })".Trim() -eq 'true'- if ($contains -or $shallow) {- Log "Keeping its checkout: it already has $release (``hermes update`` moves it to the next release)"- return- }+ # A rerun only moves a checkout forward onto the release. Any other move (a main+ # checkout diverged from a release cut on release/*, one already past it, a shallow+ # one that cannot tell) is `hermes update`'s: it refuses a release that predates the+ # session stores this checkout wrote (update_downgrade_guard).+ Invoke-Native { git -C $InstallDir merge-base --is-ancestor $release HEAD 2>$null } | Out-Null+ if (-not $LASTEXITCODE) {+ Log "Keeping its checkout: it already has $release (``hermes update`` moves it to the next release)"+ return+ }+ Invoke-Native { git -C $InstallDir merge-base --is-ancestor HEAD $release 2>$null } | Out-Null+ if ($LASTEXITCODE) {+ Log "Keeping its checkout: $release does not descend from it (``hermes update`` decides that move)"+ return}} else {Invoke-Logged "Fetching origin/$Branch" { git -C $InstallDir fetch origin "+refs/heads/${Branch}:refs/remotes/origin/${Branch}" }diff --git a/scripts/install.sh b/scripts/install.shindex c0c5001400f..f9dbf620fc4 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -737,14 +737,18 @@ stage_repository() {return 0fiif [ -n "$release" ]; then- # Without a choice the default only moves forward, as `hermes update`'s does: a- # checkout that already contains the release (one that followed main) stays. A- # shallow checkout cannot prove it does not, so it stays for `hermes update` too.- if [ "$CHANNEL" != stable ] && { git -C "$INSTALL_DIR" merge-base --is-ancestor "$release" HEAD 2>/dev/null \- || [ "$(git -C "$INSTALL_DIR" rev-parse --is-shallow-repository 2>/dev/null)" = true ]; }; then+ # A rerun only moves a checkout forward onto the release. Any other move (a main+ # checkout diverged from a release cut on release/*, one already past it, a shallow+ # one that cannot tell) is `hermes update`'s: it refuses a release that predates the+ # session stores this checkout wrote (update_downgrade_guard).+ if git -C "$INSTALL_DIR" merge-base --is-ancestor "$release" HEAD 2>/dev/null; thenlog "Keeping its checkout: it already has $release (\`hermes update\` moves it to the next release)"return 0fi+ if ! git -C "$INSTALL_DIR" merge-base --is-ancestor HEAD "$release" 2>/dev/null; then+ log "Keeping its checkout: $release does not descend from it (\`hermes update\` decides that move)"+ return 0+ fielserun_logged "Fetching origin/$BRANCH" git -C "$INSTALL_DIR" fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" \|| fail "git fetch failed$(native_detail)" git_fetch_faileddiff --git a/tests/scripts/test_install_ps1_stable_default.py b/tests/scripts/test_install_ps1_stable_default.pyindex 9cdf0eaccbe..2898830a177 100644--- a/tests/scripts/test_install_ps1_stable_default.py+++ b/tests/scripts/test_install_ps1_stable_default.py@@ -25,15 +25,20 @@ def _git(cwd, *args, env=None):).stdout.strip()[email protected]("start,channel,tagged,lands", [- (None, "", True, "release"), # fresh install: the release, not main's tip- (None, "main", True, "tip"), # explicit opt-out: main's tip- ("before", "", True, "release"), # rerun behind the release: moves forward to it- ("tip", "", True, "tip"), # rerun already containing it: never moves back- (None, "", False, None), # release tag unreachable: fail, publish nothing- ("before", "", False, "before"), # ... a rerun keeps its checkout instead[email protected]("side,start,channel,tagged,lands", [+ (False, None, "", True, "release"), # fresh install: the release, not main's tip+ (False, None, "main", True, "tip"), # explicit opt-out: main's tip+ (False, "before", "", True, "release"), # rerun behind the release: moves forward to it+ (False, "tip", "", True, "tip"), # rerun already containing it: never moves back+ (False, None, "", False, None), # release tag unreachable: fail, publish nothing+ (False, "before", "", False, "before"), # ... a rerun keeps its checkout instead+ # The release cut on a release branch, main past the fork point (v0.22.2's shape): main moves+ # back only through `hermes update`, whose downgrade guard the installer cannot run.+ (True, "tip", "", True, "tip"),+ (True, "tip", "stable", True, "tip"),+ (True, "before", "", True, "release"),])-def test_install_ps1_lands_on_the_latest_stable_release(tmp_path, start, channel, tagged, lands):+def test_install_ps1_lands_on_the_latest_stable_release(tmp_path, side, start, channel, tagged, lands):powershell = shutil.which("powershell")if not powershell:pytest.skip("Windows PowerShell is required")@@ -42,12 +47,16 @@ def test_install_ps1_lands_on_the_latest_stable_release(tmp_path, start, channelorigin.mkdir()home.mkdir()_git(origin, "init", "-q", "-b", "main")- for label in ("before", "release", "newer"):- _git(origin, "commit", "-q", "--allow-empty", "-m", label)+ _git(origin, "commit", "-q", "--allow-empty", "-m", "before")+ if side:+ _git(origin, "checkout", "-q", "-b", "release/1.2")+ _git(origin, "commit", "-q", "--allow-empty", "-m", "release")+ commits = {"before": _git(origin, "rev-parse", "HEAD~1"), "release": _git(origin, "rev-parse", "HEAD")}if tagged:- _git(origin, "tag", "-a", "v1.2.3", "-m", "release", "HEAD~1")- commits = {name: _git(origin, "rev-parse", ref)- for name, ref in (("before", "HEAD~2"), ("release", "HEAD~1"), ("tip", "HEAD"))}+ _git(origin, "tag", "-a", "v1.2.3", "-m", "release")+ _git(origin, "checkout", "-q", "main")+ _git(origin, "commit", "-q", "--allow-empty", "-m", "newer")+ commits["tip"] = _git(origin, "rev-parse", "HEAD")gitconfig = tmp_path / "gitconfig"gitconfig.write_text(f'[url "{origin.as_uri()}"]\n insteadOf = {OFFICIAL}\n', encoding="utf-8")env = {**os.environ, "GIT_CONFIG_GLOBAL": str(gitconfig), "NO_COLOR": "1"}diff --git a/tests/scripts/test_install_sh_stable_default.py b/tests/scripts/test_install_sh_stable_default.pyindex 060330e6d15..fe4cc160f02 100644--- a/tests/scripts/test_install_sh_stable_default.py+++ b/tests/scripts/test_install_sh_stable_default.py@@ -24,26 +24,35 @@ def _git(cwd, *args, env=None):).stdout.strip()[email protected]("start,args,tagged,lands", [- (None, [], True, "release"), # fresh install: the release, not main's tip- (None, ["--channel", "main"], True, "tip"), # explicit opt-out: main's tip- ("before", [], True, "release"), # rerun behind the release: moves forward to it- ("tip", [], True, "tip"), # rerun already containing it: never moves back- (None, [], False, None), # release tag unreachable: fail, publish nothing- ("before", [], False, "before"), # ... a rerun keeps its checkout instead[email protected]("side,start,args,tagged,lands", [+ (False, None, [], True, "release"), # fresh install: the release, not main's tip+ (False, None, ["--channel", "main"], True, "tip"), # explicit opt-out: main's tip+ (False, "before", [], True, "release"), # rerun behind the release: moves forward to it+ (False, "tip", [], True, "tip"), # rerun already containing it: never moves back+ (False, None, [], False, None), # release tag unreachable: fail, publish nothing+ (False, "before", [], False, "before"), # ... a rerun keeps its checkout instead+ # The release cut on a release branch, main past the fork point (v0.22.2's shape): main moves+ # back only through `hermes update`, whose downgrade guard the installer cannot run.+ (True, "tip", [], True, "tip"),+ (True, "tip", ["--channel", "stable"], True, "tip"),+ (True, "before", [], True, "release"),])-def test_install_lands_on_the_latest_stable_release(tmp_path, start, args, tagged, lands):+def test_install_lands_on_the_latest_stable_release(tmp_path, side, start, args, tagged, lands):origin, home, bin_dir = tmp_path / "origin", tmp_path / "home", tmp_path / "bin"install = home / ".hermes" / "hermes-agent"for d in (origin, home, bin_dir):d.mkdir()_git(origin, "init", "-q", "-b", "main")- for label in ("before", "release", "newer"):- _git(origin, "commit", "-q", "--allow-empty", "-m", label)+ _git(origin, "commit", "-q", "--allow-empty", "-m", "before")+ if side:+ _git(origin, "checkout", "-q", "-b", "release/1.2")+ _git(origin, "commit", "-q", "--allow-empty", "-m", "release")+ commits = {"before": _git(origin, "rev-parse", "HEAD~1"), "release": _git(origin, "rev-parse", "HEAD")}if tagged:- _git(origin, "tag", "-a", "v1.2.3", "-m", "release", "HEAD~1")- commits = {name: _git(origin, "rev-parse", ref)- for name, ref in (("before", "HEAD~2"), ("release", "HEAD~1"), ("tip", "HEAD"))}+ _git(origin, "tag", "-a", "v1.2.3", "-m", "release")+ _git(origin, "checkout", "-q", "main")+ _git(origin, "commit", "-q", "--allow-empty", "-m", "newer")+ commits["tip"] = _git(origin, "rev-parse", "HEAD")(home / ".gitconfig").write_text(f'[url "file://{origin}"]\n insteadOf = {OFFICIAL}\n', encoding="utf-8")(bin_dir / "curl").write_text('#!/bin/sh\ncase "$*" in *api.github.com*) printf \'{\\n "tag_name": "v1.2.3",\\n}\\n\';; *) exit 22;; esac\n',diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.mdindex f3ac0037e0f..ff24de02d18 100644--- a/website/docs/getting-started/updating.md+++ b/website/docs/getting-started/updating.md@@ -53,9 +53,12 @@ says the checkout is newer, instead of announcing a new update.The installers (`install.sh`, `install.ps1` and Hermes-Setup) put a new installon the latest stable release too. Re-running one over an install that never-chose a channel moves it forward to that release the same way (a checkout that-already contains it stays). Over an install that chose a channel other than-`main`, a rerun keeps its checkout where it is: only `hermes update` moves it.+chose a channel moves it onto that release only when the release descends from+its checkout. Any other checkout (one that followed `main`, or one already past+the release) stays where it is, and `hermes update` decides that move: it refuses+a release that predates the session stores the checkout already uses. Over an+install that chose a channel other than `main`, a rerun keeps its checkout where+it is: only `hermes update` moves it.To install the tip of `main` instead, pass `--channel main` (`-Channel main`for `install.ps1`, or set `HERMES_INSTALL_CHANNEL=main` before an`irm | iex` one-liner); the installer saves that choice the way