hex/scripts/test-windows-installer.ps1
Kit Langton 754666b06b
Windows Setup.exe, one site, and a download section that works (#166)
* feat(windows): a per-user Setup.exe installer for the managed layout

* feat(release): build, test, and publish Setup.exe installers and the GitHub download mirror

* fix(onboarding): name the tray on Windows and the background service on Linux; keep Apps & Features on the updated version

* feat(site): one site with a platform-aware download section; retire hex.kitlangton.com

* feat(site): prerender the page, add robots, sitemap, llms.txt, JSON-LD, and favicon.ico
2026-10-19 19:26:41 -07:00

92 lines
5.2 KiB
PowerShell

# Silently installs, reinstalls, refuses a downgrade with, and uninstalls a
# HEX-Setup-*.exe on a disposable Windows machine (CI), checking the managed
# layout that src/windows_updater.rs expects at every step. It uses the real
# %APPDATA%, so never run it on a machine with Hex installed.
#
# scripts/test-windows-installer.ps1 -Installer dist\HEX-Setup-2.3.0-x64.exe `
# -Executable dist\HEX-2.3.0-...-x86_64-windows.exe -Version 2.3.0
[CmdletBinding()]
param(
[Parameter(Mandatory)] [string]$Installer,
[Parameter(Mandatory)] [string]$Executable,
[Parameter(Mandatory)] [string]$Version
)
$ErrorActionPreference = 'Stop'
$support = Join-Path $env:APPDATA 'voice-control'
$installed = Join-Path $support "versions\$Version\hex.exe"
$pointer = Join-Path $support 'current-version'
$shortcut = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Hex.lnk'
$uninstallKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{8FCF0256-C55C-40C3-865D-5FADB32D13B3}_is1'
$runKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
$logs = Join-Path $env:RUNNER_TEMP 'hex-installer-logs'
New-Item -ItemType Directory -Force $logs | Out-Null
function Check([bool]$condition, [string]$message) {
if (-not $condition) { throw "FAIL: $message" }
Write-Output "ok - $message"
}
function Run-Setup([string]$name) {
$process = Start-Process $Installer -Wait -PassThru -ArgumentList @(
'/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', '/SKIPVULKANCHECK=1', "/LOG=$logs\$name.log"
)
$process.ExitCode
}
if (Test-Path $support) { throw "$support already exists; run this only on a clean machine." }
$expected = (Get-FileHash -Algorithm SHA256 $Executable).Hash
Check ((Run-Setup 'install') -eq 0) 'silent install exits 0'
Check (Test-Path $installed) "hex.exe is at versions\$Version"
Check ((Get-FileHash -Algorithm SHA256 $installed).Hash -eq $expected) 'installed hex.exe matches the release bytes'
Check ((Get-Content $pointer -Raw).Trim() -eq $Version) "current-version names $Version"
$link = (New-Object -ComObject WScript.Shell).CreateShortcut($shortcut)
Check ($link.TargetPath -eq $installed) 'Start Menu shortcut targets the managed executable'
Check ($link.Arguments -eq 'app') 'Start Menu shortcut launches the app'
Check ($link.Description -eq 'HEX managed install') 'Start Menu shortcut carries the managed mark the updater repoints'
$entry = Get-ItemProperty $uninstallKey
Check ($entry.DisplayName -eq 'Hex') 'Apps & Features lists Hex'
Check ($entry.DisplayVersion -eq $Version) "Apps & Features shows $Version"
$uninstaller = ($entry.UninstallString -replace '"', '')
Check ($uninstaller -like "$support\uninstall\*") 'the uninstaller lives outside versions\, which updates prune'
Check (Test-Path $uninstaller) 'the uninstaller exists'
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64' -or (Test-Path "$env:SystemRoot\System32\vulkan-1.dll")) {
$reported = (& $installed --version) -split '\s+' | Select-Object -Last 1
Check ($reported -eq $Version) "installed hex.exe reports $Version"
} else {
Write-Output 'skip - hex.exe --version needs vulkan-1.dll, which this runner lacks'
}
Check ((Run-Setup 'reinstall') -eq 0) 'reinstalling the same version exits 0'
Check ((Get-FileHash -Algorithm SHA256 $installed).Hash -eq $expected) 'reinstall keeps the release bytes'
# A self-update to a newer version must never be rolled back by this installer.
Set-Content -Path $pointer -Value '99.0.0' -NoNewline
Check ((Run-Setup 'downgrade') -ne 0) 'an installer older than the installed version refuses to run'
Check ((Get-Content $pointer -Raw).Trim() -eq '99.0.0') 'the refused downgrade leaves current-version alone'
# Simulate what a self-update and Launch at login leave behind.
$updated = Join-Path $support 'versions\99.0.0\hex.exe'
New-Item -ItemType Directory -Force (Split-Path $updated) | Out-Null
Copy-Item $installed $updated
New-Item -ItemType Directory -Force (Join-Path $support 'updates') | Out-Null
if (-not (Test-Path $runKey)) { New-Item -Path $runKey | Out-Null }
Set-ItemProperty -Path $runKey -Name 'HEX' -Value "`"$updated`" app --hidden"
Set-Content -Path (Join-Path $support 'settings.json') -Value '{}'
$process = Start-Process $uninstaller -Wait -PassThru -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/LOG=$logs\uninstall.log"
Check ($process.ExitCode -eq 0) 'silent uninstall exits 0'
# The uninstaller finishes from a temporary copy of itself.
$deadline = (Get-Date).AddSeconds(60)
while ((Test-Path $uninstallKey) -and (Get-Date) -lt $deadline) { Start-Sleep -Milliseconds 500 }
Check (-not (Test-Path $uninstallKey)) 'Apps & Features entry is removed'
Check (-not (Test-Path (Join-Path $support 'versions'))) 'every version, including self-updated ones, is removed'
Check (-not (Test-Path (Join-Path $support 'updates'))) 'staged updates are removed'
Check (-not (Test-Path $pointer)) 'current-version is removed'
Check (-not (Test-Path $shortcut)) 'Start Menu shortcut is removed'
Check ($null -eq (Get-ItemProperty -Path $runKey -Name 'HEX' -ErrorAction SilentlyContinue)) 'Launch at login is removed'
Check (Test-Path (Join-Path $support 'settings.json')) 'settings are kept'
Remove-Item $support -Recurse -Force
Write-Output "Installer $([IO.Path]::GetFileName($Installer)) passed."