Files
isphere-ai-bridge/scripts/verify-send-capability-test-package.ps1
2026-07-10 14:36:15 +08:00

107 lines
4.0 KiB
PowerShell

param(
[string]$OutputDir = "runs/send-capability-test-package"
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$repo = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")).Path
$packageScript = Join-Path $repo "scripts\package-send-capability-test.ps1"
function Assert-True([bool]$Condition, [string]$Message) {
if (-not $Condition) {
throw $Message
}
}
if (-not (Test-Path -LiteralPath $packageScript)) {
throw "missing package script: $packageScript"
}
$packageRoot = Join-Path $repo $OutputDir
$zipPath = "$packageRoot.zip"
if (Test-Path -LiteralPath $packageRoot) {
Remove-Item -LiteralPath $packageRoot -Recurse -Force
}
if (Test-Path -LiteralPath $zipPath) {
Remove-Item -LiteralPath $zipPath -Force
}
& powershell -NoProfile -ExecutionPolicy Bypass -File $packageScript -OutputDir $OutputDir
if ($LASTEXITCODE -ne 0) {
throw "package-send-capability-test.ps1 failed with exit code $LASTEXITCODE"
}
$requiredFiles = @(
"README.txt",
"EXPECTED-RESULTS.txt",
"run-capability-test.bat",
"isphere-capability-smoke.exe",
"runs\win-helper\ISphereWinHelper.exe"
)
foreach ($relative in $requiredFiles) {
$path = Join-Path $packageRoot $relative
if (-not (Test-Path -LiteralPath $path)) {
throw "missing package file: $relative"
}
}
$readme = Get-Content -LiteralPath (Join-Path $packageRoot "README.txt") -Raw
$expected = Get-Content -LiteralPath (Join-Path $packageRoot "EXPECTED-RESULTS.txt") -Raw
$runner = Get-Content -LiteralPath (Join-Path $packageRoot "run-capability-test.bat") -Raw
foreach ($needle in @(
"LOCAL_LOGIN_UNAVAILABLE",
"NO_REAL_SEND",
"isphere-capability-smoke.exe",
"tool_count",
"production_send_enabled"
)) {
if ($readme -notmatch [regex]::Escape($needle) -and $expected -notmatch [regex]::Escape($needle) -and $runner -notmatch [regex]::Escape($needle)) {
throw "package instructions missing required phrase: $needle"
}
}
if (-not (Test-Path -LiteralPath $zipPath)) {
throw "missing package zip: $zipPath"
}
$smokeOutput = $null
Push-Location $packageRoot
try {
$smokeOutput = & ".\isphere-capability-smoke.exe"
if ($LASTEXITCODE -ne 0) {
throw "isphere-capability-smoke.exe failed with exit code $LASTEXITCODE"
}
}
finally {
Pop-Location
}
$smokeOutput | ForEach-Object { Write-Host $_ }
$lastLine = @($smokeOutput | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) | Select-Object -Last 1
Assert-True (-not [string]::IsNullOrWhiteSpace($lastLine)) "smoke output was empty"
$smokeJson = $lastLine | ConvertFrom-Json
Assert-True ($smokeJson.ok -eq $true) "smoke ok mismatch: $($smokeJson.ok)"
Assert-True ($smokeJson.helper_name -eq "ISphereWinHelper") "smoke helper_name mismatch: $($smokeJson.helper_name)"
Assert-True ($smokeJson.tool_count -eq 9) "smoke tool_count mismatch: $($smokeJson.tool_count)"
Assert-True ($smokeJson.send_preview_tool_present -eq $true) "smoke send_preview_tool_present mismatch: $($smokeJson.send_preview_tool_present)"
Assert-True ($smokeJson.production_send_enabled -eq $false) "smoke production_send_enabled mismatch: $($smokeJson.production_send_enabled)"
Assert-True ($smokeJson.local_login_required -eq $false) "smoke local_login_required mismatch: $($smokeJson.local_login_required)"
Assert-True ($smokeJson.real_isphere_login_required -eq $false) "smoke real_isphere_login_required mismatch: $($smokeJson.real_isphere_login_required)"
Assert-True ($smokeJson.no_real_send -eq $true) "smoke no_real_send mismatch: $($smokeJson.no_real_send)"
[ordered]@{
ok = $true
package_dir = (Resolve-Path -LiteralPath $packageRoot).Path
zip = (Resolve-Path -LiteralPath $zipPath).Path
required_file_count = $requiredFiles.Count
smoke_tool_count = $smokeJson.tool_count
helper_name = $smokeJson.helper_name
send_preview_tool_present = $smokeJson.send_preview_tool_present
production_send_enabled = $smokeJson.production_send_enabled
local_login_required = $false
no_real_send = $true
} | ConvertTo-Json -Depth 6 -Compress