<# .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 = '', [switch]$RequireSlim, # 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" msys2 = "reims-runtime-msys2-src-$Commit.tar.zst" sums = 'SHA256SUMS.txt' } $symbolsName = "reims-runtime-symbols-$Commit" if ($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" } $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' } # 4. QEMU runs from the bundle alone and has the reims device. $qemuBin = Join-Path $root '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) { $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 $root "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' } } 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 }