The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): git failures name git's own error, so Hermes-Setup's screen shows the cause
Teknium3c758ec96787
diff --git a/scripts/install.ps1 b/scripts/install.ps1index 49cd1a61a8d..4a538d73280 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -664,6 +664,27 @@ function Write-StatusLine([string]$Text, [int]$Width) {Write-Host ("`r" + $line.PadRight($Width - 1)) -NoNewline -ForegroundColor DarkGray}+# The error line of a failed command's output: the first fatal:/error: line (git's+# cause; later ones are generic), else the last non-empty one. Fail reasons carry it, and Hermes-Setup shows the reason+# as-is, so the screen names the cause (git's "fatal: ...") and not just the step.+$script:NativeError = $null+function Select-ErrorLine($Lines) {+ $pick = $null; $last = $null+ foreach ($raw in $Lines) {+ $line = ("$raw" -split "`r")[-1].Trim()+ if (-not $line) { continue }+ $last = $line+ if (-not $pick -and $line -match '(^|\s)(fatal|error): ') { $pick = $line }+ }+ if (-not $pick) { $pick = $last }+ if ($pick -and $pick.Length -gt 240) { $pick = $pick.Substring(0, 240) }+ return $pick+}+function Get-NativeDetail {+ if ($script:NativeError) { return ": $($script:NativeError)" }+ return ""+}+# Run a native command block like Invoke-Native: $LASTEXITCODE stays the# caller's to judge. Quiet mode shows $StatusLabel with the block's newest# output line rewritten in place, appends everything to the install log and,@@ -674,6 +695,7 @@ function Write-StatusLine([string]$Text, [int]$Width) {# function's scope, so locals here avoid the names call sites use.function Invoke-Logged {param([string]$StatusLabel, [scriptblock]$NativeBlock, [switch]$MayFail)+ $script:NativeError = $null$logWriter = $nullif (Test-QuietOutput) {$logPath = Join-Path (Join-Path $HermesHome 'logs') 'install.log'@@ -687,7 +709,17 @@ function Invoke-Logged {}if (-not $logWriter) {Log $StatusLabel- Invoke-Native $NativeBlock | Out-Host+ # stderr stays on stderr (Hermes-Setup logs it); the lines are kept so a+ # failure reason can name the cause.+ $outputLines = New-Object 'System.Collections.Generic.List[string]'+ Invoke-Native { & $NativeBlock 2>&1 } | ForEach-Object {+ $outputLines.Add("$_")+ if ($_ -is [System.Management.Automation.ErrorRecord]) { [Console]::Error.WriteLine("$_") }+ else { $_ | Out-Host }+ }+ $exitCode = $LASTEXITCODE+ if ($exitCode) { $script:NativeError = Select-ErrorLine $outputLines }+ $global:LASTEXITCODE = $exitCodereturn}$columns = 80@@ -706,6 +738,7 @@ function Invoke-Logged {if ($newest) { Write-StatusLine "${StatusLabel}: $newest" $columns }}$exitCode = $LASTEXITCODE+ if ($exitCode) { $script:NativeError = Select-ErrorLine $recentLines }} finally {$logWriter.Dispose()Write-Host ("`r" + (' ' * ($columns - 1)) + "`r") -NoNewline@@ -872,7 +905,7 @@ function Stage-Repository {}}Invoke-Logged "Fetching origin/$Branch" { git -C $InstallDir fetch origin "+refs/heads/${Branch}:refs/remotes/origin/${Branch}" }- if ($LASTEXITCODE) { Fail "git fetch failed" git_fetch_failed }+ if ($LASTEXITCODE) { Fail "git fetch failed$(Get-NativeDetail)" git_fetch_failed }$stamp = (Get-Date -Format 'yyyyMMdd-HHmmss')# Park local work BEFORE switching branches: checkout refuses a dirty# tree that conflicts, and the reset below would discard it. Work that@@ -899,7 +932,7 @@ function Stage-Repository {} else {Invoke-Logged "Checking out $Branch" { git -C $InstallDir checkout $Branch }}- if ($LASTEXITCODE) { Fail "git checkout failed" git_checkout_failed }+ if ($LASTEXITCODE) { Fail "git checkout failed$(Get-NativeDetail)" git_checkout_failed }# --no-stat: across a large gap (v2026.7.1 -> today is ~27k lines) the# diffstat arrives as one burst. Hermes-Setup.exe forwards every line# to its window as a separate event; the burst overflows the Windows@@ -929,7 +962,7 @@ function Stage-Repository {Log "List them with: git -C `"$InstallDir`" log origin/$Branch..$rescue"}Invoke-Logged "Resetting to origin/$Branch" { git -C $InstallDir reset --hard "origin/$Branch" }- if ($LASTEXITCODE) { Fail "git reset failed" git_reset_failed }+ if ($LASTEXITCODE) { Fail "git reset failed$(Get-NativeDetail)" git_reset_failed }Write-Warn "not fast-forwardable; reset to origin/$Branch"}} else {@@ -977,7 +1010,7 @@ function Stage-Repository {Invoke-Logged "Cloning history" { git clone @progress --filter=blob:none --no-checkout --branch $Branch $RepoUrl $tree }if (-not $LASTEXITCODE) { $cloned = $true; $deferred = $true }}- if (-not $cloned) { Fail "git clone failed; no checkout published" git_clone_failed }+ if (-not $cloned) { Fail "git clone failed; no checkout published$(Get-NativeDetail)" git_clone_failed }if ($Commit) {# Pin before publishing: a pinned or deferred clone has no files yet,# and a failure here leaves only the staging dir, which finally removes.@@ -998,7 +1031,7 @@ function Stage-Repository {}if (-not $materialized) {$what = if ($Commit) { $Commit } else { "the cloned tree" }- Fail "could not check out $what; no checkout published" git_checkout_failed+ Fail "could not check out $what; no checkout published$(Get-NativeDetail)" git_checkout_failed}$pinned = [bool]$Commit}@@ -1017,7 +1050,7 @@ function Stage-Repository {Invoke-Native { git -C $InstallDir merge-base --is-ancestor $Commit "origin/$Branch" 2>$null }if ($LASTEXITCODE) { Fail "commit $Commit is not on branch $Branch" commit_not_on_branch }Invoke-Logged "Pinning $Commit" { git -C $InstallDir checkout $Commit }- if ($LASTEXITCODE) { Fail "could not pin commit $Commit" git_checkout_failed }+ if ($LASTEXITCODE) { Fail "could not pin commit $Commit$(Get-NativeDetail)" git_checkout_failed }}}diff --git a/scripts/install.sh b/scripts/install.shindex 055c725f114..4cd78a12a7a 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -103,6 +103,23 @@ log_warn() { printf '%s⚠%s %s\n' "$C_YELLOW" "$C_NC" "$1"; }log_error() { printf '%s✗%s %s\n' "$C_RED" "$C_NC" "$1" >&2; }# $2: closed failure class for the local install receipt (write_install_receipt).fail() { STAGE_REASON="$1"; FAILURE_CLASS="${2:-other}"; log_error "$1"; exit 1; }+# The last failed run_logged command's own error line (git's "fatal: ..."), so a+# failure reason -- which Hermes-Setup shows as-is -- names the cause, not just the step.+RUN_LOGGED_ERROR=""+native_detail() { [ -z "$RUN_LOGGED_ERROR" ] || printf ': %s' "$RUN_LOGGED_ERROR"; }+# Pick the error line from a command's output on stdin: the first fatal:/error:+# line (git's cause; later ones are generic), else the last non-empty one.+error_line() {+ local line pick="" last=""+ while IFS= read -r line || [ -n "$line" ]; do+ line="${line%$'\r'}"; line="${line##*$'\r'}"+ [ -n "${line//[[:space:]]/}" ] || continue+ last="$line"+ [ -n "$pick" ] || case "$line" in fatal:*|error:*|*" fatal: "*|*" error: "*) pick="$line" ;; esac+ done+ pick="${pick:-$last}"+ printf '%s' "${pick:0:240}"+}# One local receipt per full-ladder run, under the profile's shared-metrics dir.# Only closed tokens and two timestamps (never STAGE_REASON, paths or URLs); the@@ -196,10 +213,17 @@ run_logged() {local may_fail=falseif [ "$1" = --may-fail ]; then may_fail=true; shift; filocal label="$1"; shift+ RUN_LOGGED_ERROR=""if ! quiet_output || ! { mkdir -p "${INSTALL_LOG%/*}" && : >> "$INSTALL_LOG"; } 2>/dev/null; thenlog "$label"- "$@"- return+ local err rc+ err="$(mktemp 2>/dev/null)" || { "$@"; return; }+ # stderr still streams (Hermes-Setup logs it); a copy names the failure.+ { "$@" 2>&1 1>&3 | tee "$err" >&2; } 3>&1+ rc=${PIPESTATUS[0]}+ [ "$rc" -eq 0 ] || RUN_LOGGED_ERROR="$(error_line < "$err")"+ rm -f "$err"+ return "$rc"filocal start cols rc line shownstart=$(( $(wc -l < "$INSTALL_LOG") + 1 ))@@ -220,6 +244,7 @@ run_logged() {} 3>>"$INSTALL_LOG"rc=${PIPESTATUS[0]}printf '\r\033[K'+ [ "$rc" -eq 0 ] || RUN_LOGGED_ERROR="$(tail -n +"$(( start + 1 ))" "$INSTALL_LOG" | error_line)"if [ "$rc" -ne 0 ] && [ "$may_fail" = false ]; thenlog_error "$label failed (exit $rc). Last output:"tail -n +"$(( start + 1 ))" "$INSTALL_LOG" | tail -n 20 | sed 's/^/ /' >&2@@ -577,7 +602,7 @@ stage_repository() {fifirun_logged "Fetching origin/$BRANCH" git -C "$INSTALL_DIR" fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" \- || fail "git fetch failed" git_fetch_failed+ || fail "git fetch failed$(native_detail)" git_fetch_failedlocal stampstamp="$(date -u +%Y%m%d-%H%M%S)"# Park local work BEFORE switching branches: checkout refuses a dirty@@ -601,10 +626,10 @@ stage_repository() {# narrow checkout (detached at its tag, no local branch) gets the branch# created at the fetched tip.if git -C "$INSTALL_DIR" show-ref --verify --quiet "refs/heads/$BRANCH"; then- run_logged "Checking out $BRANCH" git -C "$INSTALL_DIR" checkout "$BRANCH" || fail "git checkout failed" git_checkout_failed+ run_logged "Checking out $BRANCH" git -C "$INSTALL_DIR" checkout "$BRANCH" || fail "git checkout failed$(native_detail)" git_checkout_failedelserun_logged "Checking out $BRANCH" git -C "$INSTALL_DIR" checkout -b "$BRANCH" "origin/$BRANCH" \- || fail "git checkout failed" git_checkout_failed+ || fail "git checkout failed$(native_detail)" git_checkout_failedfiif ! run_logged --may-fail "Fast-forwarding to origin/$BRANCH" \git -C "$INSTALL_DIR" merge --ff-only "origin/$BRANCH"; then@@ -631,7 +656,7 @@ stage_repository() {log "List them with: git -C \"$INSTALL_DIR\" log origin/$BRANCH..$rescue_ref"firun_logged "Resetting to origin/$BRANCH" git -C "$INSTALL_DIR" reset --hard "origin/$BRANCH" \- || fail "git reset failed" git_reset_failed+ || fail "git reset failed$(native_detail)" git_reset_failedlog_warn "not fast-forwardable; reset to origin/$BRANCH"fielse@@ -680,7 +705,7 @@ stage_repository() {fiif [ "$cloned" = false ]; thenrm -rf "$staged"- fail "git clone failed; no checkout published" git_clone_failed+ fail "git clone failed; no checkout published$(native_detail)" git_clone_failedfiif [ -n "$INSTALL_COMMIT" ]; then# Pin before publishing: a pinned or deferred clone has no files yet,@@ -704,7 +729,7 @@ stage_repository() {doneif [ "$cloned" = false ]; thenrm -rf "$staged"- fail "could not check out ${INSTALL_COMMIT:-the cloned tree}; no checkout published" git_checkout_failed+ fail "could not check out ${INSTALL_COMMIT:-the cloned tree}; no checkout published$(native_detail)" git_checkout_failedfifiif ! mv "$staged/tree" "$INSTALL_DIR"; then@@ -732,7 +757,7 @@ stage_repository() {git -C "$INSTALL_DIR" merge-base --is-ancestor "$INSTALL_COMMIT" "origin/$BRANCH" 2>/dev/null \|| fail "commit $INSTALL_COMMIT is not on branch $BRANCH" commit_not_on_branchrun_logged "Pinning $INSTALL_COMMIT" git -C "$INSTALL_DIR" checkout "$INSTALL_COMMIT" \- || fail "could not pin commit $INSTALL_COMMIT" git_checkout_failed+ || fail "could not pin commit $INSTALL_COMMIT$(native_detail)" git_checkout_failedfi}diff --git a/tests/scripts/install/test_install_clone_throttle_fallback.py b/tests/scripts/install/test_install_clone_throttle_fallback.pyindex c044d67274b..5baa5ef2894 100644--- a/tests/scripts/install/test_install_clone_throttle_fallback.py+++ b/tests/scripts/install/test_install_clone_throttle_fallback.py@@ -60,7 +60,7 @@ def _run_repository_stage(installer: str, tmp_path: Path, install: Path, origin_env = dict(os.environ, HOME=tmp_path.as_posix(), HERMES_HOME=(tmp_path / "home").as_posix(),HERMES_INSTALL_DIR=install.as_posix(), HERMES_REPO_URL=origin_url)if installer == "sh":- script = f"source {shlex.quote((ROOT / 'scripts/install.sh').as_posix())} --manifest\nstage_repository\n"+ script = f"source {shlex.quote((ROOT / 'scripts/install.sh').as_posix())} --manifest\nsleep() {{ :; }}\nstage_repository\n"return subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60, check=False)if os.name != "nt":# pwsh on POSIX cannot run the Windows-only pinned Git: seed its PM store slot with host git.@@ -115,3 +115,18 @@ def test_existing_treeless_checkout_is_refetched_before_update(tmp_path, installassert git(install, "config", "--get", "remote.origin.partialclonefilter").stdout.strip() == "blob:none"assert git(install, "rev-parse", "HEAD").stdout.strip() == head, "the checkout was re-cloned, not converted"git(install, "rev-list", "HEAD", "--", "history.txt", GIT_NO_LAZY_FETCH="1") # history answers offline++[email protected]_system_guard_bypass[email protected]("installer", [+ "sh",+ pytest.param("ps1", marks=pytest.mark.skipif(POWERSHELL is None, reason="needs PowerShell")),+])+def test_clone_failure_reason_carries_gits_own_error(tmp_path, installer):+ """Hermes-Setup shows the stage reason as-is: it must name git's cause, not only the step."""+ missing = tmp_path / "no-such-repo.git"+ result = _run_repository_stage(installer, tmp_path, tmp_path / "install", missing.as_uri())+ output = result.stdout + result.stderr+ assert result.returncode != 0+ assert "git clone failed; no checkout published: fatal:" in output, output+ assert "no-such-repo.git" in output.split("no checkout published: fatal:", 1)[1].splitlines()[0]