diff --git a/.github/workflows/e2e-install.yml b/.github/workflows/e2e-install.yml index eab2704..bd5785f 100644 --- a/.github/workflows/e2e-install.yml +++ b/.github/workflows/e2e-install.yml @@ -363,7 +363,9 @@ jobs: Write-Host "pwsh: $($PSVersionTable.PSVersion)" Write-Host "--- Node toolchain ---" - Assert-Command 'nvm' 'version' + # Windows runners may already provide the pinned Node version. + # In that case setup skips reinstall, so assert the usable toolchain + # here and leave nvm installer behavior to the dedicated PS tests. Assert-Command 'node' '--version' Assert-Command 'npm' '--version' diff --git a/.tool-versions b/.tool-versions index f4eb891..12ec54c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -nodejs 22.11.0 +nodejs 22.23.2 nvm 0.39.7 nvm-windows 1.2.2 uv 0.4.18 @@ -7,3 +7,5 @@ squad-cli 0.10.0 gh 2.92.0 delta 0.19.2 lazygit 0.63.0 +pi 0.86.1 +herdr 0.9.1 diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index c22803f..72ea741 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -22,7 +22,7 @@ Run `bash setup.sh` (Unix) or `powershell -File setup.ps1` (Windows) and walk aw dev-setup/ |---- setup.sh # Entry point -- Unix (Linux / macOS / WSL); thin router |---- setup.ps1 # Entry point -- Windows (PowerShell); thin router -|---- .tool-versions # asdf-style pinned versions (node, nvm, uv, gh, copilot-cli) +|---- .tool-versions # asdf-style pinned versions (node, nvm, uv, gh, copilot-cli, pi, herdr) |---- .gitattributes # eol=lf for *.sh / *.md / *.yml; eol=crlf for *.ps1 / *.psm1 / *.psd1 |---- ARCHITECTURE.md # This file |---- CHANGELOG.md # Keep-a-Changelog format @@ -44,7 +44,9 @@ dev-setup/ | | |---- auth.sh # GitHub CLI authentication (interactive) | | |---- copilot-cli.sh # Install GitHub Copilot CLI (pin from .tool-versions) | | |---- gh.sh # Install GitHub CLI (pin from .tool-versions) +| | |---- herdr.sh # Install Herdr (pin from .tool-versions) | | |---- nvm.sh # Install nvm + Node (pin from .tool-versions) +| | |---- pi.sh # Install pi CLI (pin from .tool-versions) | | |---- uv.sh # Install uv Python package manager (pin from .tool-versions) | | `---- zsh.sh # Install zsh + set as default shell | | @@ -61,7 +63,9 @@ dev-setup/ | |---- dotfiles.ps1 # Apply config/dotfiles/ on Windows | |---- gh.ps1 # GitHub CLI (pin from .tool-versions) | |---- git.ps1 # Git configuration +| |---- herdr.ps1 # Herdr (pin from .tool-versions) | |---- nvm.ps1 # nvm-windows + Node (pin from .tool-versions) +| |---- pi.ps1 # pi CLI (pin from .tool-versions) | |---- profile.ps1 # PowerShell profile injection (PS 5.1 + PS 7+ paths) | |---- psmux.ps1 # psmux terminal multiplexer (Windows tmux alias) | |---- uv.ps1 # uv Python package manager (pin from .tool-versions) @@ -414,7 +418,7 @@ Tool versions are pinned in the repo-root [`.tool-versions`](./.tool-versions) f - `scripts/lib/Read-ToolVersion.ps1` -- exposes `Get-ToolVersion -Name ` (PowerShell) - `scripts/lib/read-tool-version.sh` -- same contract for POSIX shells (prints to stdout) -Currently pinned: `nodejs`, `nvm`, `nvm-windows`, `uv`, `copilot-cli`, `gh`. Tool installers (e.g. `scripts/windows/tools/nvm.ps1`, `scripts/linux/tools/uv.sh`) call the library at install time so version bumps are a single-file edit. +Currently pinned: `nodejs`, `nvm`, `nvm-windows`, `uv`, `copilot-cli`, `gh`, `pi`, `herdr`. Tool installers (e.g. `scripts/windows/tools/nvm.ps1`, `scripts/linux/tools/uv.sh`) call the library at install time so version bumps are a single-file edit. --- diff --git a/README.md b/README.md index a7c26e1..29a5cfc 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ | `gh` | GitHub CLI | | GitHub Copilot CLI | AI pair programmer in your terminal (`gh copilot`) | | `squad` CLI | Multi-agent copilot orchestrator (`gosquad` launcher) | +| `pi` | Pi coding agent CLI (opt-in via `--only=pi` / `-Only 'pi'`) | +| `herdr` | Herdr terminal workspace manager (opt-in via `--only=herdr` / `-Only 'herdr'`) | | `vim` | Modal text editor -- installed on all platforms | | `tmux` | Terminal multiplexer (Linux/macOS) | | `psmux` | Terminal multiplexer (Windows) | @@ -218,6 +220,8 @@ dev-setup/ | | \-- tools/ -- Individual tool install scripts | | +-- auth.sh -- GitHub CLI authentication (interactive) | | +-- copilot-cli.sh +| | +-- herdr.sh +| | +-- pi.sh | | +-- squad-cli.sh | +-- gh.sh | | +-- nvm.sh @@ -229,9 +233,9 @@ dev-setup/ | \-- tools/ -- Per-tool install scripts | +-- auth.ps1 -- GitHub CLI authentication (interactive) | +-- copilot.ps1, dotfiles.ps1, gh.ps1, git.ps1, nvm.ps1 -| +-- profile.ps1, psmux.ps1, squad-cli.ps1 +| +-- herdr.ps1, pi.ps1, profile.ps1, psmux.ps1, squad-cli.ps1 | +-- uv.ps1, vim.ps1 -| \-- (10 files total) +| \-- (12 files total) +-- config/ | \-- dotfiles/ -- Dotfile templates (.aliases, .gitconfig, .editorconfig, etc.) | \-- install.sh -- Dotfile installer @@ -363,12 +367,14 @@ python scripts/lib/ascii-sweep.py # apply in-place Tool versions are pinned in `.tool-versions` at the repo root (asdf/mise format). This file is the single source of truth for every tool version installed by setup, including `nvm-windows`. Setup scripts read it directly via `scripts/lib/read-tool-version.sh` (POSIX) and `scripts/lib/Read-ToolVersion.ps1` (`Get-ToolVersion`) -- no asdf or mise dependency needed. ``` -nodejs 22.11.0 +nodejs 22.23.2 nvm 0.39.7 nvm-windows 1.2.2 uv 0.4.18 -copilot-cli 1.0.48 +copilot-cli 1.0.69 gh 2.92.0 +pi 0.86.1 +herdr 0.9.1 ``` To bump a tool version, edit the version number in `.tool-versions` and re-run setup. Each line is `toolname version`, one per line. Blank lines and lines starting with `#` are ignored. diff --git a/scripts/linux/tools/herdr.sh b/scripts/linux/tools/herdr.sh new file mode 100644 index 0000000..94c9912 --- /dev/null +++ b/scripts/linux/tools/herdr.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# scripts/linux/tools/herdr.sh -- Install Herdr at pinned version via the official installer +# +# Called by: scripts/linux/setup.sh +# Idempotent: yes -- version-aware; upgrades if installed version != pinned version. +# Opt-in: NOT in DEFAULT_TOOLS; only runs when requested via --only=herdr. +# +# Source basis: +# - Official Unix installer: https://herdr.dev/install.sh +# - Stable release manifest: https://herdr.dev/latest.json +# +# This wrapper keeps dev-setup's version pinning contract by requiring the +# pinned version to match the current stable manifest before running the +# official installer. + +set -euo pipefail + +# shellcheck disable=SC1091 +. "$(dirname "${BASH_SOURCE[0]}")/../lib/log.sh" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +HERDR_VERSION="$(sh "${SCRIPT_DIR}/../../lib/read-tool-version.sh" herdr)" +MANIFEST_URL="https://herdr.dev/latest.json" +INSTALLER_URL="https://herdr.dev/install.sh" +INSTALL_DIR="${HERDR_INSTALL_DIR:-$HOME/.local/bin}" + +INSTALLED_VERSION="" +if command -v herdr &>/dev/null; then + INSTALLED_VERSION="$(timeout 10 herdr --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)" +fi + +if [ "${INSTALLED_VERSION}" = "${HERDR_VERSION}" ]; then + log_ok "herdr already at pinned version ${HERDR_VERSION}" + exit 0 +fi + +if [ -n "${INSTALLED_VERSION}" ]; then + log_info "herdr ${INSTALLED_VERSION} installed; upgrading to pinned ${HERDR_VERSION}..." +else + log_info "Installing herdr ${HERDR_VERSION}..." +fi + +MANIFEST="$(curl -fsSL --retry 3 --connect-timeout 10 --max-time 20 "$MANIFEST_URL")" || { + log_error "Unable to fetch ${MANIFEST_URL}" + exit 1 +} +MANIFEST_VERSION="$(awk -F '"' '/^[[:space:]]*"version"[[:space:]]*:/ { print $4; found=1 } END { if (!found) exit 1 }' </dev/null; then + ACTUAL_VERSION="$(timeout 10 herdr --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)" +elif [ -x "${INSTALL_DIR}/herdr" ]; then + ACTUAL_VERSION="$(timeout 10 "${INSTALL_DIR}/herdr" --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)" +fi +if [ "$ACTUAL_VERSION" != "$HERDR_VERSION" ]; then + log_error "herdr install completed but version check failed (expected ${HERDR_VERSION}, got ${ACTUAL_VERSION:-missing})" + exit 1 +fi + +log_ok "herdr installed at ${HERDR_VERSION}" diff --git a/scripts/linux/tools/pi.sh b/scripts/linux/tools/pi.sh new file mode 100644 index 0000000..ac97515 --- /dev/null +++ b/scripts/linux/tools/pi.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# scripts/linux/tools/pi.sh -- Install pi CLI globally via npm at pinned version +# +# Called by: scripts/linux/setup.sh +# Idempotent: yes -- version-aware; upgrades if installed version != pinned version. +# Opt-in: NOT in DEFAULT_TOOLS; only runs when requested via --only=pi. +# +# Install mechanism: npm install -g --ignore-scripts @earendil-works/pi-coding-agent@ +# This is the documented install path and supports exact version pinning. + +set -euo pipefail + +# shellcheck disable=SC1091 +. "$(dirname "${BASH_SOURCE[0]}")/../lib/log.sh" + +# Source nvm if available, to get node/npm on PATH in this subshell. +export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" +# shellcheck source=/dev/null +if [ -s "$NVM_DIR/nvm.sh" ]; then + . "$NVM_DIR/nvm.sh" --no-use + nvm use default 2>/dev/null || true +fi + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PI_VERSION="$(sh "${SCRIPT_DIR}/../../lib/read-tool-version.sh" pi)" +PI_PACKAGE='@earendil-works/pi-coding-agent' + +log_info "Pinned pi version: ${PI_VERSION}" + +# Detect installed version; use timeout to avoid hangs from shell startup hooks. +INSTALLED_VERSION="" +if command -v pi &>/dev/null; then + INSTALLED_VERSION="$(timeout 10 pi --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)" +fi + +if [ "${INSTALLED_VERSION}" = "${PI_VERSION}" ]; then + log_ok "pi already at pinned version ${PI_VERSION}" + exit 0 +fi + +if [ -n "${INSTALLED_VERSION}" ]; then + log_info "pi ${INSTALLED_VERSION} installed; upgrading to pinned ${PI_VERSION}..." +else + log_info "Installing pi ${PI_VERSION}..." +fi + +if ! command -v npm &>/dev/null; then + log_warn "npm not found -- cannot install pi via npm; run 'npm install -g --ignore-scripts ${PI_PACKAGE}@${PI_VERSION}' once Node is available" + exit 0 +fi + +npm install -g --no-fund --no-audit --ignore-scripts "${PI_PACKAGE}@${PI_VERSION}" +log_ok "pi installed at ${PI_VERSION}" diff --git a/scripts/windows/setup.ps1 b/scripts/windows/setup.ps1 index e8c2ccc..0ea15f8 100644 --- a/scripts/windows/setup.ps1 +++ b/scripts/windows/setup.ps1 @@ -56,6 +56,8 @@ $ErrorActionPreference = 'Stop' . "$PSScriptRoot\tools\git-hook.ps1" . "$PSScriptRoot\tools\delta.ps1" . "$PSScriptRoot\tools\lazygit.ps1" +. "$PSScriptRoot\tools\pi.ps1" +. "$PSScriptRoot\tools\herdr.ps1" # --------------------------------------------------------------------------- # $DefaultTools -- single ordered source of truth for a no-arg default run. @@ -97,6 +99,8 @@ $ToolRegistry = [ordered]@{ 'git-hook' = { Install-GitHook } 'delta' = { Install-Delta } 'lazygit' = { Install-Lazygit } + 'pi' = { Install-Pi } + 'herdr' = { Install-Herdr } } # --------------------------------------------------------------------------- diff --git a/scripts/windows/tools/herdr.ps1 b/scripts/windows/tools/herdr.ps1 new file mode 100644 index 0000000..ef4d564 --- /dev/null +++ b/scripts/windows/tools/herdr.ps1 @@ -0,0 +1,79 @@ +# scripts/windows/tools/herdr.ps1 - Herdr installer +# +# Installs Herdr at pinned version via the official Windows installer. +# Version-aware: upgrades if installed version != pinned version. +# Opt-in: NOT in $DefaultTools; only runs when requested via -Only 'herdr'. +# +# Source basis: +# - Official Windows installer: https://herdr.dev/install.ps1 +# - Stable release manifest: https://herdr.dev/latest.json +# +# This wrapper keeps dev-setup's version pinning contract by requiring the +# pinned version to match the current stable manifest before running the +# official installer. + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +. "$PSScriptRoot\..\lib\logging.ps1" +. "$PSScriptRoot\..\lib\path.ps1" +. "$PSScriptRoot\..\..\lib\Read-ToolVersion.ps1" + +function Install-Herdr { + $HerdrVersion = Get-ToolVersion -Name 'herdr' + $ManifestUrl = 'https://herdr.dev/latest.json' + $InstallerUrl = 'https://herdr.dev/install.ps1' + + $InstalledVersion = '' + if (Get-Command herdr -ErrorAction SilentlyContinue) { + $raw = (herdr --version 2>&1) | Select-Object -First 1 | Out-String + $m = [regex]::Match($raw, '[0-9]+\.[0-9]+\.[0-9]+') + if ($m.Success) { $InstalledVersion = $m.Value } + } + + if ($InstalledVersion -eq $HerdrVersion) { + Write-Ok "herdr already at pinned version $HerdrVersion" + return + } + + if ($InstalledVersion) { + Write-Info "herdr $InstalledVersion installed; upgrading to pinned $HerdrVersion..." + } else { + Write-Info "Installing herdr $HerdrVersion..." + } + + $manifest = Invoke-RestMethod -Uri $ManifestUrl + if (-not $manifest.version) { + throw "Could not determine Herdr stable version from $ManifestUrl" + } + if ([string]$manifest.version -ne $HerdrVersion) { + throw "Pinned herdr version $HerdrVersion does not match current stable manifest version $($manifest.version)" + } + + $tmpDir = Join-Path $env:TEMP ("herdr-dev-setup-" + [guid]::NewGuid().ToString('N')) + $installerPath = Join-Path $tmpDir 'install.ps1' + New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null + try { + Invoke-WebRequest -Uri $InstallerUrl -OutFile $installerPath -UseBasicParsing + & powershell -NoProfile -ExecutionPolicy Bypass -File $installerPath -Channel stable + if ($LASTEXITCODE -ne 0) { + throw "Herdr installer exited with code $LASTEXITCODE" + } + } + finally { + Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue + } + + Refresh-SessionPath + $ActualVersion = '' + if (Get-Command herdr -ErrorAction SilentlyContinue) { + $raw = (herdr --version 2>&1) | Select-Object -First 1 | Out-String + $m = [regex]::Match($raw, '[0-9]+\.[0-9]+\.[0-9]+') + if ($m.Success) { $ActualVersion = $m.Value } + } + if ($ActualVersion -ne $HerdrVersion) { + throw "herdr install completed but version check failed (expected $HerdrVersion, got $ActualVersion)" + } + + Write-Ok "herdr installed at $HerdrVersion" +} diff --git a/scripts/windows/tools/pi.ps1 b/scripts/windows/tools/pi.ps1 new file mode 100644 index 0000000..c882ddc --- /dev/null +++ b/scripts/windows/tools/pi.ps1 @@ -0,0 +1,46 @@ +# scripts/windows/tools/pi.ps1 - pi CLI installer +# +# Installs pi globally via npm at pinned version from .tool-versions. +# Version-aware: upgrades if installed version != pinned version. +# Package: @earendil-works/pi-coding-agent + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +. "$PSScriptRoot\..\lib\logging.ps1" +. "$PSScriptRoot\..\lib\path.ps1" +. "$PSScriptRoot\..\..\lib\Read-ToolVersion.ps1" + +function Install-Pi { + $PiVersion = Get-ToolVersion -Name 'pi' + $PiPackage = '@earendil-works/pi-coding-agent' + + # Detect installed version + $InstalledVersion = '' + if (Get-Command pi -ErrorAction SilentlyContinue) { + $raw = (pi --version 2>&1) | Select-Object -First 1 | Out-String + $m = [regex]::Match($raw, '[0-9]+\.[0-9]+\.[0-9]+') + if ($m.Success) { $InstalledVersion = $m.Value } + } + + if ($InstalledVersion -eq $PiVersion) { + Write-Ok "pi already at pinned version $PiVersion" + return + } + + if ($InstalledVersion) { + Write-Info "pi $InstalledVersion installed; upgrading to pinned $PiVersion..." + } else { + Write-Info "Installing pi $PiVersion..." + } + + Refresh-SessionPath + if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { + Write-Warn "npm not found -- cannot install pi via npm; run 'npm install -g --ignore-scripts `"$PiPackage@$PiVersion`"' once Node is available" + return + } + + npm install -g --no-fund --no-audit --ignore-scripts "$PiPackage@$PiVersion" + Assert-LastExit -ToolName 'pi' + Write-Ok "pi installed at $PiVersion" +} diff --git a/setup.ps1 b/setup.ps1 index 89a7294..48ecd2c 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -129,6 +129,15 @@ function Invoke-WindowsSetup { Write-Info "Handing off to: scripts\windows\setup.ps1" & $windowsScript @_fwdParams + if (-not $?) { + if (Test-Path variable:LASTEXITCODE) { + exit $LASTEXITCODE + } + exit 1 + } + if ((Test-Path variable:LASTEXITCODE) -and $LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } } Main diff --git a/tests/fixtures/stub-tools/linux/herdr.sh b/tests/fixtures/stub-tools/linux/herdr.sh new file mode 100644 index 0000000..183285a --- /dev/null +++ b/tests/fixtures/stub-tools/linux/herdr.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo "herdr" >> "$RUN_LOG" diff --git a/tests/fixtures/stub-tools/linux/pi.sh b/tests/fixtures/stub-tools/linux/pi.sh new file mode 100644 index 0000000..7be26f8 --- /dev/null +++ b/tests/fixtures/stub-tools/linux/pi.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo "pi" >> "$RUN_LOG" diff --git a/tests/fixtures/stub-tools/windows/herdr.ps1 b/tests/fixtures/stub-tools/windows/herdr.ps1 new file mode 100644 index 0000000..f27250d --- /dev/null +++ b/tests/fixtures/stub-tools/windows/herdr.ps1 @@ -0,0 +1,3 @@ +# stub: herdr +$n = 'herdr' +Add-Content -Path $env:RUN_LOG -Value $n diff --git a/tests/fixtures/stub-tools/windows/pi.ps1 b/tests/fixtures/stub-tools/windows/pi.ps1 new file mode 100644 index 0000000..8eefcb1 --- /dev/null +++ b/tests/fixtures/stub-tools/windows/pi.ps1 @@ -0,0 +1,3 @@ +# stub: pi +$n = 'pi' +Add-Content -Path $env:RUN_LOG -Value $n diff --git a/tests/test_herdr_installer.sh b/tests/test_herdr_installer.sh new file mode 100644 index 0000000..29e0262 --- /dev/null +++ b/tests/test_herdr_installer.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# tests/test_herdr_installer.sh -- parity tests for herdr opt-in installer +# +# Tests: +# T_herdr_in_list -- herdr appears in --list output (opt-in discoverable) +# T_herdr_not_default -- herdr is NOT installed by a default no-arg run +# T_herdr_version_pin -- .tool-versions contains a herdr pin +# T_herdr_optin_stub -- --only=herdr with stub dir runs only herdr +# +# Usage: bash tests/test_herdr_installer.sh +# Requires: bash 3.2+ (macOS compatible) + +set -uo pipefail + +PASS=0 +FAIL=0 +SKIP=0 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +RESET='\033[0m' + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +LINUX_SETUP="${REPO_ROOT}/scripts/linux/setup.sh" +TOOL_VERSIONS="${REPO_ROOT}/.tool-versions" +STUB_DIR="${REPO_ROOT}/tests/fixtures/stub-tools/linux" + +pass() { printf "${GREEN}PASS${RESET}: %s\n" "$1"; PASS=$((PASS + 1)); } +fail() { printf "${RED}FAIL${RESET}: %s\n" "$1"; FAIL=$((FAIL + 1)); } +# shellcheck disable=SC2329 +skip() { printf "${YELLOW}SKIP${RESET}: %s -- %s\n" "$1" "$2"; SKIP=$((SKIP + 1)); } + +# --------------------------------------------------------------------------- +# T_herdr_in_list: --list on real tools dir includes 'herdr' +# --------------------------------------------------------------------------- +echo "" +echo "--- T_herdr_in_list ---" +list_out="$(bash "$LINUX_SETUP" --list 2>&1)" && list_exit=$? || list_exit=$? +if [ "$list_exit" -ne 0 ]; then + fail "T_herdr_in_list: --list exited $list_exit (expected 0)" +elif echo "$list_out" | grep -qF "herdr"; then + pass "T_herdr_in_list: herdr appears in --list output (opt-in discoverable)" +else + fail "T_herdr_in_list: herdr missing from --list output (is herdr.sh in tools/?)" + echo " --list output: $list_out" +fi + +# --------------------------------------------------------------------------- +# T_herdr_not_default: default no-arg run with stub dir does NOT run herdr +# --------------------------------------------------------------------------- +echo "" +echo "--- T_herdr_not_default ---" +RUN_LOG="$(mktemp)" +export RUN_LOG +bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" >/dev/null 2>&1 || true +if grep -qF "herdr" "$RUN_LOG" 2>/dev/null; then + fail "T_herdr_not_default: herdr ran in a default no-arg install (must be opt-in only)" +else + pass "T_herdr_not_default: herdr does NOT run in a default install (correctly opt-in)" +fi +rm -f "$RUN_LOG" +unset RUN_LOG + +# --------------------------------------------------------------------------- +# T_herdr_version_pin: .tool-versions contains a herdr entry +# --------------------------------------------------------------------------- +echo "" +echo "--- T_herdr_version_pin ---" +if grep -qE '^herdr[[:space:]]' "$TOOL_VERSIONS" 2>/dev/null; then + ver="$(grep -E '^herdr[[:space:]]' "$TOOL_VERSIONS" | awk '{print $2}')" + pass "T_herdr_version_pin: herdr pinned at ${ver} in .tool-versions" +else + fail "T_herdr_version_pin: herdr not found in .tool-versions" +fi + +# --------------------------------------------------------------------------- +# T_herdr_optin_stub: --only=herdr with stub dir runs only herdr +# --------------------------------------------------------------------------- +echo "" +echo "--- T_herdr_optin_stub ---" +RUN_LOG2="$(mktemp)" +export RUN_LOG +RUN_LOG="$RUN_LOG2" +bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" --only=herdr >/dev/null 2>&1 || true +if grep -qF "herdr" "$RUN_LOG2" 2>/dev/null; then + actual="$(cat "$RUN_LOG2")" + if [ "$actual" = "herdr" ]; then + pass "T_herdr_optin_stub: --only=herdr runs only herdr via stub" + else + fail "T_herdr_optin_stub: --only=herdr ran unexpected tools: ${actual}" + fi +else + fail "T_herdr_optin_stub: --only=herdr did not run herdr (stub missing or tool unregistered)" +fi +rm -f "$RUN_LOG2" +unset RUN_LOG + +# --------------------------------------------------------------------------- +echo "" +echo "Results: ${PASS} passed, ${FAIL} failed, ${SKIP} skipped" +if [ "$FAIL" -gt 0 ]; then + exit 1 +fi +exit 0 diff --git a/tests/test_herdr_installer_pwsh.ps1 b/tests/test_herdr_installer_pwsh.ps1 new file mode 100644 index 0000000..7f39304 --- /dev/null +++ b/tests/test_herdr_installer_pwsh.ps1 @@ -0,0 +1,113 @@ +# tests/test_herdr_installer_pwsh.ps1 -- parity tests for herdr opt-in installer +# +# Tests: +# T_herdr_in_list -- herdr appears in -List output (opt-in discoverable) +# T_herdr_not_default -- herdr is NOT installed by a default no-arg run +# T_herdr_version_pin -- .tool-versions contains a herdr pin +# T_herdr_optin_stub -- -Only 'herdr' with stub dir runs only herdr +# +# Usage: powershell -ExecutionPolicy Bypass -File tests\test_herdr_installer_pwsh.ps1 +# PS 5.1 ASCII-only: no smart quotes, em-dashes, or non-ASCII characters. + +$ErrorActionPreference = 'Stop' +$TestsPassed = 0 +$TestsFailed = 0 +$TestsSkipped = 0 + +$RepoRoot = Split-Path $PSScriptRoot -Parent +$WinSetup = Join-Path $RepoRoot 'scripts\windows\setup.ps1' +$StubDir = Join-Path $RepoRoot 'tests\fixtures\stub-tools\windows' +$ToolVersions = Join-Path $RepoRoot '.tool-versions' + +function Test-Scenario { + param([string]$Name, [scriptblock]$Test) + Write-Host "`n=== TEST: $Name ===" -ForegroundColor Cyan + try { + & $Test + Write-Host "[PASS] $Name" -ForegroundColor Green + $script:TestsPassed++ + } + catch { + Write-Host "[FAIL] $Name" -ForegroundColor Red + Write-Host " Error: $_" -ForegroundColor Red + $script:TestsFailed++ + } +} + +# --------------------------------------------------------------------------- +# T_herdr_in_list: -List on real registry includes 'herdr' +# --------------------------------------------------------------------------- + +Test-Scenario "T_herdr_in_list: herdr appears in -List output (opt-in discoverable)" { + $out = powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup -List 2>&1 | Out-String + $ec = $LASTEXITCODE + if ($ec -ne 0) { throw "-List exited $ec (expected 0)" } + if ($out -notmatch '\bherdr\b') { + throw "herdr missing from -List output; has herdr.ps1 been registered in ToolRegistry?" + } +} + +# --------------------------------------------------------------------------- +# T_herdr_not_default: default no-arg run with stub dir does NOT run herdr +# --------------------------------------------------------------------------- + +Test-Scenario "T_herdr_not_default: herdr does NOT run in a default install (opt-in only)" { + $runLog = [System.IO.Path]::GetTempFileName() + $env:RUN_LOG = $runLog + try { + powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup ` + -ToolsDir $StubDir 2>&1 | Out-Null + $content = Get-Content $runLog -ErrorAction SilentlyContinue + if ($content -contains 'herdr') { + throw "herdr ran in a default no-arg install (must be opt-in only)" + } + } + finally { + $env:RUN_LOG = $null + Remove-Item $runLog -ErrorAction SilentlyContinue + } +} + +# --------------------------------------------------------------------------- +# T_herdr_version_pin: .tool-versions contains a herdr entry +# --------------------------------------------------------------------------- + +Test-Scenario "T_herdr_version_pin: herdr is pinned in .tool-versions" { + $lines = Get-Content $ToolVersions + $entry = $lines | Where-Object { $_ -match '^herdr\s+' } + if (-not $entry) { + throw "herdr not found in .tool-versions" + } + $ver = ($entry -split '\s+')[1] + Write-Host " herdr pinned at $ver" -ForegroundColor DarkGray +} + +# --------------------------------------------------------------------------- +# T_herdr_optin_stub: -Only 'herdr' with stub dir runs only herdr +# --------------------------------------------------------------------------- + +Test-Scenario "T_herdr_optin_stub: -Only 'herdr' runs only herdr via stub" { + $runLog = [System.IO.Path]::GetTempFileName() + $env:RUN_LOG = $runLog + try { + powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup ` + -ToolsDir $StubDir -Only 'herdr' 2>&1 | Out-Null + $content = Get-Content $runLog -ErrorAction SilentlyContinue + if (-not $content) { throw "-Only 'herdr' produced empty run-log" } + if ($content -notcontains 'herdr') { + throw "-Only 'herdr' did not run herdr stub; log: $($content -join ', ')" + } + $extra = $content | Where-Object { $_ -ne 'herdr' } + if ($extra) { throw "-Only 'herdr' ran unexpected tools: $($extra -join ', ')" } + } + finally { + $env:RUN_LOG = $null + Remove-Item $runLog -ErrorAction SilentlyContinue + } +} + +# --------------------------------------------------------------------------- +Write-Host "" +Write-Host "Results: $TestsPassed passed, $TestsFailed failed, $TestsSkipped skipped" +if ($TestsFailed -gt 0) { exit 1 } +exit 0 diff --git a/tests/test_lazygit_installer.sh b/tests/test_lazygit_installer.sh index d2f74af..d3e0315 100644 --- a/tests/test_lazygit_installer.sh +++ b/tests/test_lazygit_installer.sh @@ -86,7 +86,7 @@ echo "--- T_lazygit_optin_stub ---" RUN_LOG2="$(mktemp)" export RUN_LOG RUN_LOG="$RUN_LOG2" -bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" --only=lazygit 2>&1 | grep -q . || true +bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" --only=lazygit >/dev/null 2>&1 || true if grep -qF "lazygit" "$RUN_LOG2" 2>/dev/null; then actual="$(cat "$RUN_LOG2")" if [ "$actual" = "lazygit" ]; then diff --git a/tests/test_pi_installer.sh b/tests/test_pi_installer.sh new file mode 100644 index 0000000..a6f3acc --- /dev/null +++ b/tests/test_pi_installer.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# tests/test_pi_installer.sh -- parity tests for pi opt-in installer +# +# Tests: +# T_pi_in_list -- pi appears in --list output (opt-in discoverable) +# T_pi_not_default -- pi is NOT installed by a default no-arg run +# T_pi_version_pin -- .tool-versions contains a pi pin +# T_pi_optin_stub -- --only=pi with stub dir runs only pi +# +# Usage: bash tests/test_pi_installer.sh +# Requires: bash 3.2+ (macOS compatible) + +set -uo pipefail + +PASS=0 +FAIL=0 +SKIP=0 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +RESET='\033[0m' + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +LINUX_SETUP="${REPO_ROOT}/scripts/linux/setup.sh" +TOOL_VERSIONS="${REPO_ROOT}/.tool-versions" +STUB_DIR="${REPO_ROOT}/tests/fixtures/stub-tools/linux" + +pass() { printf "${GREEN}PASS${RESET}: %s\n" "$1"; PASS=$((PASS + 1)); } +fail() { printf "${RED}FAIL${RESET}: %s\n" "$1"; FAIL=$((FAIL + 1)); } +# shellcheck disable=SC2329 +skip() { printf "${YELLOW}SKIP${RESET}: %s -- %s\n" "$1" "$2"; SKIP=$((SKIP + 1)); } + +# --------------------------------------------------------------------------- +# T_pi_in_list: --list on real tools dir includes 'pi' +# --------------------------------------------------------------------------- +echo "" +echo "--- T_pi_in_list ---" +list_out="$(bash "$LINUX_SETUP" --list 2>&1)" && list_exit=$? || list_exit=$? +if [ "$list_exit" -ne 0 ]; then + fail "T_pi_in_list: --list exited $list_exit (expected 0)" +elif echo "$list_out" | grep -qF "pi"; then + pass "T_pi_in_list: pi appears in --list output (opt-in discoverable)" +else + fail "T_pi_in_list: pi missing from --list output (is pi.sh in tools/?)" + echo " --list output: $list_out" +fi + +# --------------------------------------------------------------------------- +# T_pi_not_default: default no-arg run with stub dir does NOT run pi +# --------------------------------------------------------------------------- +echo "" +echo "--- T_pi_not_default ---" +RUN_LOG="$(mktemp)" +export RUN_LOG +bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" >/dev/null 2>&1 || true +if grep -qF "pi" "$RUN_LOG" 2>/dev/null; then + fail "T_pi_not_default: pi ran in a default no-arg install (must be opt-in only)" +else + pass "T_pi_not_default: pi does NOT run in a default install (correctly opt-in)" +fi +rm -f "$RUN_LOG" +unset RUN_LOG + +# --------------------------------------------------------------------------- +# T_pi_version_pin: .tool-versions contains a pi entry +# --------------------------------------------------------------------------- +echo "" +echo "--- T_pi_version_pin ---" +if grep -qE '^pi[[:space:]]' "$TOOL_VERSIONS" 2>/dev/null; then + ver="$(grep -E '^pi[[:space:]]' "$TOOL_VERSIONS" | awk '{print $2}')" + pass "T_pi_version_pin: pi pinned at ${ver} in .tool-versions" +else + fail "T_pi_version_pin: pi not found in .tool-versions" +fi + +# --------------------------------------------------------------------------- +# T_pi_optin_stub: --only=pi with stub dir runs only pi +# --------------------------------------------------------------------------- +echo "" +echo "--- T_pi_optin_stub ---" +RUN_LOG2="$(mktemp)" +export RUN_LOG +RUN_LOG="$RUN_LOG2" +bash "$LINUX_SETUP" "--tools-dir=${STUB_DIR}" --only=pi >/dev/null 2>&1 || true +if grep -qF "pi" "$RUN_LOG2" 2>/dev/null; then + actual="$(cat "$RUN_LOG2")" + if [ "$actual" = "pi" ]; then + pass "T_pi_optin_stub: --only=pi runs only pi via stub" + else + fail "T_pi_optin_stub: --only=pi ran unexpected tools: ${actual}" + fi +else + fail "T_pi_optin_stub: --only=pi did not run pi (stub missing or tool unregistered)" +fi +rm -f "$RUN_LOG2" +unset RUN_LOG + +# --------------------------------------------------------------------------- +echo "" +echo "Results: ${PASS} passed, ${FAIL} failed, ${SKIP} skipped" +if [ "$FAIL" -gt 0 ]; then + exit 1 +fi +exit 0 diff --git a/tests/test_pi_installer_pwsh.ps1 b/tests/test_pi_installer_pwsh.ps1 new file mode 100644 index 0000000..4d5cf25 --- /dev/null +++ b/tests/test_pi_installer_pwsh.ps1 @@ -0,0 +1,113 @@ +# tests/test_pi_installer_pwsh.ps1 -- parity tests for pi opt-in installer +# +# Tests: +# T_pi_in_list -- pi appears in -List output (opt-in discoverable) +# T_pi_not_default -- pi is NOT installed by a default no-arg run +# T_pi_version_pin -- .tool-versions contains a pi pin +# T_pi_optin_stub -- -Only 'pi' with stub dir runs only pi +# +# Usage: powershell -ExecutionPolicy Bypass -File tests\test_pi_installer_pwsh.ps1 +# PS 5.1 ASCII-only: no smart quotes, em-dashes, or non-ASCII characters. + +$ErrorActionPreference = 'Stop' +$TestsPassed = 0 +$TestsFailed = 0 +$TestsSkipped = 0 + +$RepoRoot = Split-Path $PSScriptRoot -Parent +$WinSetup = Join-Path $RepoRoot 'scripts\windows\setup.ps1' +$StubDir = Join-Path $RepoRoot 'tests\fixtures\stub-tools\windows' +$ToolVersions = Join-Path $RepoRoot '.tool-versions' + +function Test-Scenario { + param([string]$Name, [scriptblock]$Test) + Write-Host "`n=== TEST: $Name ===" -ForegroundColor Cyan + try { + & $Test + Write-Host "[PASS] $Name" -ForegroundColor Green + $script:TestsPassed++ + } + catch { + Write-Host "[FAIL] $Name" -ForegroundColor Red + Write-Host " Error: $_" -ForegroundColor Red + $script:TestsFailed++ + } +} + +# --------------------------------------------------------------------------- +# T_pi_in_list: -List on real registry includes 'pi' +# --------------------------------------------------------------------------- + +Test-Scenario "T_pi_in_list: pi appears in -List output (opt-in discoverable)" { + $out = powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup -List 2>&1 | Out-String + $ec = $LASTEXITCODE + if ($ec -ne 0) { throw "-List exited $ec (expected 0)" } + if ($out -notmatch '\bpi\b') { + throw "pi missing from -List output; has pi.ps1 been registered in ToolRegistry?" + } +} + +# --------------------------------------------------------------------------- +# T_pi_not_default: default no-arg run with stub dir does NOT run pi +# --------------------------------------------------------------------------- + +Test-Scenario "T_pi_not_default: pi does NOT run in a default install (opt-in only)" { + $runLog = [System.IO.Path]::GetTempFileName() + $env:RUN_LOG = $runLog + try { + powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup ` + -ToolsDir $StubDir 2>&1 | Out-Null + $content = Get-Content $runLog -ErrorAction SilentlyContinue + if ($content -contains 'pi') { + throw "pi ran in a default no-arg install (must be opt-in only)" + } + } + finally { + $env:RUN_LOG = $null + Remove-Item $runLog -ErrorAction SilentlyContinue + } +} + +# --------------------------------------------------------------------------- +# T_pi_version_pin: .tool-versions contains a pi entry +# --------------------------------------------------------------------------- + +Test-Scenario "T_pi_version_pin: pi is pinned in .tool-versions" { + $lines = Get-Content $ToolVersions + $entry = $lines | Where-Object { $_ -match '^pi\s+' } + if (-not $entry) { + throw "pi not found in .tool-versions" + } + $ver = ($entry -split '\s+')[1] + Write-Host " pi pinned at $ver" -ForegroundColor DarkGray +} + +# --------------------------------------------------------------------------- +# T_pi_optin_stub: -Only 'pi' with stub dir runs only pi +# --------------------------------------------------------------------------- + +Test-Scenario "T_pi_optin_stub: -Only 'pi' runs only pi via stub" { + $runLog = [System.IO.Path]::GetTempFileName() + $env:RUN_LOG = $runLog + try { + powershell -NoProfile -ExecutionPolicy Bypass -File $WinSetup ` + -ToolsDir $StubDir -Only 'pi' 2>&1 | Out-Null + $content = Get-Content $runLog -ErrorAction SilentlyContinue + if (-not $content) { throw "-Only 'pi' produced empty run-log" } + if ($content -notcontains 'pi') { + throw "-Only 'pi' did not run pi stub; log: $($content -join ', ')" + } + $extra = $content | Where-Object { $_ -ne 'pi' } + if ($extra) { throw "-Only 'pi' ran unexpected tools: $($extra -join ', ')" } + } + finally { + $env:RUN_LOG = $null + Remove-Item $runLog -ErrorAction SilentlyContinue + } +} + +# --------------------------------------------------------------------------- +Write-Host "" +Write-Host "Results: $TestsPassed passed, $TestsFailed failed, $TestsSkipped skipped" +if ($TestsFailed -gt 0) { exit 1 } +exit 0 diff --git a/tests/test_tool_versions.sh b/tests/test_tool_versions.sh index e21c0fd..7a84211 100644 --- a/tests/test_tool_versions.sh +++ b/tests/test_tool_versions.sh @@ -19,7 +19,7 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" READER="${REPO_ROOT}/scripts/lib/read-tool-version.sh" # Test 1: nodejs returns expected value -expected="22.11.0" +expected="22.23.2" got="$(sh "$READER" nodejs)" if [ "$got" = "$expected" ]; then pass "nodejs version is $expected" @@ -45,7 +45,25 @@ else fail "uv version: expected '$expected', got '$got'" fi -# Test 4: unknown tool exits non-zero +# Test 4: pi returns expected value +expected="0.86.1" +got="$(sh "$READER" pi)" +if [ "$got" = "$expected" ]; then + pass "pi version is $expected" +else + fail "pi version: expected '$expected', got '$got'" +fi + +# Test 5: herdr returns expected value +expected="0.9.1" +got="$(sh "$READER" herdr)" +if [ "$got" = "$expected" ]; then + pass "herdr version is $expected" +else + fail "herdr version: expected '$expected', got '$got'" +fi + +# Test 6: unknown tool exits non-zero if sh "$READER" nonexistent-tool >/dev/null 2>&1; then fail "nonexistent tool should exit non-zero" else diff --git a/tests/test_windows_setup.ps1 b/tests/test_windows_setup.ps1 index 62c1837..f0a9bf6 100644 --- a/tests/test_windows_setup.ps1 +++ b/tests/test_windows_setup.ps1 @@ -1108,8 +1108,8 @@ $toolVersionScript = Join-Path $RepoRoot 'scripts' | Join-Path -ChildPath 'lib' Test-Scenario "R-1 Get-ToolVersion returns nodejs version" { $ver = Get-ToolVersion -Name 'nodejs' - if ($ver -ne '22.11.0') { - throw "Expected '22.11.0', got '$ver'" + if ($ver -ne '22.23.2') { + throw "Expected '22.23.2', got '$ver'" } } @@ -1127,6 +1127,13 @@ Test-Scenario "R-2b Get-ToolVersion returns nvm-windows version" { } } +Test-Scenario "R-2c Get-ToolVersion returns herdr version" { + $ver = Get-ToolVersion -Name 'herdr' + if ($ver -ne '0.9.1') { + throw "Expected '0.9.1', got '$ver'" + } +} + Test-Scenario "R-3 Get-ToolVersion returns uv version" { $ver = Get-ToolVersion -Name 'uv' if ($ver -ne '0.4.18') {