返回 DeepSeek-Reasonix
test-windows-upgrade-startup.ps1
根目录 / scripts / test-windows-upgrade-startup.ps1
1 [CmdletBinding()]
2 param(
3 [string]$ApplicationPath,
4 [string]$FixtureBuilderPath,
5 [string]$ExpectedVersion,
6 [string]$EvidenceDirectory
7 )
8 $ErrorActionPreference = 'Stop'
9
10 function Invoke-UpgradeFixture([string]$builder, [string[]]$arguments) {
11 & $builder @arguments
12 if ($LASTEXITCODE -ne 0) { throw "Upgrade fixture failed with exit code $LASTEXITCODE" }
13 }
14
15 function Invoke-UpgradeStartup([string]$installRoot, [string]$version, [string]$fixtureHome, [string]$text, [string]$evidence, [bool]$prepareHistorical) {
16 & (Join-Path $PSScriptRoot 'test-windows-startup-recovery.ps1') `
17 -InstallRoot $installRoot -ExpectedVersion $version -DataHome $fixtureHome `
18 -ExpectedVisibleText $text -EvidenceDirectory $evidence -PrepareHistoricalSession:$prepareHistorical
19 if (-not $?) { throw 'Upgraded startup verification failed.' }
20 }
21
22 function Invoke-WindowsUpgradeAcceptance {
23 param(
24 [Parameter(Mandatory=$true)][string]$ApplicationPath,
25 [Parameter(Mandatory=$true)][string]$FixtureBuilderPath,
26 [Parameter(Mandatory=$true)][string]$ExpectedVersion,
27 [Parameter(Mandatory=$true)][string]$EvidenceDirectory
28 )
29 $application = (Resolve-Path -LiteralPath $ApplicationPath).Path
30 $fixtureBuilder = (Resolve-Path -LiteralPath $FixtureBuilderPath).Path
31 $installRoot = Split-Path $application -Parent
32 $evidence = [IO.Path]::GetFullPath($EvidenceDirectory)
33 if (Test-Path -LiteralPath $evidence) { throw 'Upgrade acceptance evidence directory must be new.' }
34 $current = Get-Content -LiteralPath (Join-Path $installRoot 'current.json') -Raw | ConvertFrom-Json
35 $release = Join-Path $installRoot $current.activeDir
36 $source = Get-Content -LiteralPath (Join-Path $release 'app/resources/build.json') -Raw | ConvertFrom-Json
37 if ($current.activeVersion -ne $ExpectedVersion -or $source.version -ne $ExpectedVersion) {
38 throw 'Upgrade acceptance package version does not match the expected version.'
39 }
40 if ([string]$source.commit -notmatch '^[0-9a-fA-F]{40}$') {
41 throw 'Packaged build.json must contain a full source commit before recording acceptance.'
42 }
43 New-Item -ItemType Directory -Path $evidence | Out-Null
44 $fixtureHome = Join-Path $evidence 'home # %20 中文'
45 $fixtureReport = Join-Path $evidence 'fixture.json'
46 Invoke-UpgradeFixture $fixtureBuilder @('--mode', 'create', '--home', $fixtureHome, '--report', $fixtureReport)
47 $fixture = Get-Content -LiteralPath $fixtureReport -Raw | ConvertFrom-Json
48 if ([string]::IsNullOrWhiteSpace($fixture.visibleText)) { throw 'Fixture assistant body marker is missing.' }
49 foreach ($phase in @('first', 'restart')) {
50 Invoke-UpgradeStartup $installRoot $ExpectedVersion $fixtureHome $fixture.visibleText (Join-Path $evidence $phase) ($phase -eq 'first')
51 Invoke-UpgradeFixture $fixtureBuilder @('--mode', 'verify', '--home', $fixtureHome, '--report', $fixtureReport, '--phase', $phase)
52 }
53 @{
54 version = $ExpectedVersion
55 sourceSha = $source.commit
56 applicationSha256 = (Get-FileHash -Algorithm SHA256 -LiteralPath $application).Hash
57 oldDataUpgrade = 'passed'
58 restart = 'passed'
59 visibleHistory = 'passed'
60 registryBackup = 'passed'
61 topicUnknownData = 'passed'
62 } | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $evidence 'result.json') -Encoding utf8
63 }
64
65 if ($MyInvocation.InvocationName -ne '.') { Invoke-WindowsUpgradeAcceptance @PSBoundParameters }
66
66 lines Plain Text