The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): install git on macOS again when /usr/bin/git is the CLT stub
unsupportedpastels5aaedc178b26
diff --git a/scripts/install.sh b/scripts/install.shindex 1d5e8dcc9f7..09d419cc1ec 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -534,19 +534,44 @@ emit_manifest() {printf '%s\n' ']}'}+git_runs() { command -v git >/dev/null 2>&1 && git --version >/dev/null 2>&1; }++# macOS ships /usr/bin/git as a stub until Apple's Command Line Tools are+# installed: it is on PATH, but every call fails ("see man xcode-select").+# Prefer Homebrew (headless); else open Apple's install dialog and, with a+# terminal, wait for the user to finish it so the install continues in this run.+install_macos_git() {+ if command -v brew >/dev/null 2>&1; then+ log "Installing git with Homebrew"+ brew install git >/dev/null 2>&1 || true+ hash -r+ git_runs && return 0+ fi+ # Opens Apple's install dialog; harmless if it is already open or done.+ xcode-select --install >/dev/null 2>&1 || true+ local _remedy="Install Apple's Command Line Tools (run: xcode-select --install), then re-run this installer."+ if [ "$NON_INTERACTIVE" = true ] || ! has_terminal; then+ fail "git needs Apple's Command Line Tools. $_remedy" git_missing+ fi+ log "git needs Apple's Command Line Tools: click Install in the macOS dialog and accept the license"+ local _waited=0+ while [ "$_waited" -lt 900 ]; do+ git_runs && return 0+ sleep 5+ _waited=$((_waited + 5))+ [ $((_waited % 60)) -ne 0 ] || log "Still waiting for the Command Line Tools install ($((_waited / 60))m)"+ done+ fail "Command Line Tools did not finish within 15 minutes. $_remedy" git_missing+}+stage_prerequisites() {+ if [ "$(uname -s 2>/dev/null)" = Darwin ] && ! git_runs; then+ install_macos_git+ ficommand -v git >/dev/null 2>&1 || fail "git is required. Install it with your system package manager." git_missing- # macOS ships /usr/bin/git as a stub until Apple's Command Line Tools are- # installed: it is on PATH, but every call fails ("see man xcode-select").local _git_errif ! _git_err="$(git --version 2>&1)"; then- _git_err="$(printf '%s\n' "$_git_err" | error_line)"- if [ "$(uname -s 2>/dev/null)" = Darwin ]; then- # Opens Apple's install dialog; harmless if it is already open or done.- xcode-select --install >/dev/null 2>&1 || true- fail "git cannot run ($_git_err). Install Apple's Command Line Tools (run: xcode-select --install), then re-run this installer." git_missing- fi- fail "git is installed but cannot run: $_git_err" git_missing+ fail "git is installed but cannot run: $(printf '%s\n' "$_git_err" | error_line)" git_missingficommand -v curl >/dev/null 2>&1 || fail "curl is required. Install it with your system package manager." curl_missing# PM's Node on musl is the unofficial-builds musl archive, which links thediff --git a/tests/installation/test_install_git_prerequisite.py b/tests/installation/test_install_git_prerequisite.pyindex dfd54ae73f7..9f8c26f1724 100644--- a/tests/installation/test_install_git_prerequisite.py+++ b/tests/installation/test_install_git_prerequisite.py@@ -2,7 +2,9 @@macOS ships /usr/bin/git as a stub until Apple's Command Line Tools areinstalled, so `command -v git` passes and the clone fails much later with-"git clone failed; no checkout published".+"git clone failed; no checkout published". On macOS the installer gets git+first: Homebrew when present, else Apple's install dialog, waiting for it+when a terminal is attached."""import os@@ -16,6 +18,7 @@ _STUB_ERR = ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), ""missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun")+_WORKING_GIT = "#!/bin/sh\necho 'git version 2.50.1'\n"def _exe(path: Path, body: str) -> None:@@ -24,55 +27,99 @@ def _exe(path: Path, body: str) -> None:path.chmod(0o755)-def _run_prerequisites(tmp_path: Path, *, git_works: bool, system: str):+def _run_prerequisites(tmp_path: Path, *, system: str, git: str = "stub", interactive: bool = False,+ brew: bool = False, clt_finishes: bool = True):+ """git: "stub" (fails until the CLT install finishes) or "working"."""bin_dir = tmp_path / "bin"- log = tmp_path / "xcode-select.log"- if git_works:- _exe(bin_dir / "git", "#!/bin/sh\necho 'git version 2.50.1'\n")+ brew_bin = tmp_path / "brew-bin"+ brew_bin.mkdir()+ done = tmp_path / "clt-done"+ calls = tmp_path / "calls.log"+ if git == "working":+ _exe(bin_dir / "git", _WORKING_GIT)else:- _exe(bin_dir / "git", f'#!/bin/sh\necho "{_STUB_ERR}" >&2\nexit 1\n')+ _exe(bin_dir / "git", f'#!/bin/sh\nif [ -f "{done}" ]; then echo "git version 2.39.5"; exit 0; fi\n'+ f'echo "{_STUB_ERR}" >&2\nexit 1\n')_exe(bin_dir / "curl", "#!/bin/sh\nexit 0\n")_exe(bin_dir / "uname", f"#!/bin/sh\necho {system}\n")- _exe(bin_dir / "xcode-select", f'#!/bin/sh\necho "$*" >> "{log}"\nexit 1\n')+ _exe(bin_dir / "xcode-select", f'#!/bin/sh\necho "xcode-select $*" >> "{calls}"\nexit 1\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')+ if brew:+ # Homebrew's bin precedes /usr/bin on PATH, as on a real Mac.+ _exe(bin_dir / "brew", f'#!/bin/sh\necho "brew $*" >> "{calls}"\n'+ f"printf '#!/bin/sh\\necho git version 2.51.0\\n' > \"{brew_bin}/git\"\n"+ f'chmod +x "{brew_bin}/git"\n')probe = ('source "$1" --manifest\n'- "NON_INTERACTIVE=true\n"+ f"NON_INTERACTIVE={'false' if interactive else 'true'}\n"+ f"has_terminal() {{ {'return 0' if interactive else 'return 1'}; }}\n""uv_bootstrap_target() { echo darwin-arm64; }\n""stage_prerequisites\n")- env = dict(os.environ, PATH=f"{bin_dir}{os.pathsep}{os.environ['PATH']}", HOME=str(tmp_path))+ path = os.pathsep.join([str(brew_bin), str(bin_dir), os.environ["PATH"]])+ env = dict(os.environ, PATH=path, HOME=str(tmp_path))result = subprocess.run(["bash", "-c", probe, "probe", str(_SCRIPT)],- env=env, capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=60, check=False,+ env=env, capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=120, check=False,)- return result, (log.read_text() if log.is_file() else "")+ return result, (calls.read_text().splitlines() if calls.is_file() else [])@pytest.mark.platforms("posix")-def test_macos_git_stub_fails_prerequisites_with_clt_remedy(tmp_path):- result, xcode_calls = _run_prerequisites(tmp_path, git_works=False, system="Darwin")+def test_macos_stub_waits_for_clt_dialog_then_continues(tmp_path):+ result, calls = _run_prerequisites(tmp_path, system="Darwin", interactive=True)++ assert result.returncode == 0, result.stderr+ assert "click Install" in result.stdout+ assert "prerequisites ok" in result.stdout+ assert calls == ["xcode-select --install", "sleep 5"]++[email protected]("posix")+def test_macos_stub_prefers_homebrew_without_dialog(tmp_path):+ result, calls = _run_prerequisites(tmp_path, system="Darwin", interactive=True, brew=True)++ assert result.returncode == 0, result.stderr+ assert "prerequisites ok" in result.stdout+ assert calls == ["brew install git"]++[email protected]("posix")+def test_macos_stub_non_interactive_fails_fast_with_remedy(tmp_path):+ result, calls = _run_prerequisites(tmp_path, system="Darwin", interactive=False)assert result.returncode != 0assert "xcode-select --install" in result.stderr- assert "invalid active developer path" in result.stderrassert "prerequisites ok" not in result.stdout- assert xcode_calls.split() == ["--install"]+ assert calls == ["xcode-select --install"]++[email protected]("posix")+def test_macos_stub_wait_gives_up_after_fifteen_minutes(tmp_path):+ result, calls = _run_prerequisites(tmp_path, system="Darwin", interactive=True, clt_finishes=False)++ assert result.returncode != 0+ assert "did not finish within 15 minutes" in result.stderr+ assert calls.count("sleep 5") == 180+ assert "Still waiting for the Command Line Tools install (15m)" in result.stdout@pytest.mark.platforms("posix")def test_broken_git_elsewhere_names_git_error_without_xcode(tmp_path):- result, xcode_calls = _run_prerequisites(tmp_path, git_works=False, system="Linux")+ result, calls = _run_prerequisites(tmp_path, system="Linux")assert result.returncode != 0assert "git is installed but cannot run" in result.stderr- assert "xcode-select" not in result.stderr- assert xcode_calls == ""+ assert "invalid active developer path" in result.stderr+ assert calls == []@pytest.mark.platforms("posix")def test_working_git_passes_prerequisites(tmp_path):- result, xcode_calls = _run_prerequisites(tmp_path, git_works=True, system="Darwin")+ result, calls = _run_prerequisites(tmp_path, system="Darwin", git="working")assert result.returncode == 0, result.stderrassert "prerequisites ok" in result.stdout- assert xcode_calls == ""+ assert calls == []