Skip to content

The agent that grows with you

refactor(update): remove orphaned tag selection helpers

ethernetd10edca3c5f9
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 46088fa6382..27fc25bd642 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -605,51 +605,6 @@ def _run_logged_subprocess(cmd, *, cwd=None, env=None):
proc.stdout.close()
-_RELEASE_TAG_RE = re.compile(r"^v(0|[1-9]\d{0,2})\.(\d+)\.(\d+)$")
-def _parse_release_tag(tag: str):
- """Parse ``vX.Y.Z`` into a sortable (X, Y, Z) tuple, or return None.
-
- Tags with a pre-release or build suffix (``v1.2.3-rc1``) return None.
- Tags that do not have the shape of a final release also return None.
- The stable channel only moves between final releases.
- """
- m = _RELEASE_TAG_RE.match(tag.strip())
- if not m:
- return None
- return tuple(int(g) for g in m.groups())
-def _latest_release_tag_from_ls_remote(output: str):
- """Select the newest final-release tag from ``git ls-remote --tags`` output.
-
- Returns ``(tag, sha)`` or ``(None, None)``. Peeled entries (``^{}``) have
- priority over the tag-object SHA. Thus annotated tags and lightweight tags
- both give the commit SHA.
- """
- best = None # (version_tuple, tag)
- shas = {} # tag -> commit sha (peeled wins)
- for line in output.splitlines():
- parts = line.split("\t")
- if len(parts) != 2:
- continue
- sha, ref = parts
- if not ref.startswith("refs/tags/"):
- continue
- name = ref[len("refs/tags/"):]
- peeled = name.endswith("^{}")
- if peeled:
- name = name[:-3]
- version = _parse_release_tag(name)
- if version is None:
- continue
- if peeled or name not in shas:
- shas[name] = sha.strip()
- if best is None or version > best[0]:
- best = (version, name)
- if best is None:
- return None, None
- tag = best[1]
- return tag, shas.get(tag)
-
-
def _source_update_channel(args=None, *, channel=None, branch_explicit=False) -> str:
"""Explicit branches win; otherwise transient channel, then this install's record."""
if branch_explicit or getattr(args, "branch", None):
diff --git a/scripts/release.py b/scripts/release.py
index fcd0da57fd0..419d71678fc 100755
--- a/scripts/release.py
+++ b/scripts/release.py
@@ -2249,8 +2249,7 @@ def remote_github_repo(remote: str) -> str | None:
return match.group(1) if match else None
-# Cap the major at three digits — the same rule as _parse_release_tag in
-# hermes_cli/update_cmd.py and _SEMVER_TAG_RE in scripts/write_install_stamp.py.
+# Cap the major at three digits, as in scripts/write_install_stamp.py.
# The legacy CalVer tags (v2026.7.20) must never match as SemVer.
_SEMVER_TAG_RE = re.compile(r"v(?:0|[1-9]\d{0,2})\.\d+\.\d+$")
_LEGACY_CALVER_TAG_RE = re.compile(r"v20\d{2}\.\d+\.\d+(?:\.\d+)?$")
diff --git a/tests/hermes_cli/test_update_channel_stable.py b/tests/hermes_cli/test_update_channel_stable.py
index c18b408f459..9411de4dd1d 100644
--- a/tests/hermes_cli/test_update_channel_stable.py
+++ b/tests/hermes_cli/test_update_channel_stable.py
@@ -1,80 +1,8 @@
-"""Release-tag parsing and source-update channel selection policy."""
+"""Source-update channel selection policy."""
from unittest.mock import patch
-from hermes_cli.update_cmd import (
- _latest_release_tag_from_ls_remote,
- _parse_release_tag,
- _source_update_channel,
-)
-
-
-class TestParseReleaseTag:
- def test_final_releases_parse(self):
- assert _parse_release_tag("v0.17.0") == (0, 17, 0)
- assert _parse_release_tag("v10.2.33") == (10, 2, 33)
- assert _parse_release_tag(" v1.2.3 ") == (1, 2, 3)
-
- def test_prereleases_and_garbage_rejected(self):
- for tag in ("v1.2.3-rc1", "v1.2.3-beta.1", "v1.2", "1.2.3", "release-1", "vv1.2.3", ""):
- assert _parse_release_tag(tag) is None, tag
-
- def test_canary_tags_never_reach_the_stable_channel(self):
- """The inverse direction of the canary channel: canary tags are
- version-suffixed (v0.28.0-canary.20260818), and the stable
- selector's no-suffix rule is what keeps a canary prerelease from
- ever winning a stable-channel update. If this shape ever parses,
- stable users get canaries."""
- assert _parse_release_tag("v0.28.0-canary.20260818") is None
- assert _parse_release_tag("v1.0.0-canary.1") is None
-
- def test_calver_tags_rejected(self):
- """Historical CalVer tags (v2026.7.20) must not win a numeric sort.
-
- The major component is capped at three digits, the same rule as
- _SEMVER_TAG_RE in scripts/write_install_stamp.py and
- latestReleaseFromLsRemote in apps/desktop. A four-digit year would
- rank above every SemVer release forever.
- """
- assert _parse_release_tag("v2026.7.20") is None
- assert _parse_release_tag("v1000.0.0") is None
- assert _parse_release_tag("v999.0.0") == (999, 0, 0)
-
- def test_numeric_ordering_not_lexicographic(self):
- """v0.10.0 must sort above v0.9.0 — the whole point of tuple parsing."""
- newer, older = _parse_release_tag("v0.10.0"), _parse_release_tag("v0.9.0")
- assert newer is not None and older is not None
- assert newer > older
-
-
-class TestLatestReleaseTagFromLsRemote:
- def test_picks_newest_final_release(self):
- output = (
- "aaa1\trefs/tags/v0.9.0\n"
- "bbb2\trefs/tags/v0.10.0\n"
- "ccc3\trefs/tags/v0.10.1-rc1\n"
- "ddd4\trefs/tags/some-other-tag\n"
- )
- tag, sha = _latest_release_tag_from_ls_remote(output)
- assert tag == "v0.10.0"
- assert sha == "bbb2"
-
- def test_peeled_sha_wins_for_annotated_tags(self):
- output = (
- "tagobj\trefs/tags/v1.0.0\n"
- "commitsha\trefs/tags/v1.0.0^{}\n"
- )
- tag, sha = _latest_release_tag_from_ls_remote(output)
- assert tag == "v1.0.0"
- assert sha == "commitsha"
-
- def test_no_release_tags(self):
- assert _latest_release_tag_from_ls_remote("aaa\trefs/tags/nightly\n") == (None, None)
- assert _latest_release_tag_from_ls_remote("") == (None, None)
-
- def test_malformed_lines_ignored(self):
- output = "garbage line no tab\naaa\trefs/heads/main\nbbb\trefs/tags/v2.0.0\n"
- assert _latest_release_tag_from_ls_remote(output) == ("v2.0.0", "bbb")
+from hermes_cli.update_cmd import _source_update_channel
class _Args: