fix(banner): stop fabricating '1 commit behind' on SSH-official remotes

The SSH-official-remote path in _check_via_local_git was hard-coded to
return 1 when _check_via_rev reported UPDATE_AVAILABLE_NO_COUNT, so
'hermes --version' and the CLI banner surfaced a stable but false
'Update available: 1 commit behind — run hermes update' message. The
count never grew: whether upstream was 1 commit or 100 commits ahead,
the banner always said '1 commit behind'.

Root cause: an ls-remote probe against the upstream URL can only tell
us tip SHAs, not a real commit count. Returning the sentinel
UPDATE_AVAILABLE_NO_COUNT (-1) already means 'update exists, count
unknown' — the exact right shape for this path.

The dashboard/desktop UI does not depend on the fabricated 1:

- The REST /api/hermes/update/check endpoint
  (hermes_cli/web_server.py::check_hermes_update) treats any nonzero
  behind as update_available=true, and its docstring explicitly
  documents -1 as a legitimate value.
- The desktop store (apps/desktop/src/store/updates.ts::mapBackendCheck)
  clamps behind<=0 to 0 and reads updateAvailable as a separate boolean
  field.

So restoring the sentinel is a strict improvement: CLI banner and
hermes --version now say 'Update available' honestly instead of
inventing a count, and every REST/desktop consumer keeps working.

Changes:
- hermes_cli/banner.py: drop the 'return 1' override in the SSH branch;
  propagate the sentinel unchanged.
- hermes_cli/main.py::_print_version_info: render the sentinel as
  'Update available — run <cmd>' (without a count).
- tests/hermes_cli/test_update_check.py: update the SSH-official test
  to assert on the sentinel; add 3 new tests covering the CLI
  renderer's -1 / >0 / 0 branches.
This commit is contained in:
gkd2323c
2026-07-09 02:30:29 +08:00
committed by Teknium
parent c2bf1ac70a
commit 294071bf08
2 changed files with 17 additions and 6 deletions
+11 -4
View File
@@ -220,10 +220,17 @@ def _check_via_local_git(repo_dir: Path) -> Optional[int]:
origin_url = _git_stdout(["remote", "get-url", "origin"], cwd=repo_dir)
if _is_official_ssh_remote(origin_url):
head_rev = _git_stdout(["rev-parse", "HEAD"], cwd=repo_dir)
checked = _check_via_rev(head_rev) if head_rev else None
if checked == UPDATE_AVAILABLE_NO_COUNT:
return 1
return checked
# ls-remote against the upstream URL only tells us tip SHAs — there
# is no local history to count commits against. Return the
# UPDATE_AVAILABLE_NO_COUNT sentinel so the banner and CLI renderers
# print "update available" instead of fabricating a "1 commit behind"
# message. The dashboard's REST /api/hermes/update/check already
# treats any nonzero behind as update_available=true (see
# hermes_cli/web_server.py::check_hermes_update), and the desktop
# store clamps behind<=0 to 0 and reads update_available separately
# (apps/desktop/src/store/updates.ts::mapBackendCheck), so no UI
# consumer depends on a fabricated count here.
return _check_via_rev(head_rev) if head_rev else None
# Installer checkouts are shallow (`git clone --depth 1`). On a shallow
# clone the history stops at a single commit, so a plain `git fetch` would
+6 -2
View File
@@ -5079,11 +5079,15 @@ def _print_version_info(*, check_updates: bool = True) -> None:
# Show update status (synchronous — acceptable since user asked for version info)
try:
from hermes_cli.banner import check_for_updates
from hermes_cli.banner import UPDATE_AVAILABLE_NO_COUNT, check_for_updates
from hermes_cli.config import recommended_update_command
behind = check_for_updates()
if behind and behind > 0:
if behind == UPDATE_AVAILABLE_NO_COUNT:
print(
f"Update available — run '{recommended_update_command()}'"
)
elif behind and behind > 0:
commits_word = "commit" if behind == 1 else "commits"
print(
f"Update available: {behind} {commits_word} behind — "