Skip to content

Commit bb393db

Browse files
mdesmetclaude
andcommitted
fix(install.ps1): address PR review — WOW64 arch, help, Pester tests
- WOW64 arch fix (MAJOR): resolve via PROCESSOR_ARCHITEW6432 so a 32-bit PowerShell host on 64-bit Windows is correctly detected as AMD64 instead of being rejected as unsupported x86. - Add -Help/-Help usage block (Show-Usage) mirroring the bash installer's usage(). - Consolidate the two Add-Type P/Invoke blocks into one Win32.AltimateNative type (IsProcessorFeaturePresent + SendMessageTimeout). - Standardize user-facing errors through Write-Err with a uniform "error: " prefix. - Document that archive integrity verification is intentionally deferred to match the bash installer (HTTPS from GitHub releases); full checksum publish+verify for both installers tracked as a follow-up PR. - Add Pester behavioral tests (test/windows/install.Tests.ps1) covering syntax, -Help, the WOW64 fix, ARM64/x86 rejection, and unknown-version handling, plus a windows-latest CI lane in ci.yml. Verified: 6/6 pass on PowerShell 7.6.2. - Extend windows-install.test.ts to assert the ARCHITEW6432 logic and -Help block. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 7756038 commit bb393db

4 files changed

Lines changed: 202 additions & 16 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
typescript: ${{ steps.filter.outputs.typescript }}
2424
drivers: ${{ steps.filter.outputs.drivers }}
2525
dbt-tools: ${{ steps.filter.outputs.dbt-tools }}
26+
installer: ${{ steps.filter.outputs.installer }}
2627
steps:
2728
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2829

@@ -50,6 +51,9 @@ jobs:
5051
- 'packages/opencode/test/altimate/connections.test.ts'
5152
dbt-tools:
5253
- 'packages/dbt-tools/**'
54+
installer:
55+
- 'install.ps1'
56+
- 'test/windows/**'
5357
5458
# ---------------------------------------------------------------------------
5559
# Main TypeScript tests — excludes driver E2E tests (separate job) and
@@ -309,6 +313,34 @@ jobs:
309313
run: bun run test
310314
working-directory: packages/dbt-tools
311315

316+
# ---------------------------------------------------------------------------
317+
# Windows installer (install.ps1) — Pester behavioral tests on real Windows.
318+
# Runs the script as a subprocess (stopping early via -Help / unknown version
319+
# so nothing is downloaded) to cover arg parsing, the WOW64 arch fix, and
320+
# unknown-version rejection. Only when install.ps1 / its tests change.
321+
# ---------------------------------------------------------------------------
322+
windows-installer:
323+
name: Windows Installer (Pester)
324+
needs: changes
325+
if: needs.changes.outputs.installer == 'true' || github.event_name == 'push'
326+
runs-on: windows-latest
327+
timeout-minutes: 10
328+
steps:
329+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
330+
331+
- name: Install Pester
332+
shell: pwsh
333+
run: Install-Module Pester -MinimumVersion 5.0.0 -Force -Scope CurrentUser -SkipPublisherCheck
334+
335+
- name: Run installer Pester tests
336+
shell: pwsh
337+
run: |
338+
$config = New-PesterConfiguration
339+
$config.Run.Path = "./test/windows/install.Tests.ps1"
340+
$config.Run.Throw = $true
341+
$config.Output.Verbosity = "Detailed"
342+
Invoke-Pester -Configuration $config
343+
312344
# ---------------------------------------------------------------------------
313345
# dbt-tools E2E — slow (~3 min), only on push to main.
314346
# Tests dbt CLI fallbacks against real dbt versions (1.8, 1.10, 1.11) and

‎install.ps1‎

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ param(
2020
[switch]$NoPathUpdate = $false,
2121
# Force the baseline (non-AVX2) build even if AVX2 is detected. Also used by
2222
# the illegal-instruction retry below when AVX2 detection is wrong.
23-
[switch]$ForceBaseline = $false
23+
[switch]$ForceBaseline = $false,
24+
# Show usage and exit (mirrors -h/--help in the bash installer).
25+
[switch]$Help = $false
2426
)
2527

