From 55c42be13c63e435c641b0e54dafd641bd0ccb87 Mon Sep 17 00:00:00 2001 From: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:37:30 +0900 Subject: [PATCH] fix: address release-review findings in herdr-t3 staging and Windows PATH/Rex scripts (#236) - herdr-t3 install/verify: restrict auto tag selection to stable vX.Y.Z tags so prereleases cannot win or break the version sort; verify the git checkout exit code before building - herdr-t3 install.sh/rollback.sh: stage the .app beside the destination and swap only after the copy verifies, so a failed ditto never leaves ~/Applications without the app - herdr-t3 verify.ps1: probe the herdr named pipe with a real NamedPipeClientPipe connect instead of Directory.Exists - user-path.ps1: handle a missing HKCU Path value without GetValueKind throwing, and store the mise shims entry pre-expanded when User PATH is REG_SZ - install-rex.ps1: drop the PS7-only ?? operator for 5.1 compatibility and stop a running rex.exe before replacing its install root Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- components/herdr-t3/install.ps1 | 7 +++++-- components/herdr-t3/install.sh | 17 ++++++++++++----- components/herdr-t3/rollback.sh | 10 ++++++++-- components/herdr-t3/verify.ps1 | 14 +++++++++++--- platforms/windows-11/install-rex.ps1 | 9 ++++++++- platforms/windows-11/user-path.ps1 | 17 ++++++++++++++--- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/components/herdr-t3/install.ps1 b/components/herdr-t3/install.ps1 index b010d32..a9a666a 100644 --- a/components/herdr-t3/install.ps1 +++ b/components/herdr-t3/install.ps1 @@ -21,10 +21,12 @@ function Log($msg) { Write-Host "[herdr-t3] $msg" } function Die($msg) { Write-Host "[herdr-t3] ERROR: $msg" -ForegroundColor Red; exit 1 } if (-not $Ref) { + # Stable release tags only: a prerelease tag like v1.1.0-rc.1 would fail + # the [version] cast below and must never win auto-selection. $tags = git ls-remote --tags $RepoUrl "refs/tags/v*" | - ForEach-Object { ($_ -split "/")[-1] } | Where-Object { $_ -notmatch '\^' } + ForEach-Object { ($_ -split "/")[-1] } | Where-Object { $_ -match '^v\d+\.\d+\.\d+$' } $Ref = $tags | Sort-Object { [version]($_.TrimStart('v')) } | Select-Object -Last 1 - if (-not $Ref) { Die "no v* tag found on $RepoUrl" } + if (-not $Ref) { Die "no stable v* tag found on $RepoUrl" } } if ($Ref -match '^v[0-9]') { git ls-remote --exit-code --tags $RepoUrl "refs/tags/$Ref" | Out-Null @@ -43,6 +45,7 @@ if (-not (Test-Path (Join-Path $target ".git"))) { git -C $target fetch --quiet --tags origin } git -C $target checkout --quiet $Ref +if ($LASTEXITCODE -ne 0) { Die "git checkout $Ref failed in $target" } $commit = (git -C $target rev-parse HEAD).Trim() Log "building $name ($commit)" diff --git a/components/herdr-t3/install.sh b/components/herdr-t3/install.sh index 5b9a695..690ef7d 100755 --- a/components/herdr-t3/install.sh +++ b/components/herdr-t3/install.sh @@ -34,9 +34,11 @@ bundle_id_of() { # $1 = .app path -> prints CFBundleIdentifier or nothing resolve_ref() { local ref="${1:-}" if [[ -z "$ref" ]]; then + # Stable release tags only: sort -V would let a prerelease tag like + # v1.1.0-rc.1 win auto-selection. ref="$(git ls-remote --tags "$REPO_URL" 'refs/tags/v*' \ - | awk -F/ '{print $3}' | grep -v '\^' | sort -V | tail -1)" - [[ -n "$ref" ]] || die "no v* tag found on $REPO_URL" + | awk -F/ '{print $3}' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)" + [[ -n "$ref" ]] || die "no stable v* tag found on $REPO_URL" fi if [[ "$ref" =~ ^v[0-9] ]]; then git ls-remote --exit-code --tags "$REPO_URL" "refs/tags/$ref" >/dev/null \ @@ -76,10 +78,15 @@ stage_app() { # $1 = source .app, $2 = destination .app pgrep -f "$dst/Contents/MacOS/herdr-t3" >/dev/null 2>&1 \ && die "herdr-t3 is still running; quit it and retry" fi - rm -rf "$dst" fi - ditto "$src" "$dst" - [[ -x "$dst/Contents/MacOS/herdr-t3" ]] || die "staged app has no executable: $dst" + # Stage beside the destination and swap only after the copy verifies, so a + # failed ditto never leaves ~/Applications without the app. + local staging="$dst.staging-$$" + rm -rf "$staging" + ditto "$src" "$staging" || { rm -rf "$staging"; die "ditto failed staging $src"; } + [[ -x "$staging/Contents/MacOS/herdr-t3" ]] || { rm -rf "$staging"; die "staged app has no executable: $staging"; } + rm -rf "$dst" + mv "$staging" "$dst" # Register with Launch Services so Finder/Spotlight/`open -a` resolve it, # and unregister the build artifact so it can never win resolution. [[ -x "$LSREGISTER" ]] && "$LSREGISTER" -f "$dst" >/dev/null 2>&1 || true diff --git a/components/herdr-t3/rollback.sh b/components/herdr-t3/rollback.sh index a4d20b4..40e9d31 100755 --- a/components/herdr-t3/rollback.sh +++ b/components/herdr-t3/rollback.sh @@ -41,9 +41,15 @@ if [[ -e "$dst" ]]; then fi pgrep -f "$dst/Contents/MacOS/herdr-t3" >/dev/null 2>&1 && die "herdr-t3 still running; quit and retry" fi - rm -rf "$dst" fi -ditto "$built" "$dst" +# Stage beside the destination and swap only after the copy verifies, so a +# failed ditto never leaves ~/Applications without the app. +staging="$dst.staging-$$" +rm -rf "$staging" +ditto "$built" "$staging" || { rm -rf "$staging"; die "ditto failed staging $built"; } +[[ -x "$staging/Contents/MacOS/herdr-t3" ]] || { rm -rf "$staging"; die "staged app has no executable: $staging"; } +rm -rf "$dst" +mv "$staging" "$dst" [[ -x "$LSREGISTER" ]] && "$LSREGISTER" -f "$dst" >/dev/null 2>&1 || true [[ -x "$LSREGISTER" ]] && "$LSREGISTER" -u "$built" >/dev/null 2>&1 || true diff --git a/components/herdr-t3/verify.ps1 b/components/herdr-t3/verify.ps1 index 176146a..5fe839b 100644 --- a/components/herdr-t3/verify.ps1 +++ b/components/herdr-t3/verify.ps1 @@ -31,9 +31,17 @@ Write-Host "[herdr-t3] start menu: $lnk" if ($Live) { if (-not (Get-Process -Name "herdr-t3" -ErrorAction SilentlyContinue)) { Fail "app is not running (run launch.ps1)" } $sock = if ($env:HERDR_SOCKET) { $env:HERDR_SOCKET } else { Join-Path $env:APPDATA "herdr\herdr.sock" } - $pipe = "\\.\pipe\$sock" - if (-not (Test-Path $sock) -and -not [System.IO.Directory]::Exists($pipe)) { - Fail "herdr endpoint not found: $sock / $pipe (is herdr running?)" + # Windows herdr endpoints are named pipes; Directory.Exists cannot see + # them, so probe the pipe with a short connect instead. + $pipeName = [System.IO.Path]::GetFileName($sock) + $pipeUp = $false + try { + $pipeClient = New-Object System.IO.Pipes.NamedPipeClientPipe('.', $pipeName, [System.IO.Pipes.PipeDirection]::InOut) + try { $pipeClient.Connect(1500); $pipeUp = $true } catch { } + finally { $pipeClient.Dispose() } + } catch { } + if (-not (Test-Path $sock) -and -not $pipeUp) { + Fail "herdr endpoint not found: $sock / \\.\pipe\$pipeName (is herdr running?)" } Write-Host "[herdr-t3] live: app running, herdr endpoint present: $sock" } diff --git a/platforms/windows-11/install-rex.ps1 b/platforms/windows-11/install-rex.ps1 index d56d939..b9341c5 100644 --- a/platforms/windows-11/install-rex.ps1 +++ b/platforms/windows-11/install-rex.ps1 @@ -76,6 +76,11 @@ else { Expand-Archive -LiteralPath $zipPath -DestinationPath $extractDir -Force if (Test-Path -LiteralPath $InstallRoot) { + # A running rex.exe locks its directory; stop it first so the + # replace cannot fail halfway and leave a mixed install. + Get-Process -Name 'rex' -ErrorAction SilentlyContinue | + Where-Object { $_.Path -and $_.Path.StartsWith($InstallRoot, [StringComparison]::OrdinalIgnoreCase) } | + Stop-Process -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $InstallRoot -Recurse -Force } New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null @@ -87,7 +92,9 @@ else { } $newVersion = Get-RexVersion -RexExe $existingExe - Write-Host "ok Rex $($newVersion ?? $release.version) installed -> $existingExe" + $reportedVersion = $newVersion + if (-not $reportedVersion) { $reportedVersion = $release.version } + Write-Host "ok Rex $reportedVersion installed -> $existingExe" } finally { Remove-Item -LiteralPath $tempDir -Recurse -Force -ErrorAction SilentlyContinue diff --git a/platforms/windows-11/user-path.ps1 b/platforms/windows-11/user-path.ps1 index c098d9a..68a949f 100644 --- a/platforms/windows-11/user-path.ps1 +++ b/platforms/windows-11/user-path.ps1 @@ -74,11 +74,14 @@ if (-not $StateDir) { function Get-UserPathRaw { $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $false) try { + if ($key.GetValueNames() -notcontains 'Path') { + # PATH normally exists as REG_EXPAND_SZ; a missing value is + # written back expandable. + return [pscustomobject]@{ Value = ''; Kind = [Microsoft.Win32.RegistryValueKind]::ExpandString } + } $value = $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) $kind = $key.GetValueKind('Path') if ($kind -eq [Microsoft.Win32.RegistryValueKind]::Unknown) { - # PATH normally exists as REG_EXPAND_SZ; a missing value kind means - # the value itself is absent, so write it back expandable. $kind = [Microsoft.Win32.RegistryValueKind]::ExpandString } } @@ -136,7 +139,15 @@ if (-not $Apply) { } $kept = @($entries | Where-Object { -not (Test-LegacyCargoEntry -Entry $_) }) -if (-not $shimPresent) { $kept += $miseShimEntry } +if (-not $shimPresent) { + # A REG_SZ User PATH is never environment-expanded at runtime, so the + # shim entry must be stored pre-expanded there; REG_EXPAND_SZ keeps the + # portable %LOCALAPPDATA% form. + $shimEntry = if ($current.Kind -eq [Microsoft.Win32.RegistryValueKind]::String) { + [Environment]::ExpandEnvironmentVariables($miseShimEntry) + } else { $miseShimEntry } + $kept += $shimEntry +} $newValue = ($kept -join ';') if ($newValue -eq $current.Value) {