提交记录修改scripts/ci-windows-build.ps1+1 −1看文件
修改scripts/test-windows-installation-files.ps1+55 −1看文件
| @@ -53,7 +53,7 @@ try { | ||
| 53 | 53 | Invoke-BuildTool 'node' @('--test', 'internal/cage/browser-clipboard.test.mjs', 'scripts/windows-native-bridge.test.mjs') |
| 54 | 54 | Invoke-BuildTool (Get-BuildCommand @('pwsh.exe', 'pwsh')) @('-NoProfile', '-NonInteractive', '-File', 'scripts/windows-workbench-smoke.test.ps1') |
| 55 | 55 | $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe' |
| 56 | 删除: & (Join-Path $PSScriptRoot 'test-windows-installation-files.ps1') -HelperShell $windowsPowerShell | |
| 56 | 新增: & (Join-Path $PSScriptRoot 'test-windows-installation-files.ps1') -HelperShell $windowsPowerShell -InstallerSmoke | |
| 57 | 57 | if ($Release) { |
| 58 | 58 | & (Join-Path $PSScriptRoot 'prepare-qemu-release.ps1') |
| 59 | 59 | $qemuSource = Join-Path $repository '_output/windows-qemu-sources/full-source.tar.gz' |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | #requires -Version 5.1 |
| 2 | 删除:param([string]$HelperShell = (Get-Process -Id $PID).Path) | |
| 2 | 新增:param([string]$HelperShell = (Get-Process -Id $PID).Path, [switch]$InstallerSmoke) | |
| 3 | 3 | $ErrorActionPreference = 'Stop' |
| 4 | 4 | $helper = Join-Path $PSScriptRoot '../packaging/windows/installation-files.ps1' |
| 5 | 5 | $root = Join-Path ([IO.Path]::GetTempPath()) ('cage-install-files-' + [guid]::NewGuid().ToString('N')) |
| @@ -62,7 +62,61 @@ function Commit([string]$Old, [string]$Stage, [string]$Receipt) { | ||
| 62 | 62 | Invoke-Helper @('-Operation','cleanup','-Source',$backup,'-Target',$Old,'-Receipt',$Receipt) |
| 63 | 63 | return $backup |
| 64 | 64 | } |
| 65 | 新增:function Test-InstallerTransaction { | |
| 66 | 新增: if (!$windows -or $PSVersionTable.PSVersion.Major -lt 7) { throw 'The optional NSIS fixture requires PowerShell 7 on a disposable Windows user.' } | |
| 67 | 新增: $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ClaudeCage' | |
| 68 | 新增: $desktop = Join-Path ([Environment]::GetFolderPath('DesktopDirectory')) 'Cage.lnk' | |
| 69 | 新增: $menu = Join-Path ([Environment]::GetFolderPath('Programs')) 'Cage' | |
| 70 | 新增: if ((Test-Path $key) -or (Test-Path -LiteralPath $desktop) -or (Test-Path -LiteralPath $menu)) { throw 'The NSIS fixture refuses an existing Cage registration or shortcuts.' } | |
| 71 | 新增: $runtime = $false | |
| 72 | 新增: foreach ($hive in @([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryHive]::CurrentUser)) { | |
| 73 | 新增: $base = [Microsoft.Win32.RegistryKey]::OpenBaseKey($hive, [Microsoft.Win32.RegistryView]::Registry32) | |
| 74 | 新增: $client = $base.OpenSubKey('SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}') | |
| 75 | 新增: try { if ($client -and [string]$client.GetValue('pv') -notin @('','0.0.0.0')) { $runtime = $true } } | |
| 76 | 新增: finally { if ($client) { $client.Dispose() }; $base.Dispose() } | |
| 77 | 新增: } | |
| 78 | 新增: if (!$runtime) { Write-Output 'SKIP: quick NSIS transaction needs an existing WebView2 runtime; full installer acceptance is still required.'; return } | |
| 79 | 新增: $scenario = Join-Path $root 'nsis-transaction'; $app = Join-Path $scenario 'payload'; $target = Join-Path $scenario 'empty target' | |
| 80 | 新增: $setup = Join-Path $scenario 'fixture-setup.exe' | |
| 81 | 新增: $reportBase = if ($env:RUNNER_TEMP) { $env:RUNNER_TEMP } else { [IO.Path]::GetTempPath() } | |
| 82 | 新增: $report = Join-Path $reportBase ('cage-smoke-installation-fixture-' + [guid]::NewGuid().ToString('N') + '.json') | |
| 83 | 新增: Write-File (Join-Path $app 'LICENSE.txt') 'Compile-only text payload; no Cage application or VM.' | |
| 84 | 新增: App $app 'fixture' | |
| 85 | 新增: $version = (Get-Content (Join-Path $PSScriptRoot '../VERSION') -Raw).Trim() | |
| 86 | 新增: & (Get-Command makensis.exe -ErrorAction Stop).Source /V2 /INPUTCHARSET UTF8 "/DAPP_DIR=$app" "/DVERSION=$version" "/DVERSION_NUMERIC=$(($version -split '-')[0]).0" "/DFILE_MANIFEST=$app\Cage.install-files.json" "/DOUTPUT_FILE=$setup" (Join-Path $PSScriptRoot '../packaging/windows/Cage.nsi') | |
| 87 | 新增: if ($LASTEXITCODE -ne 0) { throw 'The production NSIS fixture did not compile.' } | |
| 88 | 新增: function Run-Fixture([string]$Executable, [string[]]$Arguments) { | |
| 89 | 新增: $process = Start-Process -FilePath $Executable -ArgumentList $Arguments -PassThru | |
| 90 | 新增: try { | |
| 91 | 新增: if (!$process.WaitForExit(30000)) { $process.Kill($true); $process.WaitForExit(); throw 'The owned NSIS fixture exceeded 30 seconds.' } | |
| 92 | 新增: if ($process.ExitCode -ne 0) { | |
| 93 | 新增: foreach ($path in @($report, "$report.helper.json")) { | |
| 94 | 新增: if ((Test-Path -LiteralPath $path) -and (Get-Item -LiteralPath $path).Length -le 8192) { Write-Output ('Quick NSIS diagnostic: ' + (Get-Content -LiteralPath $path -Raw)) } | |
| 95 | 新增: } | |
| 96 | 新增: throw "The NSIS fixture returned $($process.ExitCode)." | |
| 97 | 新增: } | |
| 98 | 新增: } finally { $process.Dispose() } | |
| 99 | 新增: } | |
| 100 | 新增: try { | |
| 101 | 新增: [IO.Directory]::CreateDirectory($target) | Out-Null | |
| 102 | 新增: Run-Fixture $setup @('/S','/DESKTOPSHORTCUT=0','/STARTMENUSHORTCUT=0',"/DIAGNOSTICS=`"$report`"","/D=$target") | |
| 103 | 新增: Check ((Get-Content (Join-Path $target 'program.txt') -Raw) -eq 'fixture') 'NSIS did not publish its text payload.' | |
| 104 | 新增: Check (!(Test-Path -LiteralPath ($target + '.cage-installation.json'))) 'NSIS left the first-install receipt unfinished.' | |
| 105 | 新增: Check ((Get-ItemProperty $key).InstallLocation -eq $target) 'NSIS registered a different fixture target.' | |
| 106 | 新增: } finally { | |
| 107 | 新增: if (Test-Path $key) { | |
| 108 | 新增: if ((Get-ItemProperty $key).InstallLocation -ne $target) { throw 'NSIS fixture registration changed owner; retained for inspection.' } | |
| 109 | 新增: Run-Fixture (Join-Path $target 'Uninstall.exe') @('/S') | |
| 110 | 新增: $deadline = [DateTime]::UtcNow.AddSeconds(20) | |
| 111 | 新增: while ((Test-Path -LiteralPath $target) -and [DateTime]::UtcNow -lt $deadline) { Start-Sleep -Milliseconds 100 } | |
| 112 | 新增: } | |
| 113 | 新增: } | |
| 114 | 新增: Check (!(Test-Path $key) -and !(Test-Path -LiteralPath $desktop) -and !(Test-Path -LiteralPath $menu)) 'NSIS fixture left registry or shortcut changes.' | |
| 115 | 新增: Check (!(Test-Path -LiteralPath $target)) 'NSIS fixture did not uninstall its owned files.' | |
| 116 | 新增: Write-Output 'PASS: production NSIS silently installed/uninstalled its text-only fixture through PowerShell 5.1 transactions; no application or VM was started.' | |
| 117 | 新增:} | |
| 65 | 118 | try { |
| 119 | 新增: if ($InstallerSmoke) { Test-InstallerTransaction } | |
| 66 | 120 | # A new install has no backup path or existing ownership manifest. |
| 67 | 121 | $scenario = Join-Path $root 'first-install' |
| 68 | 122 | $old = Join-Path $scenario 'empty-destination'; $stage = Join-Path $scenario 'staged'; $receipt = Join-Path $scenario 'receipt.json' |

