The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): keep "git is required" on macOS when git is not on PATH
unsupportedpastelsb65e078cdc77
diff --git a/scripts/install.sh b/scripts/install.shindex 8a836822a41..395208bdf3c 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -541,22 +541,28 @@ git_runs() { command -v git >/dev/null 2>&1 && git --version >/dev/null 2>&1; }# Prefer Homebrew (headless); else open Apple's install dialog and wait for the# user to finish it, so the install continues in this run.install_macos_git() {+ # Developer tools present with their git (e.g. an Xcode license never+ # accepted, or a broken ~/.gitconfig): installing another git won't help,+ # so let the caller report git's own error. A folder alone is not enough:+ # a macOS upgrade can leave it behind empty.+ local _dev+ _dev="$(xcode-select -p 2>/dev/null)" || _dev=""+ [ -n "$_dev" ] && [ -x "$_dev/usr/bin/git" ] && return 0if command -v brew >/dev/null 2>&1; then# Auto-update runs git (the broken stub here) and can take minutes.run_logged --may-fail "Installing git with Homebrew" env HOMEBREW_NO_AUTO_UPDATE=1 brew install git || truehash -rgit_runs && return 0fi- # Developer tools present with their git (e.g. an Xcode license never- # accepted): no dialog will open, so let the caller report git's own error.- # A folder alone is not enough: a macOS upgrade can leave it behind empty.- local _dev- _dev="$(xcode-select -p 2>/dev/null)" || _dev=""- [ -n "$_dev" ] && [ -x "$_dev/usr/bin/git" ] && return 0# Opens Apple's install dialog. With a leftover folder it may refuse# instead ("already installed"); no dialog opens, so don't wait for one.- if ! xcode-select --install >/dev/null 2>&1 && [ -n "$_dev" ] && [ -d "$_dev" ]; then- fail "The developer tools at $_dev are incomplete and xcode-select --install declined to reinstall them. Reinstall the Command Line Tools (run: sudo rm -rf /Library/Developer/CommandLineTools, then xcode-select --install), then re-run this installer." git_missing+ local _xs+ if ! _xs="$(xcode-select --install 2>&1)"; then+ if [ -n "$_dev" ] && [ -d "$_dev" ]; then+ fail "The developer tools at $_dev are incomplete and xcode-select --install declined to reinstall them. Reinstall the Command Line Tools (run: sudo rm -rf /Library/Developer/CommandLineTools, then xcode-select --install), then re-run this installer." git_missing+ fi+ # Say why (e.g. no GUI session over SSH) before any wait.+ log_warn "xcode-select --install: $(printf '%s\n' "$_xs" | error_line)"filocal _remedy="Install Apple's Command Line Tools (run: xcode-select --install), then re-run this installer."# Hermes-Setup drives stages with --json: no stage timeout, a Cancel@@ -576,7 +582,8 @@ install_macos_git() {}stage_prerequisites() {- if [ "$(uname -s 2>/dev/null)" = Darwin ] && ! git_runs; then+ # No git on PATH at all is not the stub: report "git is required" below.+ if [ "$(uname -s 2>/dev/null)" = Darwin ] && command -v git >/dev/null 2>&1 && ! git_runs; theninstall_macos_gitficommand -v git >/dev/null 2>&1 || fail "git is required. Install it with your system package manager." git_missingdiff --git a/tests/hermes_cli/test_shared_metrics_install_run.py b/tests/hermes_cli/test_shared_metrics_install_run.pyindex 5fa13e8c84c..fc80ef28159 100644--- a/tests/hermes_cli/test_shared_metrics_install_run.py+++ b/tests/hermes_cli/test_shared_metrics_install_run.py@@ -136,7 +136,7 @@ def test_start_with_collection_off_purges_receipts_unreported(marks, monkeypatchassert marks.rows == [][email protected](sys.platform == "win32", reason="runs the real install.sh")[email protected]("posix")def test_real_install_sh_ladder_leaves_only_closed_tokens(tmp_path):"""The real ladder with git missing from PATH fails in prerequisites and parks one closed receipt."""tools = tmp_path / "bin"diff --git a/tests/scripts/install/test_install_sh_git_prerequisite.py b/tests/scripts/install/test_install_sh_git_prerequisite.pyindex 2730f75fc41..5ea206e353e 100644--- a/tests/scripts/install/test_install_sh_git_prerequisite.py+++ b/tests/scripts/install/test_install_sh_git_prerequisite.py@@ -23,6 +23,8 @@ _LICENSE_ERR = ("Please run 'sudo xcodebuild -license' from within a Terminal window to review and agree to the Xcode ""and Apple SDKs license.")+# Test text for a refused `xcode-select --install`, not Apple's exact wording.+_INSTALL_ERR = "xcode-select: error: no GUI session to show the install dialog"_WORKING_GIT = "#!/bin/sh\necho 'git version 2.50.1'\n"@@ -62,7 +64,8 @@ def _run_prerequisites(tmp_path: Path, *, git: str = "stub", interactive: bool =f'#!/bin/sh\nif [ "$1" = -p ]; then\n'f' if [ -d "{dev_dir}" ]; then echo "{dev_dir}"; exit 0; fi\n'f' echo "xcode-select: error: unable to get active developer directory" >&2; exit 2\nfi\n'- f'echo "xcode-select $*" >> "{calls}"\nexit {install_rc}\n')+ f'echo "xcode-select $*" >> "{calls}"\n'+ f'[ {install_rc} -eq 0 ] || echo "{_INSTALL_ERR}" >&2\nexit {install_rc}\n')# Each poll interval is where the user may finish Apple's dialog.finish = f'touch "{done}"\n' if clt_finishes else ""_exe(bin_dir / "sleep", f'#!/bin/sh\necho "sleep $*" >> "{calls}"\n{finish}exit 0\n')@@ -90,8 +93,15 @@ def _run_prerequisites(tmp_path: Path, *, git: str = "stub", interactive: bool =@pytest.mark.platforms("macos")-def test_macos_stub_waits_for_clt_dialog_then_continues(tmp_path):- result, calls = _run_prerequisites(tmp_path, interactive=True)[email protected]("opts", [+ pytest.param({"interactive": True}, id="terminal"),+ # Hermes-Setup runs stages with --non-interactive --json and no terminal.+ pytest.param({"json": True}, id="hermes-setup-json"),+ # After a macOS upgrade `-p` names a folder that exists but holds no git.+ pytest.param({"dev": "damaged", "interactive": True}, id="upgrade-leftover-folder"),+])+def test_macos_stub_opens_clt_dialog_waits_then_continues(tmp_path, opts):+ result, calls = _run_prerequisites(tmp_path, **opts)assert result.returncode == 0, result.stderrassert "click Install" in result.stdout@@ -100,12 +110,12 @@ def test_macos_stub_waits_for_clt_dialog_then_continues(tmp_path):@pytest.mark.platforms("macos")-def test_macos_stub_hermes_setup_json_run_waits_too(tmp_path):- """Hermes-Setup runs stages with --non-interactive --json and no terminal."""- result, calls = _run_prerequisites(tmp_path, interactive=False, json=True)+def test_macos_stub_shows_why_clt_install_failed_before_waiting(tmp_path):+ result, calls = _run_prerequisites(tmp_path, install_rc=1, interactive=True)assert result.returncode == 0, result.stderr- assert "prerequisites ok" in result.stdout+ assert _INSTALL_ERR in result.stdout+ assert result.stdout.index(_INSTALL_ERR) < result.stdout.index("click Install")assert calls == ["xcode-select --install", "sleep 5"]@@ -118,16 +128,6 @@ def test_macos_stub_prefers_homebrew_without_dialog(tmp_path):assert calls == ["brew install git auto_update_off=1"][email protected]("macos")-def test_macos_headless_non_interactive_fails_fast_with_remedy(tmp_path):- result, calls = _run_prerequisites(tmp_path, interactive=False)-- assert result.returncode != 0- assert "xcode-select --install" in result.stderr- assert "prerequisites ok" not in result.stdout- assert calls == ["xcode-select --install"]--@pytest.mark.platforms("macos")def test_macos_stub_wait_gives_up_after_fifteen_minutes(tmp_path):result, calls = _run_prerequisites(tmp_path, interactive=True, clt_finishes=False)@@ -139,36 +139,28 @@ def test_macos_stub_wait_gives_up_after_fifteen_minutes(tmp_path):@pytest.mark.platforms("macos")-def test_macos_tools_present_but_git_fails_reports_git_error_without_waiting(tmp_path):- """An unaccepted Xcode license: no dialog opens, so neither prompt nor wait."""- result, calls = _run_prerequisites(tmp_path, git="license", dev="complete", interactive=True)-- assert result.returncode != 0- assert "git is installed but cannot run" in result.stderr- assert "sudo xcodebuild -license" in result.stderr- assert "Command Line Tools" not in result.stderr- assert calls == []--[email protected]("macos")-def test_macos_upgrade_leftover_tools_folder_still_opens_dialog(tmp_path):- """After a macOS upgrade `-p` names a folder that exists but holds no git."""- result, calls = _run_prerequisites(tmp_path, dev="damaged", interactive=True)-- assert result.returncode == 0, result.stderr- assert "prerequisites ok" in result.stdout- assert calls == ["xcode-select --install", "sleep 5"]--[email protected]("macos")-def test_macos_damaged_tools_install_refused_fails_fast_with_reinstall_remedy(tmp_path):- """`--install` refuses over a leftover folder: no dialog opens, so no wait."""- result, calls = _run_prerequisites(tmp_path, dev="damaged", install_rc=1, interactive=True)[email protected](("opts", "expect", "forbid", "expected_calls"), [+ pytest.param({}, ["xcode-select --install"], [], ["xcode-select --install"], id="headless-non-interactive"),+ # An unaccepted Xcode license: the tools hold git, so no brew, dialog or wait,+ # and git's own remedy rather than the Command Line Tools one.+ pytest.param({"git": "license", "dev": "complete", "brew": True, "interactive": True},+ ["git is installed but cannot run", "sudo xcodebuild -license"], ["Command Line Tools"], [],+ id="tools-present-git-fails"),+ # `--install` refuses over a leftover folder: no dialog opens, so no wait.+ pytest.param({"dev": "damaged", "install_rc": 1, "interactive": True},+ ["sudo rm -rf /Library/Developer/CommandLineTools"], [], ["xcode-select --install"],+ id="install-refused-over-leftover-folder"),+])+def test_macos_fails_fast_with_remedy(tmp_path, opts, expect, forbid, expected_calls):+ result, calls = _run_prerequisites(tmp_path, **opts)assert result.returncode != 0- assert "sudo rm -rf /Library/Developer/CommandLineTools" in result.stderr+ for text in expect:+ assert text in result.stderr+ for text in forbid:+ assert text not in result.stderrassert "prerequisites ok" not in result.stdout- assert calls == ["xcode-select --install"]+ assert calls == expected_calls@pytest.mark.platforms("linux")