The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): map SSL_CERT_FILE into GIT_SSL_CAINFO for git children
kokhloc70374b561c3
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 9b297bc1ba8..88c69bd75a5 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -166,6 +166,31 @@ def _updates_config() -> dict:return section if isinstance(section, dict) else {}+def _map_ssl_cert_file_for_git(git_cmd) -> None:+ """Point git's libcurl at the same CA bundle Python already trusts.++ git ignores ``SSL_CERT_FILE`` (its libcurl reads only ``GIT_SSL_CAINFO`` /+ ``http.sslCAInfo``), so on a network with a TLS-inspecting proxy whose+ corporate root lives only in that variable the channel read succeeds and+ the very next ``git fetch`` dies with "certificate signer not trusted" —+ half the updater trusting a bundle the other half refuses. Written into+ ``os.environ`` once so every git child the updater spawns sees it: the+ network fetches (via ``_no_prompt_git_kwargs``) and the partial-clone+ checkout's lazy promisor fetches (which inherit the process env).++ An explicit ``GIT_SSL_CAINFO`` or a configured ``http.sslCAInfo`` wins:+ the env var outranks the config file in git's precedence, so mapping over+ either would silently override a deliberate choice.+ """+ bundle = os.environ.get("SSL_CERT_FILE")+ if not bundle or os.environ.get("GIT_SSL_CAINFO"):+ return+ configured = _git_run(git_cmd, ["config", "--get", "http.sslCAInfo"])+ if configured.returncode == 0 and configured.stdout.strip():+ return+ os.environ["GIT_SSL_CAINFO"] = bundle++def _no_prompt_git_kwargs() -> dict:"""``subprocess.run`` kwargs for the updater's network git calls.@@ -596,6 +621,10 @@ def _cmd_update_check(branch: str = "main", *, branch_explicit: bool = False, chsys.exit(1)git_cmd = _base_git_cmd()+ # The check fetches over HTTPS too; give git the same CA bundle Python+ # uses, or --check fails where the apply path succeeds (see+ # _map_ssl_cert_file_for_git).+ _map_ssl_cert_file_for_git(git_cmd)_check.clear_git_debris(root)selected_channel = _source_update_channel(channel=channel, branch_explicit=branch_explicit)@@ -1114,6 +1143,10 @@ def _prepare_git_command() -> tuple[bool, list, bool]:git_cmd = _base_git_cmd()if sys.platform == "win32" and git_dir.exists():_git_run(git_cmd, ["config", "windows.appendAtomically", "false"])+ # One CA story for the whole update: git's libcurl must trust what the+ # channel read already trusts, or the fetch dies mid-update behind a+ # TLS-inspecting proxy (see _map_ssl_cert_file_for_git).+ _map_ssl_cert_file_for_git(git_cmd)# A broken Git-for-Windows trampoline refuses every call with a "BUG (fork bomb)" guard;# swap in a real binary up front so git survives instead of degrading to ZIP.# See #87876.diff --git a/tests/hermes_cli/test_update_ssl_cert_file.py b/tests/hermes_cli/test_update_ssl_cert_file.pynew file mode 100644index 00000000000..5f445311c02--- /dev/null+++ b/tests/hermes_cli/test_update_ssl_cert_file.py@@ -0,0 +1,87 @@+"""SSL_CERT_FILE → GIT_SSL_CAINFO mapping for the updater's git children.++git's libcurl ignores ``SSL_CERT_FILE``: GnuTLS builds do, and so do OpenSSL+builds with a compiled-in CA path. git reads only ``GIT_SSL_CAINFO`` /+``http.sslCAInfo``. Behind a TLS-inspecting proxy whose corporate root lives+only in ``SSL_CERT_FILE``, the channel read (Python honors it) succeeded and+the very next ``git fetch`` failed with "certificate signer not trusted",+reported as a "Network error". The updater must keep one CA story across all+of its git children — including the partial-clone checkout's lazy promisor+fetches, which inherit the process environment rather than+``_no_prompt_git_kwargs``.+"""++import subprocess++from hermes_cli import update_cmd+++def _git_config_reader(configured: str | None):+ """A ``git`` double answering ``config --get http.sslCAInfo``."""+ calls = []++ def run(cmd, args, **kwargs):+ calls.append(args)+ if args[:3] == ["config", "--get", "http.sslCAInfo"]:+ out = configured if configured is not None else ""+ return subprocess.CompletedProcess(cmd, 0 if configured else 1, out, "")+ raise AssertionError(f"unexpected git call: {args}")++ return run, calls+++class TestMapSslCertFileForGit:+ def test_maps_when_only_ssl_cert_file_is_set(self, monkeypatch, tmp_path):+ monkeypatch.setenv("SSL_CERT_FILE", str(tmp_path / "corp-bundle.pem"))+ monkeypatch.delenv("GIT_SSL_CAINFO", raising=False)+ run, _ = _git_config_reader(None)+ monkeypatch.setattr(update_cmd, "_git_run", run)+ update_cmd._map_ssl_cert_file_for_git(["git"])+ import os+ assert os.environ["GIT_SSL_CAINFO"] == str(tmp_path / "corp-bundle.pem")++ def test_explicit_git_ssl_cainfo_wins(self, monkeypatch, tmp_path):+ monkeypatch.setenv("SSL_CERT_FILE", str(tmp_path / "corp-bundle.pem"))+ monkeypatch.setenv("GIT_SSL_CAINFO", str(tmp_path / "git-pinned.pem"))+ run, calls = _git_config_reader(None)+ monkeypatch.setattr(update_cmd, "_git_run", run)+ update_cmd._map_ssl_cert_file_for_git(["git"])+ import os+ assert os.environ["GIT_SSL_CAINFO"] == str(tmp_path / "git-pinned.pem")+ assert calls == [] # the env pin short-circuits before git is consulted++ def test_configured_http_sslcainfo_is_not_overridden(self, monkeypatch, tmp_path):+ monkeypatch.setenv("SSL_CERT_FILE", str(tmp_path / "corp-bundle.pem"))+ monkeypatch.delenv("GIT_SSL_CAINFO", raising=False)+ run, _ = _git_config_reader(str(tmp_path / "configured.pem"))+ monkeypatch.setattr(update_cmd, "_git_run", run)+ update_cmd._map_ssl_cert_file_for_git(["git"])+ import os+ assert "GIT_SSL_CAINFO" not in os.environ++ def test_noop_without_ssl_cert_file(self, monkeypatch):+ monkeypatch.delenv("SSL_CERT_FILE", raising=False)+ monkeypatch.delenv("GIT_SSL_CAINFO", raising=False)+ run, calls = _git_config_reader(None)+ monkeypatch.setattr(update_cmd, "_git_run", run)+ update_cmd._map_ssl_cert_file_for_git(["git"])+ import os+ assert "GIT_SSL_CAINFO" not in os.environ+ assert calls == [] # nothing to map — git is never consulted++ def test_mapped_bundle_reaches_network_git_children(self, monkeypatch, tmp_path):+ """The mapping is live in the env of a network git call made after it."""+ import os+ monkeypatch.setenv("SSL_CERT_FILE", str(tmp_path / "corp-bundle.pem"))+ monkeypatch.delenv("GIT_SSL_CAINFO", raising=False)++ def run(cmd, args, **kwargs):+ if args[:3] == ["config", "--get", "http.sslCAInfo"]:+ return subprocess.CompletedProcess(cmd, 1, "", "")+ return subprocess.CompletedProcess(cmd, 0, "", "")++ monkeypatch.setattr(update_cmd, "_git_run", run)+ update_cmd._map_ssl_cert_file_for_git(["git"])+ kw = update_cmd._no_prompt_git_kwargs()+ assert kw["env"]["GIT_SSL_CAINFO"] == str(tmp_path / "corp-bundle.pem")+ assert os.environ["GIT_SSL_CAINFO"] == str(tmp_path / "corp-bundle.pem")