Files

192 lines
7.7 KiB
PowerShell

<#
.SYNOPSIS
Real-host smoke test for an alpha portable reims-vgpu runtime archive.
.DESCRIPTION
Implements docs/portable-runtime-spec.md section 6 (alpha -> stable gate):
1. Verifies SHA256 against SHA256SUMS.txt (when provided).
2. Extracts the runtime into an isolated directory under -TempRoot (never C:).
3. Verifies manifest.json provenance, NOTICE.md, licenses/, and core binaries.
4. Runs `reims-ctl doctor` and `reims-ctl list --json` in a clean environment
stripped of MSYS2 / Cargo paths to prove true portability.
5. Writes a Markdown report for human review before promoting to `stable`.
.EXAMPLE
powershell -ExecutionPolicy Bypass -File scripts/smoke-runtime.ps1 `
-ArchivePath D:\Data\reims-go\releases\reims-runtime-win-x64-3731afd.tar.zst `
-Sha256File D:\Data\reims-go\releases\SHA256SUMS.txt
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$ArchivePath,
[string]$Sha256File = '',
[string]$TempRoot = 'D:\Build\Temp',
[string]$ReportOut = ''
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path -LiteralPath $ArchivePath)) {
throw "Archive not found: $ArchivePath"
}
$archiveFile = Get-Item -LiteralPath $ArchivePath
$actualHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $ArchivePath).Hash.ToLowerInvariant()
$hashStatus = 'skipped (no -Sha256File provided)'
if ($Sha256File -ne '') {
if (-not (Test-Path -LiteralPath $Sha256File)) {
throw "SHA256SUMS file not found: $Sha256File"
}
$matched = $false
foreach ($line in (Get-Content -LiteralPath $Sha256File)) {
if ($line -match '^([0-9a-fA-F]{64})\s+\*?(.+)$') {
$h = $Matches[1].ToLowerInvariant()
$n = $Matches[2].Trim()
if ($n -eq $archiveFile.Name) {
if ($h -ne $actualHash) {
throw "SHA256 mismatch for $($archiveFile.Name): expected $h, got $actualHash"
}
$matched = $true
break
}
}
}
if (-not $matched) {
throw "Entry for $($archiveFile.Name) not found in $Sha256File"
}
$hashStatus = "PASS ($actualHash)"
}
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$smokeDir = Join-Path $TempRoot "smoke-$stamp"
$extractDir = Join-Path $smokeDir 'runtime'
$dataDir = Join-Path $smokeDir 'data'
New-Item -ItemType Directory -Force -Path $extractDir, $dataDir | Out-Null
function Resolve-Zstd {
@(
(Get-Command zstd.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source),
'D:\DevTools\msys64\usr\bin\zstd.exe',
'C:\msys64\usr\bin\zstd.exe'
) | Where-Object { $_ -and (Test-Path -LiteralPath $_) } | Select-Object -First 1
}
try {
Write-Host "[1/5] Extracting $($archiveFile.Name) into $extractDir..."
if ($archiveFile.Name.EndsWith('.tar.zst')) {
$zstd = Resolve-Zstd
if (-not $zstd) { throw 'zstd.exe not found to extract .tar.zst' }
$tarPath = Join-Path $smokeDir 'runtime.tar'
& $zstd -d -f -q $ArchivePath -o $tarPath
if ($LASTEXITCODE -ne 0) { throw "zstd decompress failed ($LASTEXITCODE)" }
& tar.exe -xf $tarPath -C $extractDir
if ($LASTEXITCODE -ne 0) { throw "tar extract failed ($LASTEXITCODE)" }
Remove-Item -LiteralPath $tarPath -Force
} elseif ($archiveFile.Name.EndsWith('.zip')) {
Expand-Archive -LiteralPath $ArchivePath -DestinationPath $extractDir -Force
} else {
throw "Unsupported archive format: $($archiveFile.Name)"
}
# Handle single top-level folder inside archive.
$rootDir = $extractDir
$children = @(Get-ChildItem -LiteralPath $extractDir)
if ($children.Count -eq 1 -and $children[0].PSIsContainer) {
$rootDir = $children[0].FullName
}
Write-Host "[2/5] Checking manifest.json, compliance files, and core binaries..."
$required = @(
'manifest.json',
'NOTICE.md',
'licenses',
'bin\reims-ctl.exe',
'bin\reims-util.exe',
'qemu\bin\qemu-system-x86_64.exe',
'qemu\bin\qemu-img.exe'
)
foreach ($rel in $required) {
$p = Join-Path $rootDir $rel
if (-not (Test-Path -LiteralPath $p)) {
throw "Missing required runtime asset: $rel"
}
}
$manifest = Get-Content -Raw -LiteralPath (Join-Path $rootDir 'manifest.json') | ConvertFrom-Json
$patchList = @()
if ($manifest.patches) {
$patchList = @($manifest.patches | ForEach-Object { $_.name })
}
Write-Host "[3/5] Running reims-ctl doctor in a clean MSYS2-free environment..."
$cleanEnv = @{
'XDG_CONFIG_HOME' = (Join-Path $dataDir 'config')
'XDG_DATA_HOME' = (Join-Path $dataDir 'data')
'XDG_CACHE_HOME' = (Join-Path $dataDir 'cache')
'TEMP' = (Join-Path $dataDir 'tmp')
'TMP' = (Join-Path $dataDir 'tmp')
'REIMS_CTL_QEMU' = (Join-Path $rootDir 'qemu')
'PATH' = "$($env:SystemRoot)\System32;$($env:SystemRoot)"
}
New-Item -ItemType Directory -Force -Path $cleanEnv['XDG_CONFIG_HOME'], $cleanEnv['XDG_DATA_HOME'], $cleanEnv['XDG_CACHE_HOME'], $cleanEnv['TEMP'] | Out-Null
function Invoke-CleanCtl([string[]]$ctlArgs) {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = (Join-Path $rootDir 'bin\reims-ctl.exe')
$psi.Arguments = ($ctlArgs -join ' ')
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.CreateNoWindow = $true
foreach ($k in $cleanEnv.Keys) {
$psi.EnvironmentVariables[$k] = $cleanEnv[$k]
}
$proc = [System.Diagnostics.Process]::Start($psi)
$stdout = $proc.StandardOutput.ReadToEnd()
$stderr = $proc.StandardError.ReadToEnd()
$proc.WaitForExit()
return @{ Code = $proc.ExitCode; Stdout = $stdout; Stderr = $stderr }
}
$doctorRes = Invoke-CleanCtl @('doctor')
Write-Host "[4/5] Running reims-ctl list --json..."
$listRes = Invoke-CleanCtl @('list', '--json')
if ($listRes.Code -ne 0) {
throw "reims-ctl list --json failed ($($listRes.Code)): $($listRes.Stderr)"
}
Write-Host "[5/5] Generating smoke report..."
$reportLines = @(
"# Runtime Smoke Test Report",
"",
"- **Tested at**: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzz')",
"- **Host**: $([Environment]::MachineName) ($([Environment]::OSVersion.VersionString))",
"- **Archive**: $($archiveFile.Name) ($([math]::Round($archiveFile.Length / 1MB, 1)) MB)",
"- **SHA256 check**: $hashStatus",
"- **Upstream commit**: $($manifest.commit) (channel: $($manifest.channel))",
"- **vendor/qemu commit**: $($manifest.vendor_qemu_commit)",
"- **Patches**: $(if ($patchList.Count -gt 0) { $patchList -join ', ' } else { 'none (pure upstream)' })",
"- **Source package declared**: $($manifest.source_package)",
"- **reims-ctl list --json**: PASS (exit $($listRes.Code))",
"- **reims-ctl doctor exit code**: $($doctorRes.Code)",
"",
"## reims-ctl doctor output",
'```text',
$doctorRes.Stdout.TrimEnd(),
'```'
)
$report = $reportLines -join "`n"
if ($ReportOut -ne '') {
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $ReportOut) | Out-Null
[IO.File]::WriteAllText($ReportOut, $report + "`n", [Text.UTF8Encoding]::new($false))
Write-Host "Smoke report written to: $ReportOut"
} else {
Write-Host "`n$report"
}
Write-Host "`nSmoke test finished. Human review required before promoting alpha -> stable."
} finally {
if (Test-Path -LiteralPath $smokeDir) {
Remove-Item -LiteralPath $smokeDir -Recurse -Force -ErrorAction SilentlyContinue
}
}