The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): peel an annotated-tag pin before verifying the checkout
tobenwarriordff92f3d78b6
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.pyindex a234264c446..3fdf1c23877 100644--- a/hermes_cli/plugins_cmd.py+++ b/hermes_cli/plugins_cmd.py@@ -538,6 +538,28 @@ def _git_head_revision(repo: Path, git_exe: str) -> str:).stdout.strip().lower()+def _git_resolve_commit(repo: Path, git_exe: str, revision: str) -> str:+ """The COMMIT a revision names, peeling annotated tags.++ A catalog pin is 40 hex, but that does not make it a commit: a tag object+ has a sha of its own, and a pin recorded as `git rev-parse <tag>` names the+ tag object, not the commit it points at. Git detaches at the commit, so+ comparing HEAD against the tag object's sha refuses a correct checkout+ (and the catalog installer then cannot install that entry at all). Peeling+ first keeps the guard — HEAD must still BE that commit — while admitting+ the pins authors actually publish. Returns `revision` unchanged when it+ resolves to nothing, so the mismatch guard below still fires.+ """+ try:+ result = _run_plugin_git(+ git_exe, repo, "rev-parse", "--verify", "--quiet", f"{revision}^{{commit}}", timeout=15,+ )+ except (OSError, subprocess.TimeoutExpired):+ return revision+ resolved = result.stdout.strip().lower()+ return resolved if result.returncode == 0 and resolved else revision++def _checkout_exact_revision(repo: Path, git_exe: str, revision: str, source_url: str = "") -> None:"""Fetch and detach at one immutable commit, then verify the resulting HEAD."""for verb, args, failure_prefix in (@@ -550,7 +572,7 @@ def _checkout_exact_revision(repo: Path, git_exe: str, revision: str, source_urlexcept subprocess.TimeoutExpired as exc:raise PluginOperationError(f"Git {verb} of commit '{revision}' timed out after 60 seconds.") from excactual = _git_head_revision(repo, git_exe)- if actual != revision:+ if actual != _git_resolve_commit(repo, git_exe, revision):raise PluginOperationError(f"Checked-out revision '{actual}' does not match requested commit '{revision}'.")diff --git a/tests/hermes_cli/test_plugin_install_ref.py b/tests/hermes_cli/test_plugin_install_ref.pyindex f7f1dbec1e3..ece3d8ca2c0 100644--- a/tests/hermes_cli/test_plugin_install_ref.py+++ b/tests/hermes_cli/test_plugin_install_ref.py@@ -364,3 +364,53 @@ def test_reinstall_after_manual_directory_removal_retains_pin(monkeypatch, tmp_passert _git(target, "rev-parse", "HEAD") == old_shaassert _metadata(home)["demo"]["pinned"] is True+++def test_annotated_tag_pin_installs_at_its_commit(monkeypatch, tmp_path):+ """A pin recorded from an annotated tag — the TAG object's sha, which is 40+ hex but not a commit — must install at the commit that tag points to.++ Catalog entries publish pins this way whenever the author runs+ `git rev-parse <tag>`; git detaches at the tag's commit, so the guard has+ to peel before comparing or the entry is uninstallable.+ """+ from hermes_cli.plugins_cmd import _install_plugin_core++ repo, old_sha, _new_sha = _plugin_repo(tmp_path)+ _git(repo, "tag", "-a", "v1.0.2", old_sha, "-m", "v1.0.2")+ tag_object_sha = _git(repo, "rev-parse", "v1.0.2")++ # The premise: the tag's own sha names the tag object, not the commit.+ assert tag_object_sha != old_sha+ assert _git(repo, "cat-file", "-t", tag_object_sha) == "tag"++ home = tmp_path / "home"+ monkeypatch.setenv("HERMES_HOME", str(home))++ target, _manifest, _name = _install_plugin_core(+ repo.as_uri(), force=False, ref=tag_object_sha+ )++ assert _git(target, "rev-parse", "HEAD") == old_sha+ assert (target / "marker.txt").read_text() == "old"+ # The durable record is the commit, not the tag object: `plugins update`+ # and the drift guard both compare against it.+ assert _metadata(home)["demo"]["revision"] == old_sha+++def test_checkout_that_lands_on_another_commit_is_still_rejected(monkeypatch, tmp_path):+ """Peeling must not weaken the guard: an annotated tag pin whose checkout+ ends somewhere else is still a mismatch."""+ from hermes_cli.plugins_cmd import PluginOperationError, _checkout_exact_revision++ repo, old_sha, new_sha = _plugin_repo(tmp_path)+ _git(repo, "tag", "-a", "v1.0.2", old_sha, "-m", "v1.0.2")+ tag_object_sha = _git(repo, "rev-parse", "v1.0.2")+ clone = tmp_path / "clone"+ subprocess.run(["git", "clone", "-q", repo.as_uri(), str(clone)], check=True)+ monkeypatch.setattr(+ "hermes_cli.plugins_cmd._git_head_revision", lambda _repo, _git: new_sha+ )++ with pytest.raises(PluginOperationError, match="does not match requested"):+ _checkout_exact_revision(clone, "git", tag_object_sha)