Files
Alby96 20d64af4a4
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-15 18:11:43 +01:00

198 lines
14 KiB
PowerShell

# Installs, runs, upgrades and removes the packed installers on a clean Windows runner (BRIEF §18): silent mode,
# folder with a space, Add/Remove Programs entry, shortcuts, the .chronos file type, upgrade in place (files of the
# previous version removed), user data kept, the uninstaller removing itself, and the documented exit codes. Then the
# single setup: a program added to and removed from an installation in place (a changed file is kept), the separate
# 1.0 Uploader replaced, and a 1.0 Server for Windows retained until the switches leave it out.
param(
[Parameter(Mandatory)] [string] $Setup1,
[Parameter(Mandatory)] [string] $Setup2,
[Parameter(Mandatory)] [string] $LegacyUploaderSetup,
[Parameter(Mandatory)] [string] $ServerSetup,
[Parameter(Mandatory)] [string] $Version1,
[Parameter(Mandatory)] [string] $Version2,
[Parameter(Mandatory)] [string] $Screenshots
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
# Relative paths are taken from the PowerShell location: .NET resolves them from the process directory, which a
# Set-Location does not move, and the programs get the screenshot folder as an argument.
$Setup1 = (Resolve-Path -LiteralPath $Setup1).Path
$Setup2 = (Resolve-Path -LiteralPath $Setup2).Path
$LegacyUploaderSetup = (Resolve-Path -LiteralPath $LegacyUploaderSetup).Path
$ServerSetup = (Resolve-Path -LiteralPath $ServerSetup).Path
$Screenshots = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Screenshots)
function Invoke-Program([string] $Exe, [string[]] $Arguments) {
$start = [System.Diagnostics.ProcessStartInfo]::new($Exe)
foreach ($argument in $Arguments) { $start.ArgumentList.Add($argument) }
$start.UseShellExecute = $false
$process = [System.Diagnostics.Process]::Start($start)
if (-not $process.WaitForExit(600000)) {
$process.Kill($true)
throw "$Exe $Arguments did not finish in 10 minutes"
}
Write-Host "$(Split-Path $Exe -Leaf) $Arguments -> exit $($process.ExitCode)"
return $process.ExitCode
}
function Assert-True([bool] $Condition, [string] $Message) {
if (-not $Condition) { throw "FAILED: $Message" }
Write-Host "ok: $Message"
}
function Wait-Removed([string] $Path) {
for ($i = 0; $i -lt 120 -and (Test-Path -LiteralPath $Path); $i++) { Start-Sleep -Milliseconds 500 }
return -not (Test-Path -LiteralPath $Path)
}
function Get-DefaultValue([string] $Key) {
if (-not (Test-Path -LiteralPath $Key)) { return $null }
return (Get-Item -LiteralPath $Key).GetValue('')
}
function Get-LinkTarget([string] $Link) {
return (New-Object -ComObject WScript.Shell).CreateShortcut($Link).TargetPath
}
function Get-InstallLog([string] $Directory) {
return Get-Content -Raw -LiteralPath (Join-Path $Directory 'install-log.json') | ConvertFrom-Json
}
$dir = Join-Path $env:RUNNER_TEMP 'Chronos Test'
$entryKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Chronos'
$programs = [Environment]::GetFolderPath('Programs')
$desktop = [Environment]::GetFolderPath('DesktopDirectory')
$links = @(
(Join-Path $programs 'Chronos.lnk'), (Join-Path $programs 'Chronos Uploader.lnk'),
(Join-Path $desktop 'Chronos.lnk'), (Join-Path $desktop 'Chronos Uploader.lnk'))
$userData = Join-Path $env:LOCALAPPDATA 'Chronos'
$userFile = Join-Path $userData 'kept-by-setup.txt'
New-Item -ItemType Directory -Force -Path $userData | Out-Null
Set-Content -LiteralPath $userFile -Value 'user data'
Write-Host '--- Arguments'
Assert-True ((Invoke-Program $Setup1 @('/BOGUS')) -eq 2) 'an unknown switch exits with 2 (invalid arguments)'
Assert-True ((Invoke-Program $Setup1 @('/S', '/uninstall')) -eq 6) 'removing a product that is not installed exits with 6'
Assert-True ((Invoke-Program $Setup2 @('/S', '/COMPONENTS=Server')) -eq 2) 'a component the setup does not ship and nothing retains exits with 2'
Write-Host "--- Install $Version1 into '$dir'"
Assert-True ((Invoke-Program $Setup1 @('/S', "/DIR=$dir", '/COMPONENTS=Desktop,Uploader')) -eq 0) 'silent install exits with 0'
foreach ($file in 'Chronos.exe', 'Chronos.Uploader.exe', 'Uninstall Chronos.exe', 'install-log.json', 'legacy.txt') {
Assert-True (Test-Path -LiteralPath (Join-Path $dir $file)) "$file installed"
}
$entry = Get-ItemProperty -LiteralPath $entryKey
Assert-True ($entry.DisplayVersion -eq $Version1) "Add/Remove Programs lists version $Version1"
Assert-True ($entry.InstallLocation -eq $dir) 'Add/Remove Programs lists the chosen folder'
Assert-True ($entry.QuietUninstallString -eq "`"$(Join-Path $dir 'Uninstall Chronos.exe')`" /uninstall /S") 'quiet uninstall command points at the uninstaller'
foreach ($link in $links) { Assert-True (Test-Path -LiteralPath $link) "shortcut '$link' created" }
Assert-True ((Get-DefaultValue 'HKCU:\Software\Classes\.chronos') -eq 'Chronos.Project') '.chronos opens with Chronos'
Assert-True ((Get-DefaultValue 'HKCU:\Software\Classes\Chronos.Project\shell\open\command') -eq "`"$(Join-Path $dir 'Chronos.exe')`" `"%1`"") 'Chronos.Project opens the installed Chronos.exe'
$log = Get-InstallLog $dir
Assert-True ($log.formatVersion -eq 2 -and $null -ne $log.hashes.'Chronos.exe') 'the install log records each file with its SHA-256 (format 2)'
Write-Host '--- Run the installed programs'
foreach ($program in 'Chronos.exe', 'Chronos.Uploader.exe') {
$before = @(Get-ChildItem -Path $Screenshots -Filter *.png -ErrorAction SilentlyContinue).Count
$code = Invoke-Program (Join-Path $dir $program) @('--capture', $Screenshots)
$count = @(Get-ChildItem -Path $Screenshots -Filter *.png -ErrorAction SilentlyContinue).Count - $before
Assert-True ($code -eq 0 -and $count -gt 0) "installed $program starts and draws its screens ($count screenshot(s))"
}
Write-Host "--- Upgrade in place to $Version2"
Assert-True ((Invoke-Program $Setup2 @('/S')) -eq 0) 'silent upgrade exits with 0'
Assert-True ((Get-ItemProperty -LiteralPath $entryKey).DisplayVersion -eq $Version2) "Add/Remove Programs lists version $Version2"
Assert-True ((Get-InstallLog $dir).version -eq $Version2) "install log records version $Version2"
Assert-True (Test-Path -LiteralPath (Join-Path $dir 'Chronos.exe')) 'Chronos.exe still installed'
Assert-True (Test-Path -LiteralPath (Join-Path $dir 'Chronos.Uploader.exe')) 'the Uploader installed before is kept by the upgrade'
Assert-True (-not (Test-Path -LiteralPath (Join-Path $dir 'legacy.txt'))) 'a file only the previous version had is removed'
foreach ($link in $links) { Assert-True (Test-Path -LiteralPath $link) "shortcut '$link' kept" }
Assert-True (Test-Path -LiteralPath $userFile) 'user data kept by the upgrade'
Write-Host '--- Uninstall with the installed uninstaller'
Assert-True ((Invoke-Program (Join-Path $dir 'Uninstall Chronos.exe') @('/uninstall', '/S')) -eq 0) 'silent uninstall exits with 0'
Assert-True (Wait-Removed $dir) 'install folder removed, uninstaller included'
Assert-True (-not (Test-Path -LiteralPath $entryKey)) 'Add/Remove Programs entry removed'
foreach ($link in $links) { Assert-True (-not (Test-Path -LiteralPath $link)) "shortcut '$link' removed" }
Assert-True (-not (Test-Path -LiteralPath 'HKCU:\Software\Classes\Chronos.Project')) 'Chronos.Project file type removed'
Assert-True ($null -eq (Get-DefaultValue 'HKCU:\Software\Classes\.chronos')) '.chronos no longer opens with Chronos'
Assert-True (Test-Path -LiteralPath $userFile) 'user data kept by the uninstall'
$single = Join-Path $env:LOCALAPPDATA 'Programs\Chronos'
$uploaderLinks = @((Join-Path $programs 'Chronos Uploader.lnk'), (Join-Path $desktop 'Chronos Uploader.lnk'))
$desktopLinks = @((Join-Path $programs 'Chronos.lnk'), (Join-Path $desktop 'Chronos.lnk'))
Write-Host '--- One setup: the Uploader alone, then the desktop app added, then the Uploader removed'
Assert-True ((Invoke-Program $Setup2 @('/S', '/COMPONENTS=Uploader')) -eq 0) 'silent install of the Uploader alone exits with 0'
Assert-True (Test-Path -LiteralPath (Join-Path $single 'Chronos.Uploader.exe')) 'Uploader installed in %LOCALAPPDATA%\Programs\Chronos'
Assert-True (-not (Test-Path -LiteralPath (Join-Path $single 'Chronos.exe'))) 'the desktop app is not installed'
foreach ($link in $desktopLinks) { Assert-True (-not (Test-Path -LiteralPath $link)) "no shortcut '$link'" }
Assert-True ($null -eq (Get-DefaultValue 'HKCU:\Software\Classes\.chronos')) '.chronos is not registered without the desktop app'
Assert-True ((Invoke-Program $Setup2 @('/S', '/COMPONENTS=Desktop,Uploader')) -eq 0) 'adding the desktop app in place exits with 0'
Assert-True (Test-Path -LiteralPath (Join-Path $single 'Chronos.exe')) 'the desktop app is added in place'
foreach ($link in $desktopLinks) { Assert-True (Test-Path -LiteralPath $link) "shortcut '$link' created" }
Assert-True ((Get-DefaultValue 'HKCU:\Software\Classes\.chronos') -eq 'Chronos.Project') '.chronos opens with the added desktop app'
# A changed file of a removed program is never deleted: setup checks it against the SHA-256 it recorded.
$changed = Join-Path $single 'Chronos.Uploader.exe'
[System.IO.File]::AppendAllText($changed, 'changed after setup')
Assert-True ((Invoke-Program $Setup2 @('/S', '/COMPONENTS=Desktop')) -eq 0) 'removing the Uploader in place exits with 0'
Assert-True (Test-Path -LiteralPath $changed) 'the Uploader file changed since setup installed it is kept'
Assert-True (-not ((Get-InstallLog $single).components -contains 'Uploader')) 'the install log no longer lists the Uploader'
foreach ($link in $uploaderLinks) { Assert-True (-not (Test-Path -LiteralPath $link)) "shortcut '$link' removed with the Uploader" }
Remove-Item -LiteralPath $changed
Assert-True ((Invoke-Program (Join-Path $single 'Uninstall Chronos.exe') @('/uninstall', '/S')) -eq 0) 'silent uninstall exits with 0'
Assert-True (Wait-Removed $single) 'install folder removed'
Write-Host '--- One setup replaces the separate 1.0 Uploader'
$legacyDir = Join-Path $env:LOCALAPPDATA 'Programs\Chronos Uploader'
$legacyKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ChronosUploader'
$runKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
$approvedKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run'
Assert-True ((Invoke-Program $LegacyUploaderSetup @('/S')) -eq 0) 'the separate Uploader installs'
Assert-True (Test-Path -LiteralPath (Join-Path $legacyDir 'Chronos.Uploader.exe')) 'separate Uploader in %LOCALAPPDATA%\Programs\Chronos Uploader'
# Its sign-in entry, turned off in Task Manager, as the Uploader and Windows write them.
New-Item -Force -Path $runKey | Out-Null
New-Item -Force -Path $approvedKey | Out-Null
Set-ItemProperty -LiteralPath $runKey -Name 'Chronos Uploader' -Value "`"$(Join-Path $legacyDir 'Chronos.Uploader.exe')`" --tray"
Set-ItemProperty -LiteralPath $approvedKey -Name 'Chronos Uploader' -Type Binary -Value ([byte[]](3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
Assert-True ((Invoke-Program $Setup2 @('/S')) -eq 0) 'the single setup exits with 0'
Assert-True (Test-Path -LiteralPath (Join-Path $single 'Chronos.Uploader.exe')) 'the Uploader is now in %LOCALAPPDATA%\Programs\Chronos'
Assert-True (-not (Test-Path -LiteralPath (Join-Path $single 'Chronos.exe'))) 'only the Uploader is installed: it replaces the separate one'
Assert-True (-not (Test-Path -LiteralPath $legacyKey)) 'the separate Uploader entry is gone'
Assert-True (Wait-Removed $legacyDir) 'the separate Uploader folder is gone'
Assert-True ((Get-ItemProperty -LiteralPath $runKey).'Chronos Uploader' -eq "`"$(Join-Path $single 'Chronos.Uploader.exe')`" --tray") 'the sign-in entry starts the new copy with its option'
Assert-True ($null -ne (Get-ItemProperty -LiteralPath $approvedKey -Name 'Chronos Uploader' -ErrorAction SilentlyContinue)) 'the sign-in entry stays turned off'
$link = Join-Path $programs 'Chronos Uploader.lnk'
Assert-True ((Test-Path -LiteralPath $link) -and ((Get-LinkTarget $link) -eq (Join-Path $single 'Chronos.Uploader.exe'))) 'the Start menu shortcut starts the new copy'
Assert-True (Test-Path -LiteralPath $userFile) 'user data kept by the replacement'
Assert-True ((Invoke-Program (Join-Path $single 'Uninstall Chronos.exe') @('/uninstall', '/S')) -eq 0) 'silent uninstall exits with 0'
Assert-True (Wait-Removed $single) 'install folder removed'
Assert-True ($null -eq (Get-ItemProperty -LiteralPath $runKey -Name 'Chronos Uploader' -ErrorAction SilentlyContinue)) 'the sign-in entry goes with the uninstall'
Write-Host '--- One setup keeps a 1.0 Server for Windows until the switches leave it out'
Assert-True ((Invoke-Program $ServerSetup @('/S', '/COMPONENTS=Desktop,Server')) -eq 0) 'the 1.0 Server installs'
$serverLink = Join-Path $programs 'Chronos Server.lnk'
Assert-True (Test-Path -LiteralPath $serverLink) 'its Start menu shortcut is created'
# As Chronos 1.0 wrote it: format 1, no record of which component installed what, no hashes.
$log = Get-InstallLog $single
foreach ($name in 'componentFiles', 'componentShortcuts', 'componentVersions', 'hashes') { $log.PSObject.Properties.Remove($name) }
$log.formatVersion = 1
[System.IO.File]::WriteAllText((Join-Path $single 'install-log.json'), ($log | ConvertTo-Json -Depth 5))
Assert-True ((Invoke-Program $Setup2 @('/S')) -eq 0) 'the upgrade exits with 0'
Assert-True (Test-Path -LiteralPath (Join-Path $single 'Chronos.Server.exe')) 'Chronos.Server.exe is kept'
Assert-True (Test-Path -LiteralPath (Join-Path $single 'legacy.txt')) 'a file the 1.0 log lists and this setup does not ship is kept with it'
Assert-True (Test-Path -LiteralPath $serverLink) 'its shortcut is kept'
$log = Get-InstallLog $single
Assert-True (($log.components -contains 'Server') -and ($log.componentVersions.Server -eq $Version1)) 'the install log keeps the Server at its own version'
Assert-True ((Invoke-Program $Setup2 @('/S', '/COMPONENTS=Desktop')) -eq 0) 'switches that leave the Server out exit with 0'
Assert-True (-not (Test-Path -LiteralPath (Join-Path $single 'Chronos.Server.exe'))) 'Chronos.Server.exe is removed'
Assert-True (-not (Test-Path -LiteralPath (Join-Path $single 'legacy.txt'))) 'the files kept with it are removed'
Assert-True (-not (Test-Path -LiteralPath $serverLink)) 'its shortcut is removed'
Assert-True (-not ((Get-InstallLog $single).components -contains 'Server')) 'the install log no longer lists the Server'
Assert-True ((Invoke-Program (Join-Path $single 'Uninstall Chronos.exe') @('/uninstall', '/S')) -eq 0) 'silent uninstall exits with 0'
Assert-True (Wait-Removed $single) 'install folder removed'
Assert-True (Test-Path -LiteralPath $userFile) 'user data kept'
Write-Host 'Installer test passed.'