2628
$ErrorActionPreference = "Stop"
@@ -33,17 +35,60 @@ $InstallDir = Join-Path $env:USERPROFILE ".altimate\bin"
3335
$BinaryName = "$App.exe"
3436
$InstalledBinary = Join-Path $InstallDir $BinaryName
3537

38+
# All user-facing errors go through Write-Err with a uniform "error: " prefix so
39+
# logs are greppable; informational/secondary lines use the muted Write-Muted.
3640
function Write-Muted($msg) { Write-Host $msg -ForegroundColor DarkGray }
37-
function Write-Err($msg) { Write-Host $msg -ForegroundColor Red }
41+
function Write-Err($msg) { Write-Host "error: $msg" -ForegroundColor Red }
42+
43+
function Show-Usage {
44+
Write-Host @"
45+
Altimate Code Installer (Windows)
46+
47+
Usage: irm https://www.altimate.sh/install.ps1 | iex
48+
or: install.ps1 [options]
49+
50+
Options:
51+
-Help Display this help message
52+
-Version <version> Install a specific version (e.g. 1.0.180)
53+
-NoPathUpdate Don't modify the user PATH
54+
-ForceBaseline Install the non-AVX2 (baseline) build
55+
56+
Examples:
57+
powershell -c "irm https://www.altimate.sh/install.ps1 | iex"
58+
&([scriptblock]::Create((irm https://www.altimate.sh/install.ps1))) -Version 1.0.180
59+
"@
60+
}
61+
62+
if ($Help) {
63+
Show-Usage
64+
exit 0
65+
}
66+
67+
# A single P/Invoke type carries both native calls we need — the AVX2 CPU probe
68+
# (kernel32) and the PATH-change broadcast (user32) — so we Add-Type once instead
69+
# of compiling a throwaway type per call site.
70+
function Initialize-Native {
71+
if (-not ("Win32.AltimateNative" -as [type])) {
72+
Add-Type -Namespace Win32 -Name AltimateNative -MemberDefinition @"
73+
[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);
74+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
75+
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
76+
"@
77+
}
78+
}
3879

3980
# ---------------------------------------------------------------------------
4081
# Architecture / baseline detection
4182
# ---------------------------------------------------------------------------
4283
# Only win32-x64 is built. @altimateai/altimate-core has no NAPI prebuild for
4384
# win32-arm64, so ARM64 has no standalone archive (see packages/opencode/script/build.ts).
44-
$procArch = $env:PROCESSOR_ARCHITECTURE
45-
if ($procArch -ne "AMD64") {
46-
Write-Err "Unsupported OS/Arch: windows/$procArch"
85+
#
86+
# Under WOW64 (a 32-bit PowerShell host on 64-bit Windows) PROCESSOR_ARCHITECTURE
87+
# reports "x86"; the true machine arch lives in PROCESSOR_ARCHITEW6432. Prefer the
88+
# latter so a real AMD64 box isn't misdetected as unsupported x86.
89+
$rawArch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
90+
if ($rawArch -ne "AMD64") {
91+
Write-Err "Unsupported OS/Arch: windows/$rawArch"
4792
Write-Muted "The standalone Windows build is x64 (AMD64) only. On Windows-on-ARM, use WSL or npm install -g altimate-code."
4893
exit 1
4994
}
@@ -53,9 +98,8 @@ $arch = "x64"
5398
# IsProcessorFeaturePresent(40) == PF_AVX2_INSTRUCTIONS_AVAILABLE.
5499
function Test-Avx2 {
55100
try {
56-
$sig = '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);'
57-
$k32 = Add-Type -MemberDefinition $sig -Name "AltimateKernel32" -Namespace "Win32" -PassThru
58-
return [bool]$k32::IsProcessorFeaturePresent(40)
101+
Initialize-Native
102+
return [bool][Win32.AltimateNative]::IsProcessorFeaturePresent(40)
59103
} catch {
60104
# If detection fails, assume no AVX2 and fall back to the baseline build —
61105
# the baseline binary runs everywhere, an AVX2 binary on a non-AVX2 CPU crashes.
@@ -89,7 +133,7 @@ if ([string]::IsNullOrWhiteSpace($Version)) {
89133
try {
90134
Invoke-WebRequest -Uri "https://github.com/AltimateAI/altimate-code/releases/tag/v$Version" -Method Head -UseBasicParsing | Out-Null
91135
} catch {
92-
Write-Err "Error: Release v$Version not found"
136+
Write-Err "Release v$Version not found"
93137
Write-Muted "Available releases: https://github.com/AltimateAI/altimate-code/releases"
94138
exit 1
95139
}
@@ -140,6 +184,12 @@ function Install-Target {
140184
$zipPath = Join-Path $tmpDir $filename
141185

142186
try {
187+
# NOTE: integrity verification (SHA256/signature) of the archive is
188+
# intentionally deferred to match the bash installer's posture — both rely
189+
# on HTTPS from github.com release assets. Releases do not currently publish
190+
# a checksums file; adding one + verifying it in both installers is tracked
191+
# as a follow-up. See PR #930 discussion.
192+
#
143193
# Prefer curl.exe (ships with Windows 10 1803+) for a fast download with
144194
# --fail so HTTP errors don't write an error page to disk; fall back to
145195
# Invoke-WebRequest where curl.exe is unavailable.
@@ -198,16 +248,11 @@ if (-not $needsBaseline) {
198248
# Write the user PATH through the registry (not setx, which truncates at 1024
199249
# chars) and broadcast WM_SETTINGCHANGE so already-open shells pick it up.
200250
function Publish-EnvChange {
201-
if (-not ("Win32.NativeMethods" -as [type])) {
202-
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
203-
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
204-
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
205-
"@
206-
}
251+
Initialize-Native
207252
$HWND_BROADCAST = [IntPtr]0xffff
208253
$WM_SETTINGCHANGE = 0x1a
209254
$result = [UIntPtr]::Zero
210-
[Win32.NativeMethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, "Environment", 2, 5000, [ref]$result) | Out-Null
255+
[Win32.AltimateNative]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, "Environment", 2, 5000, [ref]$result) | Out-Null
211256
}
212257

213258
if (-not $NoPathUpdate) {

‎packages/opencode/test/install/windows-install.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ describe("install.ps1 — Bun exe, not npm", () => {
3232
test("rejects win32-arm64 (no NAPI prebuild)", () => {
3333
expect(PS1).toContain("Unsupported OS/Arch")
3434
})
35+
36+
test("resolves arch via PROCESSOR_ARCHITEW6432 (WOW64-safe)", () => {
37+
// A 32-bit PowerShell host on 64-bit Windows reports PROCESSOR_ARCHITECTURE=x86;
38+
// the real arch is in PROCESSOR_ARCHITEW6432. Must prefer the latter.
39+
expect(PS1).toContain("PROCESSOR_ARCHITEW6432")
40+
})
41+
42+
test("exposes a -Help/usage block", () => {
43+
expect(PS1).toContain("[switch]$Help")
44+
expect(PS1).toContain("Altimate Code Installer")
45+
})
3546
})
3647

3748
describe("install.ps1 — baseline (non-AVX2) parity", () => {

‎test/windows/install.Tests.ps1‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Pester behavioral tests for install.ps1 (the Windows standalone installer).
2+
#
3+
# These run the real script as a subprocess on Windows PowerShell so they
4+
# exercise actual behavior — not just substring matching. They deliberately
5+
# stop the script early (via -Help or an unknown -Version) so no 268 MB binary
6+
# is ever downloaded, while still covering the risky branches: argument
7+
# parsing, the WOW64 architecture fix, and unknown-version rejection.
8+
#
9+
# Run locally on Windows: Invoke-Pester ./test/windows/install.Tests.ps1
10+
# CI runs this on windows-latest (see .github/workflows/ci.yml).
11+
12+
BeforeAll {
13+
$script:InstallScript = Join-Path $PSScriptRoot "..\..\install.ps1"
14+
15+
# Invoke install.ps1 in a child pwsh with a controlled environment and return
16+
# @{ Code = <exit code>; Output = <combined stdout+stderr> }. PROCESSOR_* env
17+
# vars are passed per-call so we can simulate WOW64 / ARM64 hosts.
18+
function Invoke-Installer {
19+
param(
20+
[string[]]$ScriptArgs = @(),
21+
[hashtable]$Env = @{}
22+
)
23+
$saved = @{}
24+
foreach ($k in $Env.Keys) {
25+
$saved[$k] = [Environment]::GetEnvironmentVariable($k)
26+
[Environment]::SetEnvironmentVariable($k, $Env[$k])
27+
}
28+
try {
29+
$output = & pwsh -NoProfile -File $script:InstallScript @ScriptArgs 2>&1 | Out-String
30+
return @{ Code = $LASTEXITCODE; Output = $output }
31+
} finally {
32+
foreach ($k in $Env.Keys) {
33+
[Environment]::SetEnvironmentVariable($k, $saved[$k])
34+
}
35+
}
36+
}
37+
}
38+
39+
Describe "install.ps1 syntax" {
40+
It "parses without errors" {
41+
$tokens = $null; $errors = $null
42+
[System.Management.Automation.Language.Parser]::ParseFile($script:InstallScript, [ref]$tokens, [ref]$errors) | Out-Null
43+
$errors | Should -BeNullOrEmpty
44+
}
45+
}
46+
47+
Describe "install.ps1 -Help" {
48+
It "prints usage and exits 0 without installing" {
49+
$r = Invoke-Installer -ScriptArgs @("-Help")
50+
$r.Code | Should -Be 0
51+
$r.Output | Should -Match "-NoPathUpdate"
52+
$r.Output | Should -Match "-ForceBaseline"
53+
$r.Output | Should -Match "-Version"
54+
}
55+
}
56+
57+
Describe "install.ps1 architecture detection" {
58+
It "detects AMD64 under WOW64 (32-bit PowerShell on 64-bit Windows)" {
59+
# PROCESSOR_ARCHITECTURE=x86 but PROCESSOR_ARCHITEW6432=AMD64 → real 64-bit box.
60+
# Using an unknown version makes the script stop at the release 404 check,
61+
# which it can only reach if the WOW64 arch check let it past.
62+
$r = Invoke-Installer -ScriptArgs @("-Version", "0.0.0-nonexistent") -Env @{
63+
PROCESSOR_ARCHITECTURE = "x86"
64+
PROCESSOR_ARCHITEW6432 = "AMD64"
65+
}
66+
$r.Output | Should -Not -Match "Unsupported OS/Arch"
67+
$r.Output | Should -Match "not found"
68+
}
69+
70+
It "rejects genuine 32-bit x86 (no ARCHITEW6432)" {
71+
$r = Invoke-Installer -ScriptArgs @("-Version", "0.0.0-nonexistent") -Env @{
72+
PROCESSOR_ARCHITECTURE = "x86"
73+
PROCESSOR_ARCHITEW6432 = ""
74+
}
75+
$r.Code | Should -Be 1
76+
$r.Output | Should -Match "Unsupported OS/Arch: windows/x86"
77+
}
78+
79+
It "rejects ARM64" {
80+
$r = Invoke-Installer -ScriptArgs @("-Version", "0.0.0-nonexistent") -Env @{
81+
PROCESSOR_ARCHITECTURE = "ARM64"
82+
PROCESSOR_ARCHITEW6432 = ""
83+
}
84+
$r.Code | Should -Be 1
85+
$r.Output | Should -Match "Unsupported OS/Arch: windows/ARM64"
86+
}
87+
}
88+
89+
Describe "install.ps1 version handling" {
90+
It "rejects an unknown pinned version with a friendly error" {
91+
$r = Invoke-Installer -ScriptArgs @("-Version", "0.0.0-nonexistent") -Env @{
92+
PROCESSOR_ARCHITECTURE = "AMD64"
93+
}
94+
$r.Code | Should -Be 1
95+
$r.Output | Should -Match "Release v0.0.0-nonexistent not found"
96+
$r.Output | Should -Match "Available releases"
97+
}
98+
}

0 commit comments

Comments
 (0)