feat: prepare PCL-ISE 0.1.2 update test release
Release PCL-ISE / release (push) Canceled after 0s

This commit is contained in:
Coldsmile_7 committed 2026-10-27 23:57:25 +08:00
1 parent 5d549ff66a
commit e831d0dfe0
28 files changed
+1026 -286

No files matched your search

+96 -4
View File
@@ -8,10 +8,11 @@ $testRoot = Join-Path $repoRoot ('artifacts\update-tests\' + [Guid]::NewGuid().T
[IO.Directory]::CreateDirectory($testRoot) | Out-Null
$framework = Join-Path $env:WINDIR 'Microsoft.NET\Framework\v4.0.30319'
$testLibrary = Join-Path $testRoot 'LauncherUpdateTests.dll'
$testLibrary = Join-Path $testRoot ('LauncherUpdateTests_' + (Split-Path $testRoot -Leaf) + '.dll')
& (Join-Path $framework 'vbc.exe') /nologo /target:library "/out:$testLibrary" $sourcePath
if ($LASTEXITCODE -ne 0) { throw 'Update module compilation failed' }
$updateType = [Reflection.Assembly]::LoadFile($testLibrary).GetType('ModLauncherUpdate')
$testAssembly = [Reflection.Assembly]::LoadFrom($testLibrary)
$updateType = $testAssembly.GetType('ModLauncherUpdate')
$parse = $updateType.GetMethod('ParseLauncherVersion')
$replace = $updateType.GetMethod('ReplaceLauncherFile')
$testState = @{ Passed = 0 }
@@ -20,8 +21,8 @@ function Assert-True([bool]$Condition, [string]$Description) {
$testState.Passed++
Write-Host "PASS: $Description"
}
function Replace-File([int]$PreviousId, [string]$Target, [string]$Source, [int]$Timeout = 30000) {
$replace.Invoke($null, @($PreviousId, $Target, $Source, $Timeout))
function Replace-File([int]$PreviousId, [string]$Target, [string]$Source, [int]$Timeout = 30000, $Operations = $null) {
$replace.Invoke($null, @($PreviousId, $Target, $Source, $Timeout, $Operations))
}
foreach ($inputVersion in @('0.1.1', 'v0.1.1', '0.1.1-dev', '0.1.1+build')) {
@@ -63,6 +64,78 @@ Replace-File 0 $newTarget $download
Assert-True ([IO.File]::ReadAllText($newTarget) -eq 'new version') 'install into absent target'
Assert-True (@(Get-ChildItem $testRoot -Filter '*.new').Count -eq 0) 'no staged files left behind'
$faultLibrary = Join-Path $testRoot 'UpdateFileOperationsTests.dll'
& $csc /nologo /target:library "/reference:$testLibrary" "/out:$faultLibrary" (Join-Path $repoRoot 'tests\LauncherUpdateFileOperations.cs')
if ($LASTEXITCODE -ne 0) { throw 'Fault operation compilation failed' }
$faultType = [Reflection.Assembly]::LoadFrom($faultLibrary).GetType('TestLauncherUpdateFileOperations')
function New-FaultOperations([string]$TargetPath) {
$operations = [Activator]::CreateInstance($faultType)
$operations.TargetPath = $TargetPath
$operations.RetryTimeoutMilliseconds = 0
return $operations
}
function Get-ReplaceFailure([string]$TargetPath, $Operations) {
try { Replace-File 0 $TargetPath $download 30000 $Operations } catch { return $_.Exception.InnerException }
throw 'Expected a file operation failure'
}
$backupFailureTarget = Join-Path $testRoot 'backup-failure.exe'
[IO.File]::WriteAllText($backupFailureTarget, 'old version')
$fault = New-FaultOperations $backupFailureTarget
$fault.FailBackup = $true
$failure = Get-ReplaceFailure $backupFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($backupFailureTarget) -eq 'old version') 'backup failure never deletes old program'
$copyFailureTarget = Join-Path $testRoot 'copy-failure.exe'
[IO.File]::WriteAllText($copyFailureTarget, 'old version')
$fault = New-FaultOperations $copyFailureTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$failure = Get-ReplaceFailure $copyFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($copyFailureTarget) -eq 'old version') 'interrupted copy restores old program over a partial target'
Assert-True ([IO.File]::ReadAllText($copyFailureTarget + '.bak') -eq 'old version') 'rollback retains backup'
$hashFailureTarget = Join-Path $testRoot 'hash-failure.exe'
[IO.File]::WriteAllText($hashFailureTarget, 'old version')
$fault = New-FaultOperations $hashFailureTarget
$fault.CorruptInstalledFile = $true
$failure = Get-ReplaceFailure $hashFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($hashFailureTarget) -eq 'old version') 'installed file hash failure restores old program'
$restoreFailureTarget = Join-Path $testRoot 'restore-failure.exe'
[IO.File]::WriteAllText($restoreFailureTarget, 'old version')
$fault = New-FaultOperations $restoreFailureTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$fault.FailRestore = $true
$failure = Get-ReplaceFailure $restoreFailureTarget $fault
Assert-True ($failure -is [AggregateException]) 'failed restore reports installation and restoration failures'
Assert-True ([IO.File]::ReadAllText($restoreFailureTarget + '.bak') -eq 'old version') 'failed restore retains backup for manual recovery'
Assert-True ([IO.File]::ReadAllText($download) -eq 'new version') 'failed restore retains source download'
$retryTarget = Join-Path $testRoot 'retry.exe'
[IO.File]::WriteAllText($retryTarget, 'old version')
$fault = New-FaultOperations $retryTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$fault.RetryTimeoutMilliseconds = 1000
Replace-File 0 $retryTarget $download 30000 $fault
Assert-True ([IO.File]::ReadAllText($retryTarget) -eq 'new version') 'temporary copy failure retries successfully'
$newFailedTarget = Join-Path $testRoot 'failed-first-install.exe'
$fault = New-FaultOperations $newFailedTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$failure = Get-ReplaceFailure $newFailedTarget $fault
Assert-True (-not [IO.File]::Exists($newFailedTarget)) 'failed first install removes partial target'
$cleanupTarget = Join-Path $testRoot 'cleanup.exe'
[IO.File]::WriteAllText($cleanupTarget, 'old version')
$fault = New-FaultOperations $cleanupTarget
$fault.FailCleanup = $true
Replace-File 0 $cleanupTarget $download 30000 $fault
Assert-True ([IO.File]::ReadAllText($cleanupTarget) -eq 'new version') 'cleanup failure does not report a successful installation as failed'
if ($LauncherPath) {
$LauncherPath = (Resolve-Path $LauncherPath).Path
$liveTarget = Join-Path $testRoot 'RunningLauncher.exe'
@@ -76,6 +149,25 @@ if ($LauncherPath) {
Assert-True ($helper.ExitCode -eq 5) 'real launcher update helper exits successfully'
Assert-True ((Get-FileHash $liveTarget).Hash -eq (Get-FileHash $LauncherPath).Hash) 'real helper replaces running old launcher after it exits'
Assert-True ((Get-FileHash ($liveTarget + '.bak')).Hash -eq (Get-FileHash $oldExe).Hash) 'real helper preserves previous launcher'
$resultPath = $updateType.GetMethod('GetLauncherUpdateResultPath').Invoke($null, @([string]$liveTarget))
$receipt = Get-Content -LiteralPath $resultPath -Raw | ConvertFrom-Json
Assert-True ($receipt.Succeeded -and $receipt.HelperProcessId -eq $helper.Id -and $receipt.TargetPath -eq $liveTarget) 'real helper saves a successful update receipt for the next startup'
$lockedTarget = Join-Path $testRoot 'locked-target.exe'
Copy-Item -LiteralPath $oldExe -Destination $lockedTarget
$originalHash = (Get-FileHash $lockedTarget).Hash
$lockStream = [IO.File]::Open($lockedTarget, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::None)
try {
$arguments = '--update 0 "{0}" "{1}" false' -f $lockedTarget, $LauncherPath
$helper = Start-Process -FilePath $LauncherPath -ArgumentList $arguments -WorkingDirectory $testRoot -WindowStyle Hidden -PassThru
if (-not $helper.WaitForExit(20000)) { throw 'Failed update helper did not finish within 20 seconds' }
$helper.Refresh()
Assert-True ($helper.ExitCode -ne 5) 'real helper reports file replacement failure without a modal dialog'
} finally { $lockStream.Dispose() }
Assert-True ((Get-FileHash $lockedTarget).Hash -eq $originalHash) 'real helper failure leaves old executable intact'
$resultPath = $updateType.GetMethod('GetLauncherUpdateResultPath').Invoke($null, @([string]$lockedTarget))
$receipt = Get-Content -LiteralPath $resultPath -Raw | ConvertFrom-Json
Assert-True (-not $receipt.Succeeded -and -not [string]::IsNullOrWhiteSpace($receipt.ErrorMessage)) 'real helper saves an error receipt for the next startup'
}
Write-Host "$($testState.Passed) checks passed. Artifacts: $testRoot"