Files
reims-vgpu/packaging/windows-runtime/scripts/check-runtime-alpha.ps1
T
YXC0915 fef2071024 Package and verify a self-contained wire-2 mode in the mainline runtime
Pin the compatibility payload and both corresponding-source archives by SHA-256. Exercise the two QEMU installations and record their separate driver and suspend families in one deliverable.
2026-12-07 07:09:38 +08:00

235 lines
13 KiB
PowerShell

<#
.SYNOPSIS
Entry gate for the alpha channel (portable-runtime-spec.md section 6), run by
CI on the packed release files before anything is published.
.DESCRIPTION
Fails unless all of these hold:
1. The runtime, both source packages and SHA256SUMS.txt exist. Slim
releases also require the matching detached symbols archive.
2. SHA256SUMS.txt lists all release archives and every hash matches.
3. manifest.json in the runtime names -Commit, channel "alpha", the source
package, and exactly the patches in -AppliedPatches.
4. The runtime's own qemu-system-x86_64.exe, run with a PATH holding only
the runtime and Windows (no MSYS2), lists reims-graphics-pci in
"-device help".
This is not the stable gate: promotion to stable still needs the real-host
smoke test (scripts/smoke-runtime.ps1) and a person's approval.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$OutDir,
[Parameter(Mandatory = $true)]
[string]$Commit,
[Parameter(Mandatory = $true)]
[string]$Zstd,
[string[]]$AppliedPatches = @(),
[string]$RequiredCapability = '',
[string]$RequiredSuspendCompatID = '',
[string]$RequiredPackagingCommit = '',
[string]$RuntimeFeaturesFile = '',
[switch]$RequireSlim,
[switch]$SkipMsys2Sources,
[switch]$SkipSymbols,
# Only for checking packages built before the 2026-11-28 rename ("candidate").
[string]$ExpectChannel = 'alpha',
[string]$TempRoot = $env:RUNNER_TEMP
)
$ErrorActionPreference = 'Stop'
$AppliedPatches = @($AppliedPatches | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
$names = @{
runtime = "reims-runtime-win-x64-$Commit.tar.zst"
source = "reims-runtime-src-$Commit.tar.zst"
sums = 'SHA256SUMS.txt'
}
if (-not $SkipMsys2Sources) {
$names.msys2 = "reims-runtime-msys2-src-$Commit.tar.zst"
}
$symbolsName = "reims-runtime-symbols-$Commit"
if ((-not $SkipSymbols) -and ($RequireSlim -or (Test-Path -LiteralPath (Join-Path $OutDir "$symbolsName.tar.zst")))) {
$names.symbols = "$symbolsName.tar.zst"
}
# 1. All assets for this layout.
foreach ($k in $names.Keys) {
$p = Join-Path $OutDir $names[$k]
if (-not (Test-Path -LiteralPath $p)) { throw "Missing release asset: $($names[$k])" }
}
Write-Host "PASS $($names.Count) release assets present"
# 2. Sums cover the archives and match.
$sums = @{}
foreach ($line in Get-Content -LiteralPath (Join-Path $OutDir $names.sums)) {
if ($line -match '^([0-9a-fA-F]{64})\s+\*?(.+)$') { $sums[$Matches[2].Trim()] = $Matches[1].ToLowerInvariant() }
}
foreach ($k in ($names.Keys | Where-Object { $_ -ne 'sums' })) {
$n = $names[$k]
if (-not $sums.ContainsKey($n)) { throw "SHA256SUMS.txt has no entry for $n" }
$got = (Get-FileHash -Algorithm SHA256 -LiteralPath (Join-Path $OutDir $n)).Hash.ToLowerInvariant()
if ($got -ne $sums[$n]) { throw "SHA256 mismatch for ${n}: listed $($sums[$n]), actual $got" }
}
Write-Host 'PASS SHA256SUMS.txt covers and matches all archives'
# Extract the runtime.
$work = Join-Path $TempRoot ("alpha-gate-" + [guid]::NewGuid())
New-Item -ItemType Directory -Force -Path $work | Out-Null
try {
$tar = Join-Path $work 'runtime.tar'
& $Zstd -d -q -f (Join-Path $OutDir $names.runtime) -o $tar
if ($LASTEXITCODE -ne 0) { throw "zstd failed ($LASTEXITCODE)" }
# Windows' own bsdtar: GNU tar from Git/MSYS2 reads "D:" as a remote host.
& (Join-Path $env:SystemRoot 'System32\tar.exe') -xf $tar -C $work
if ($LASTEXITCODE -ne 0) { throw "tar failed ($LASTEXITCODE)" }
Remove-Item -LiteralPath $tar -Force
$root = Join-Path $work "reims-runtime-win-x64-$Commit"
# 3. Manifest states what was really built.
$m = Get-Content -Raw -LiteralPath (Join-Path $root 'manifest.json') | ConvertFrom-Json
if ($m.commit -ne $Commit) { throw "manifest commit is $($m.commit), expected $Commit" }
if ($m.channel -ne $ExpectChannel) { throw "manifest channel is $($m.channel), expected $ExpectChannel" }
if ($m.source_package -ne $names.source) { throw "manifest source_package is $($m.source_package), expected $($names.source)" }
if ($RequiredCapability -and $RequiredCapability -notin $m.capabilities) { throw "manifest lacks capability $RequiredCapability" }
if ($RequiredSuspendCompatID -and ($m.suspend_compat_id -cne $RequiredSuspendCompatID -or
$Commit -cnotmatch ('^' + [regex]::Escape($RequiredSuspendCompatID) + '(?:-p[1-9][0-9]*)?$'))) {
throw "manifest suspend_compat_id is $($m.suspend_compat_id), expected $RequiredSuspendCompatID for $Commit"
}
if ($RequiredPackagingCommit -and $m.packaging_commit -cne $RequiredPackagingCommit) {
throw "manifest packaging_commit is $($m.packaging_commit), expected $RequiredPackagingCommit"
}
$files = @(Get-ChildItem -LiteralPath $root -Recurse -File)
if ($m.file_count -ne $files.Count) { throw "manifest file_count is $($m.file_count), actual $($files.Count)" }
$rawBytes = [int64](($files | Measure-Object Length -Sum).Sum)
if ($m.raw_bytes -ne $rawBytes) { throw "manifest raw_bytes is $($m.raw_bytes), actual $rawBytes" }
$declared = @($m.patches | ForEach-Object { $_.name })
if (($declared -join ',') -ne ($AppliedPatches -join ',')) {
throw "manifest patches [$($declared -join ', ')] differ from those applied [$($AppliedPatches -join ', ')]"
}
Write-Host "PASS manifest: commit $Commit, channel $($m.channel), patches [$($declared -join ', ')]"
if ($m.symbols_package -or $names.symbols) {
if (!$names.symbols -or $m.symbols_package -ne $names.symbols) { throw 'Missing or mismatched symbols package' }
$symTar = Join-Path $work 'symbols.tar'
& $Zstd -d -q -f (Join-Path $OutDir $names.symbols) -o $symTar
if ($LASTEXITCODE) { throw 'Cannot decompress symbols package' }
$members = & (Join-Path $env:SystemRoot 'System32\tar.exe') -tf $symTar
if ($LASTEXITCODE) { throw 'Cannot list symbols package' }
foreach ($rel in 'bin/reims-ctl.exe','bin/reims-util.exe','qemu/bin/qemu-system-x86_64.exe','qemu/bin/qemu-img.exe','qemu/bin/reims-vgpu-compile.exe') {
$hash = (Get-FileHash -LiteralPath (Join-Path $root $rel) -Algorithm SHA256).Hash
if ($hash -ne $m.sha256.$rel) { throw "Manifest hash mismatch for $rel" }
if ("$symbolsName/$rel.debug" -notin $members) { throw "Missing debug file for $rel" }
}
foreach ($rel in 'qemu/bin/libva.dll','qemu/bin/libva_win32.dll','qemu/bin/vaon12_drv_video.dll','NOTICE.md','MSYS2-PACKAGES.txt') {
if (!(Test-Path -LiteralPath (Join-Path $root $rel) -PathType Leaf)) { throw "Missing runtime dependency: $rel" }
}
Write-Host 'PASS stripped executable hashes, detached debug members and video driver files'
} elseif ($RequireSlim) {
foreach ($rel in 'bin/reims-ctl.exe','bin/reims-util.exe','qemu/bin/qemu-system-x86_64.exe','qemu/bin/qemu-img.exe','qemu/bin/reims-vgpu-compile.exe') {
$hash = (Get-FileHash -LiteralPath (Join-Path $root $rel) -Algorithm SHA256).Hash
if ($hash -ne $m.sha256.$rel) { throw "Manifest hash mismatch for $rel" }
}
foreach ($rel in 'qemu/bin/libva.dll','qemu/bin/libva_win32.dll','qemu/bin/vaon12_drv_video.dll','NOTICE.md','MSYS2-PACKAGES.txt') {
if (!(Test-Path -LiteralPath (Join-Path $root $rel) -PathType Leaf)) { throw "Missing runtime dependency: $rel" }
}
Write-Host 'PASS stripped executable hashes and video driver files (light alpha)'
}
$profiles = @($root)
if ($RuntimeFeaturesFile) {
$features = Get-Content -Raw -LiteralPath $RuntimeFeaturesFile | ConvertFrom-Json
if (($m.capabilities -contains 'bundled-wire2-rollback-v1') -ne [bool]$features.wire2_component) {
throw 'The compatibility profile does not match the source revision'
}
if ($features.wire2_component) {
if ($features.wire2_component.full_commit -cne $m.compatibility.wire2.full_commit) {
throw 'The bundled compatibility source commit does not match its pin'
}
foreach ($key in 'manifest','runtime','source','msys2_source') {
if ($features.wire2_component.sha256.$key -cne $m.compatibility.wire2.sha256.$key) {
throw "Incorrect bundled wire-2 pin: $key"
}
}
}
}
if ($m.capabilities -contains 'bundled-wire2-rollback-v1') {
$compat = $m.compatibility.wire2
$nested = Join-Path $root 'compat/wire2'
$nestedManifest = Join-Path $nested 'manifest.json'
$digest = (Get-FileHash -Algorithm SHA256 -LiteralPath $nestedManifest).Hash.ToLowerInvariant()
if ($digest -cne $m.sha256.'compat/wire2/manifest.json' -or $digest -cne $compat.sha256.manifest) {
throw 'Bundled wire-2 manifest mismatch'
}
$cm = Get-Content -Raw -LiteralPath $nestedManifest | ConvertFrom-Json
if ($cm.full_commit -cnotmatch '^[0-9a-f]{40}$' -or $cm.full_commit -cne $compat.full_commit -or
$cm.commit -cne $cm.full_commit.Substring(0, 7) -or $cm.suspend_compat_id -cne $cm.commit -or
$cm.suspend_compat_id -ceq $m.suspend_compat_id) { throw 'Invalid compatibility family' }
foreach ($field in 'vendor_qemu_commit','metal2vulkan_commit','util_commit','packaging_commit') {
if ($cm.$field -cnotmatch '^[0-9a-f]{40}$' -or $cm.$field -cne $compat.$field) {
throw "Bundled wire-2 provenance mismatch for $field"
}
}
foreach ($rel in 'bin/reims-ctl.exe','bin/reims-util.exe','qemu/bin/qemu-system-x86_64.exe','qemu/bin/qemu-img.exe','qemu/bin/reims-vgpu-compile.exe') {
if ((Get-FileHash -LiteralPath (Join-Path $nested $rel) -Algorithm SHA256).Hash -ne $cm.sha256.$rel) {
throw "Bundled wire-2 executable mismatch: $rel"
}
}
$srcTar = Join-Path $work 'sources.tar'
& $Zstd -d -q -f (Join-Path $OutDir $names.source) -o $srcTar
if ($LASTEXITCODE) { throw 'Cannot decompress the corresponding sources' }
foreach ($kind in 'source','msys2_source') {
$suffix = if ($kind -eq 'source') { 'src' } else { 'msys2-src' }
$rel = "compat/wire2/reims-runtime-$suffix-$($cm.commit).tar.zst"
if ($rel -cne $compat."${kind}_package") { throw "Invalid wire-2 $kind path" }
$member = "reims-runtime-src-$Commit/$rel"
& (Join-Path $env:SystemRoot 'System32/tar.exe') -xf $srcTar -C $work $member
if ($LASTEXITCODE -or (Get-FileHash -LiteralPath (Join-Path $work $member) -Algorithm SHA256).Hash -ne $compat.sha256.$kind) {
throw "Missing or mismatched wire-2 corresponding source: $rel"
}
}
$profiles += $nested
Write-Host "PASS wire-2 component $($cm.commit), independent compatibility family, matched sources and executable hashes"
}
# 4. Each supplied profile runs without MSYS2 and has the reims device.
foreach ($profileRoot in $profiles) {
$qemuBin = Join-Path $profileRoot 'qemu\bin'
$psi = [Diagnostics.ProcessStartInfo]::new((Join-Path $qemuBin 'qemu-system-x86_64.exe'), '-device help')
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.WorkingDirectory = $qemuBin
$psi.Environment['PATH'] = "$qemuBin;$env:SystemRoot\System32;$env:SystemRoot"
$proc = [Diagnostics.Process]::Start($psi)
$errTask = $proc.StandardError.ReadToEndAsync()
$out = $proc.StandardOutput.ReadToEnd()
if (-not $proc.WaitForExit(120000)) { $proc.Kill(); throw 'qemu -device help timed out' }
$err = $errTask.Result
if ($proc.ExitCode -ne 0) { throw "qemu -device help exited $($proc.ExitCode): $err" }
if ($out -notmatch 'reims-graphics-pci') { throw "qemu -device help does not list reims-graphics-pci`n$out`n$err" }
Write-Host 'PASS qemu-system-x86_64 -device help lists reims-graphics-pci (no MSYS2 on PATH)'
if ($names.symbols -or $RequireSlim) {
$oldPath = $env:PATH
$img = Join-Path $qemuBin 'qemu-img.exe'
try {
$env:PATH = $psi.Environment['PATH']
foreach ($exe in 'reims-ctl.exe','reims-util.exe') {
& (Join-Path $profileRoot "bin/$exe") --version
if ($LASTEXITCODE) { throw "$exe --version failed ($LASTEXITCODE)" }
}
$disk = Join-Path $work 'test.qcow2'
& $img create -f qcow2 $disk 32M
if ($LASTEXITCODE) { throw "qemu-img create failed ($LASTEXITCODE)" }
$info = & $img info --output=json $disk
if ($LASTEXITCODE -or (($info -join "`n" | ConvertFrom-Json).'virtual-size' -ne 32MB)) { throw 'qemu-img info failed' }
Remove-Item -LiteralPath $disk -Force
} finally { $env:PATH = $oldPath }
Write-Host 'PASS CLI versions and qcow2 creation / inspection (no MSYS2 on PATH)'
}
}
} finally {
Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue
}