Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion hermes_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
# any dependency touching ``platform.uname()`` at import time flashes a
# visible console when this process is windowless (pythonw gateway + every

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update pipeline was moved by 927463efcc441060c833aa70c99161115a547583 into hermes_cli/update_cmd.py; main.py now only re-exports these functions. Move this import and the hardened subprocess arguments to update_cmd.py, otherwise the live remote update calls remain unchanged.

# kanban worker). No-op on POSIX; never raises.
from hermes_cli._subprocess_compat import suppress_platform_ver_console
from hermes_cli._subprocess_compat import (
noninteractive_git_env,
suppress_platform_ver_console,
)

suppress_platform_ver_console()

Expand Down Expand Up @@ -8715,6 +8718,8 @@ def _sync_fork_with_upstream(git_cmd: list[str], cwd: Path) -> bool:
cwd=cwd,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
return result.returncode == 0
except Exception:
Expand Down Expand Up @@ -8778,6 +8783,8 @@ def _sync_with_upstream_if_needed(git_cmd: list[str], cwd: Path) -> None:
cwd=cwd,
capture_output=True,
check=True,
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
except subprocess.CalledProcessError:
print(" ✗ Failed to fetch upstream. Skipping upstream sync.")
Expand Down Expand Up @@ -8817,6 +8824,8 @@ def _sync_with_upstream_if_needed(git_cmd: list[str], cwd: Path) -> None:
git_cmd + ["pull", "--ff-only", "upstream", "main"],
cwd=cwd,
check=True,
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
except subprocess.CalledProcessError:
print(
Expand Down Expand Up @@ -11017,6 +11026,8 @@ def _cmd_update_check(branch: str = "main", *, branch_explicit: bool = False):
cwd=PROJECT_ROOT,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
if fetch_result.returncode != 0:
# Fallback to origin if upstream doesn't exist
Expand All @@ -11026,6 +11037,8 @@ def _cmd_update_check(branch: str = "main", *, branch_explicit: bool = False):
cwd=PROJECT_ROOT,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
upstream_exists = False
compare_branch = f"origin/{branch}"
Expand All @@ -11040,6 +11053,8 @@ def _cmd_update_check(branch: str = "main", *, branch_explicit: bool = False):
cwd=PROJECT_ROOT,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
upstream_exists = False
compare_branch = f"origin/{branch}"
Expand Down Expand Up @@ -12319,6 +12334,8 @@ def _cmd_update_impl(args, gateway_mode: bool):
cwd=PROJECT_ROOT,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
if fetch_result.returncode != 0:
stderr = fetch_result.stderr.strip()
Expand Down Expand Up @@ -12537,6 +12554,8 @@ def _cmd_update_impl(args, gateway_mode: bool):
cwd=PROJECT_ROOT,
capture_output=True,
text=True, encoding="utf-8", errors="replace",
stdin=subprocess.DEVNULL,
env=noninteractive_git_env(),
)
if pull_result.returncode != 0:
# ff-only failed — local and remote have diverged (e.g. upstream
Expand Down
44 changes: 44 additions & 0 deletions tests/hermes_cli/test_noninteractive_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,47 @@ def test_mcp_catalog_git_install_runs_noninteractively(monkeypatch, tmp_path):
for call in calls:
if call["argv"][0].endswith("git") or "git" in call["argv"][0]:
_assert_noninteractive(call)


# ---------------------------------------------------------------------------
# 4. `hermes update` — the same class, on the update path's own remote calls.
#
# These run in exactly the "nobody attached" contexts the helper exists for:
# desktop auto-update, a supervised backend restarting itself, `hermes update`
# from a launchd/systemd unit. They also capture output, so a credential
# prompt is invisible: the user sees "→ Fetching updates..." and nothing else.
# Updating from a (possibly private) fork is a first-class, detected case.
# ---------------------------------------------------------------------------


_REMOTE_GIT_VERBS = {"fetch", "pull", "push", "clone", "ls-remote"}


def _remote_calls(calls: list[dict]) -> list[dict]:
"""Captured runs whose argv drives a remote (auth-capable) git operation."""
return [c for c in calls if _REMOTE_GIT_VERBS & set(c["argv"])]


def test_update_fork_push_runs_noninteractively(monkeypatch, tmp_path):
from hermes_cli import main

calls = _capture_run(monkeypatch, main)
main._sync_fork_with_upstream(["git"], tmp_path)

remote = _remote_calls(calls)
assert remote, calls
for call in remote:
_assert_noninteractive(call)


def test_update_upstream_sync_runs_noninteractively(monkeypatch, tmp_path):
from hermes_cli import main

monkeypatch.setattr(main, "_has_upstream_remote", lambda *a, **k: True)
calls = _capture_run(monkeypatch, main)
main._sync_with_upstream_if_needed(["git"], tmp_path)

remote = _remote_calls(calls)
assert remote, calls
for call in remote:
_assert_noninteractive(call)
Loading