The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): probe update-check origin URL under the fetch's isolated git env
liuhao102403c20babba84
diff --git a/hermes_cli/banner.py b/hermes_cli/banner.pyindex eb0b714c73c..291701523cd 100644--- a/hermes_cli/banner.py+++ b/hermes_cli/banner.py@@ -180,8 +180,8 @@ def _git_run(args: list[str], *, cwd: Optional[Path] = None, timeout: int = 5, treturn None-def _git_stdout(args: list[str], *, cwd: Path, timeout: int = 5) -> Optional[str]:- result = _git_run(args, cwd=cwd, timeout=timeout)+def _git_stdout(args: list[str], *, cwd: Path, timeout: int = 5, network: bool = False) -> Optional[str]:+ result = _git_run(args, cwd=cwd, timeout=timeout, network=network)if result is None or result.returncode != 0:return Nonereturn (result.stdout or "").strip()@@ -262,7 +262,12 @@ def _check_via_rev(local_rev: str) -> Optional[int]:def _check_via_local_git(repo_dir: Path) -> Optional[int]:"""Count commits behind origin/main in a local checkout."""- origin_url = _git_stdout(["remote", "get-url", "origin"], cwd=repo_dir)+ # Probe the origin URL under the same config-isolated env as the fetch below. A plain+ # get-url applies a global url.<https>.insteadOf rewrite, so an SSH origin masquerades as+ # HTTPS, the SSH-avoiding fast path is skipped — and the fetch, whose env drops global+ # config (GIT_CONFIG_GLOBAL=/dev/null), dials the raw SSH origin; its host-key prompt opens+ # /dev/tty directly and steals the CLI's keystrokes (#104591).+ origin_url = _git_stdout(["remote", "get-url", "origin"], cwd=repo_dir, network=True)if _is_official_ssh_remote(origin_url):head_rev = _git_stdout(["rev-parse", "HEAD"], cwd=repo_dir)if not head_rev:diff --git a/tests/hermes_cli/test_banner_git_state.py b/tests/hermes_cli/test_banner_git_state.pyindex 065a000aff9..2dbb106da2a 100644--- a/tests/hermes_cli/test_banner_git_state.py+++ b/tests/hermes_cli/test_banner_git_state.py@@ -55,7 +55,7 @@ def test_check_via_local_git_ssh_fastpath_ahead_not_behind(tmp_path):repo_dir = tmp_path / "repo"(repo_dir / ".git").mkdir(parents=True)- def fake_git_stdout(args, *, cwd, timeout=5):+ def fake_git_stdout(args, *, cwd, timeout=5, network=False):if args == ["remote", "get-url", "origin"]:return "[email protected]:NousResearch/hermes-agent.git"if args == ["rev-parse", "HEAD"]:@@ -82,7 +82,7 @@ def test_check_via_local_git_ssh_fastpath_genuinely_behind(tmp_path):repo_dir = tmp_path / "repo"(repo_dir / ".git").mkdir(parents=True)- def fake_git_stdout(args, *, cwd, timeout=5):+ def fake_git_stdout(args, *, cwd, timeout=5, network=False):if args == ["remote", "get-url", "origin"]:return "[email protected]:NousResearch/hermes-agent.git"if args == ["rev-parse", "HEAD"]:@@ -110,7 +110,7 @@ def test_check_via_local_git_ssh_fastpath_offline_keeps_sentinel(tmp_path):repo_dir = tmp_path / "repo"(repo_dir / ".git").mkdir(parents=True)- def fake_git_stdout(args, *, cwd, timeout=5):+ def fake_git_stdout(args, *, cwd, timeout=5, network=False):if args == ["remote", "get-url", "origin"]:return "[email protected]:NousResearch/hermes-agent.git"if args == ["rev-parse", "HEAD"]:@@ -126,3 +126,68 @@ def test_check_via_local_git_ssh_fastpath_offline_keeps_sentinel(tmp_path):behind = banner._check_via_local_git(repo_dir)assert behind == banner.UPDATE_AVAILABLE_NO_COUNT+++def test_check_via_local_git_insteadof_rewrite_routes_to_ssh_fastpath(tmp_path, monkeypatch):+ """#104591: the origin-URL probe must run under the fetch's config-isolated env.++ A global ``url.<https>.insteadOf`` rewrite makes a plain ``git remote get-url origin``+ report HTTPS for an SSH origin, so the SSH-avoiding fast path is skipped — while the+ fetch itself drops global config (``GIT_CONFIG_GLOBAL=/dev/null``), dials the raw SSH+ origin, and its host-key prompt opens /dev/tty and steals the CLI's keystrokes. With the+ probe under the same isolated env both sides observe the raw SSH URL and the HTTPS+ ls-remote fast path runs instead — no fetch, no ssh child.+ """+ import os+ import subprocess++ from hermes_cli import banner++ repo_dir = tmp_path / "repo"+ repo_dir.mkdir()+ # Config-isolated setup so the developer's own global git config can't leak in.+ setup_env = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_SYSTEM": os.devnull}+ setup_cmds = [+ ["git", "init", "-q"],+ ["git", "commit", "--allow-empty", "-q", "-m", "init"],+ ["git", "remote", "add", "origin", "[email protected]:NousResearch/hermes-agent.git"],+ ["git", "rev-parse", "HEAD"],+ ]+ head_sha = None+ for argv in setup_cmds:+ done = subprocess.run(+ argv, cwd=repo_dir, env=setup_env, check=True, capture_output=True, text=True)+ if argv[1] == "rev-parse":+ head_sha = done.stdout.strip()+ assert head_sha++ # Global config (visible only without GIT_CONFIG_GLOBAL isolation) rewrites SSH to HTTPS.+ home = tmp_path / "home"+ home.mkdir()+ (home / ".gitconfig").write_text(+ '[url "https://github.com/"]\n\tinsteadOf = [email protected]:\n', encoding="utf-8")+ monkeypatch.setenv("HOME", str(home))+ monkeypatch.setenv("USERPROFILE", str(home)) # Git for Windows resolves global config here too++ calls = []+ real_run = banner.subprocess.run++ def spy_run(args, **kwargs):+ calls.append((list(args), kwargs))+ if args[1] == "ls-remote":+ return MagicMock(returncode=0, stdout=f"{head_sha}\trefs/heads/main\n")+ return real_run(args, **kwargs)++ monkeypatch.setattr(banner.subprocess, "run", spy_run)++ behind = banner._check_via_local_git(repo_dir)++ # Same upstream tip as HEAD: the SSH fast path concludes "not behind".+ assert behind == 0+ assert not any(args[1] == "fetch" for args, _ in calls), (+ "insteadOf rewrite must not smuggle the check into the fetch branch")+ probe = next(+ (kwargs for args, kwargs in calls if args[1:3] == ["remote", "get-url"]), None)+ assert probe is not None+ assert probe["env"]["GIT_CONFIG_GLOBAL"] == os.devnull, (+ "the origin-URL probe must observe the URL the isolated fetch will dial")diff --git a/tests/hermes_cli/test_update_check.py b/tests/hermes_cli/test_update_check.pyindex 22c34bd6219..1669cf82bae 100644--- a/tests/hermes_cli/test_update_check.py+++ b/tests/hermes_cli/test_update_check.py@@ -91,7 +91,7 @@ def test_check_via_local_git_fetch_failure_returns_none(tmp_path, monkeypatch):(repo_dir / ".git").mkdir()# Simulate a non-shallow, non-SSH-remote checkout- def mock_git_stdout(args, *, cwd, timeout=5):+ def mock_git_stdout(args, *, cwd, timeout=5, network=False):if args[:2] == ["remote", "get-url"]:return "https://github.com/NousResearch/hermes-agent.git"if args[:2] == ["rev-parse", "--is-shallow-repository"]:@@ -142,7 +142,7 @@ def test_check_via_local_git_fetch_failure_keeps_positive_stale_count(tmp_path,repo_dir.mkdir()(repo_dir / ".git").mkdir()- def mock_git_stdout(args, *, cwd, timeout=5):+ def mock_git_stdout(args, *, cwd, timeout=5, network=False):if args[:2] == ["remote", "get-url"]:return "https://github.com/NousResearch/hermes-agent.git"if args[:2] == ["rev-parse", "--is-shallow-repository"]:@@ -180,7 +180,7 @@ def test_check_via_local_git_fetch_failure_rev_list_error_returns_none(tmp_path,repo_dir.mkdir()(repo_dir / ".git").mkdir()- def mock_git_stdout(args, *, cwd, timeout=5):+ def mock_git_stdout(args, *, cwd, timeout=5, network=False):if args[:2] == ["remote", "get-url"]:return "https://github.com/NousResearch/hermes-agent.git"if args[:2] == ["rev-parse", "--is-shallow-repository"]: