Files
luminary/windows/SMOKE-WINDOWS.ps1
T
bhursey f1f96f1f10 Check offline imports in the smoke tests
With the network down, a request that goes through the system proxy cannot
reach 127.0.0.1, which is how a healthy engine looked unreachable. Both smoke
tests now start under a proxy pointed at a black hole, import a TIFF through the
real upload and preview path, and assert the launcher and app window bypass
proxies.
2026-12-01 12:47:06 +00:00

244 lines
10 KiB
PowerShell

<#
One-command smoke test for an extracted Luminary bundle on Windows.
Run it from the extracted bundle folder (or pass -Bundle):
powershell -ExecutionPolicy Bypass -File .\SMOKE-WINDOWS.ps1
It writes smoke-report.txt next to the bundle and prints the same lines.
Exit code 0 means every check passed.
What it covers without a human clicking:
- OS version and architecture, and whether the WebView2 runtime is present
- the bundle files the launcher needs, and -Verify's own result
- a real server boot in desktop mode: /api/health local:true,
/api/auth/me 200 without a cookie, /api/sync 200
- LuminaryWindow.exe launching, staying alive and owning a window titled
Luminary (the native WebView2 path)
- Stop actually stopping the server
It is deliberately conservative: it uses a throwaway data folder under
%TEMP% and a port that is unlikely to collide, so it never touches a real
catalog.
#>
[CmdletBinding()]
param(
[string]$Bundle = (Split-Path -Parent $MyInvocation.MyCommand.Path),
[int]$Port = 8912,
[int]$WindowSeconds = 8
)
$ErrorActionPreference = 'Stop'
$script:lines = @()
$script:failed = 0
function Say([string]$text) {
$script:lines += $text
Write-Host $text
}
function Check([string]$name, [bool]$ok, [string]$detail = '') {
if ($ok) {
Say (" PASS {0}{1}" -f $name, $(if ($detail) { " — $detail" } else { '' }))
} else {
$script:failed += 1
Say (" FAIL {0}{1}" -f $name, $(if ($detail) { " — $detail" } else { '' }))
}
return $ok
}
function Get-WebView2Version {
$keys = @(
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}',
'HKLM:\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}',
'HKCU:\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}'
)
foreach ($key in $keys) {
try {
$value = (Get-ItemProperty -Path $key -Name pv -ErrorAction Stop).pv
if ($value) { return $value }
} catch { }
}
return $null
}
$nodeExe = Join-Path $Bundle 'node.exe'
$appDir = Join-Path $Bundle 'app'
$entry = Join-Path $appDir 'server\index.mjs'
$windowExe = Join-Path $Bundle 'LuminaryWindow.exe'
$launcher = Join-Path $Bundle 'Luminary.ps1'
$dataDir = Join-Path $env:TEMP ('luminary-smoke-{0}' -f [guid]::NewGuid().ToString('N'))
$url = "http://127.0.0.1:$Port"
$server = $null
$window = $null
Say 'Luminary Windows smoke test'
Say (" bundle {0}" -f $Bundle)
Say (" time {0}" -f (Get-Date).ToString('s'))
try {
$os = Get-CimInstance Win32_OperatingSystem
Say ''
Say 'Environment'
Say (" OS {0} (build {1})" -f $os.Caption, $os.BuildNumber)
Say (" arch {0}" -f $env:PROCESSOR_ARCHITECTURE)
$webview2 = Get-WebView2Version
Say (" webview {0}" -f $(if ($webview2) { "runtime $webview2" } else { 'NOT INSTALLED' }))
Say ''
Say 'Bundle'
Check 'node.exe present' (Test-Path -LiteralPath $nodeExe) $nodeExe
Check 'app\server\index.mjs present' (Test-Path -LiteralPath $entry) $entry
Check 'Luminary.ps1 present' (Test-Path -LiteralPath $launcher) $launcher
Check 'LuminaryWindow.exe present' (Test-Path -LiteralPath $windowExe) $windowExe
if (Test-Path -LiteralPath $launcher) {
$verify = Start-Process -FilePath 'powershell.exe' -ArgumentList @(
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $launcher, '-Verify'
) -Wait -PassThru -WindowStyle Hidden
Check '-Verify exits 0' ($verify.ExitCode -eq 0) ("exit {0}" -f $verify.ExitCode)
}
if (-not (Test-Path -LiteralPath $nodeExe)) { throw 'node.exe is missing, cannot start the server' }
if (-not (Test-Path -LiteralPath $entry)) { throw 'app\server\index.mjs is missing, cannot start the server' }
New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
$env:PORT = "$Port"
$env:HOST = '127.0.0.1'
$env:NODE_ENV = 'production'
$env:LUMINARY_DATA = $dataDir
$env:LUMINARY_LOCAL = '1'
Say ''
Say 'Server (desktop mode)'
$server = Start-Process -FilePath $nodeExe -ArgumentList @('"' + $entry + '"') `
-WorkingDirectory $appDir -WindowStyle Hidden -PassThru `
-RedirectStandardOutput (Join-Path $dataDir 'out.log') `
-RedirectStandardError (Join-Path $dataDir 'err.log')
$deadline = (Get-Date).AddSeconds(90)
$health = $null
while ((Get-Date) -lt $deadline) {
try {
$response = Invoke-WebRequest -UseBasicParsing -TimeoutSec 2 -Uri "$url/api/health"
if ($response.StatusCode -eq 200) { $health = $response.Content | ConvertFrom-Json; break }
} catch { }
Start-Sleep -Milliseconds 500
}
Check 'health answers' ($null -ne $health)
if ($health) {
Check 'local mode advertised' ($health.local -eq $true) ("local={0}" -f $health.local)
Check 'no setup prompt' ($health.needsSetup -eq $false)
Check 'registration closed' ($health.registrationOpen -eq $false)
}
try {
$me = Invoke-WebRequest -UseBasicParsing -TimeoutSec 5 -Uri "$url/api/auth/me"
$who = $me.Content | ConvertFrom-Json
Check 'signed in without a cookie' ($me.StatusCode -eq 200) ("{0} ({1})" -f $who.user.email, $who.user.role)
} catch {
Check 'signed in without a cookie' $false $_.Exception.Message
}
try {
$sync = Invoke-WebRequest -UseBasicParsing -TimeoutSec 15 -Uri "$url/api/sync"
Check '/api/sync answers' ($sync.StatusCode -eq 200)
} catch {
Check '/api/sync answers' $false $_.Exception.Message
}
Say ''
Say 'Offline import (proxy unreachable)'
# The failure this guards against: with the network down, anything that asks
# Windows for its proxy/PAC cannot reach 127.0.0.1, so the launcher gave up on
# a healthy engine and the app window reported that it could not reach it.
$launcherText = Get-Content -LiteralPath $launcher -Raw
Check 'health probe uses a direct socket' ($launcherText -match 'TcpClient')
Check 'health probe avoids the proxy stack' ($launcherText -notmatch 'Invoke-WebRequest')
Check 'app window bypasses proxies' ($launcherText -match '--no-proxy-server')
# The import the page performs, run with every proxy variable pointing at a
# black hole: upload, decode in the bundle, read the preview back.
$probe = Join-Path $dataDir 'offline-import.cjs'
Set-Content -LiteralPath $probe -Encoding ASCII -Value @'
const fs = require('node:fs');
const path = require('node:path');
const [bundle, base, dir] = process.argv.slice(2);
const sharp = require(path.join(bundle, 'app', 'node_modules', 'sharp'));
(async () => {
const file = path.join(dir, 'offline-smoke.tiff');
await sharp({ create: { width: 8, height: 8, channels: 3, background: { r: 200, g: 100, b: 50 } } })
.tiff()
.toFile(file);
const health = await fetch(base + '/api/health');
const upload = await fetch(
base + '/api/photos/smoke-offline/original?name=offline-smoke.tiff&mime=image%2Ftiff',
{ method: 'POST', headers: { 'Content-Type': 'image/tiff' }, body: fs.readFileSync(file) },
);
const body = await upload.json().catch(() => ({}));
let preview = 0;
if (body.previewUrl) {
const target = String(body.previewUrl).startsWith('http') ? body.previewUrl : base + body.previewUrl;
preview = (await fetch(target)).status;
}
process.stdout.write(JSON.stringify({ health: health.status, upload: upload.status, preview }));
})().catch((error) => {
process.stdout.write(JSON.stringify({ error: String(error) }));
process.exit(1);
});
'@
$proxyNames = @('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy')
$noProxyNames = @('NO_PROXY', 'no_proxy')
$saved = @{}
foreach ($name in $proxyNames + $noProxyNames) {
$saved[$name] = [Environment]::GetEnvironmentVariable($name, 'Process')
}
try {
foreach ($name in $proxyNames) { Set-Item -Path "env:$name" -Value 'http://10.255.255.1:9' }
foreach ($name in $noProxyNames) { Remove-Item -Path "env:$name" -ErrorAction SilentlyContinue }
$offline = (& $nodeExe $probe $Bundle $url $dataDir | Out-String).Trim()
} finally {
foreach ($name in $proxyNames + $noProxyNames) {
if ($saved[$name]) { Set-Item -Path "env:$name" -Value $saved[$name] }
else { Remove-Item -Path "env:$name" -ErrorAction SilentlyContinue }
}
}
$offlineResult = $null
try { $offlineResult = $offline | ConvertFrom-Json } catch { }
Check 'engine answers with the proxy unreachable' ($null -ne $offlineResult -and $offlineResult.health -eq 200) $(if ($offlineResult) { "health $($offlineResult.health)" } else { $offline })
# A new upload is created (201); replacing one answers 200.
Check 'import upload accepted offline' ($null -ne $offlineResult -and $offlineResult.upload -in @(200, 201)) $(if ($offlineResult) { "upload $($offlineResult.upload)" } else { '' })
Check 'preview decodes offline' ($null -ne $offlineResult -and $offlineResult.preview -eq 200) $(if ($offlineResult) { "preview $($offlineResult.preview)" } else { '' })
Say ''
Say 'Window (WebView2)'
if (-not (Test-Path -LiteralPath $windowExe)) {
Say ' SKIP LuminaryWindow.exe is not in this bundle'
} else {
$window = Start-Process -FilePath $windowExe -ArgumentList @('--url', $url) -PassThru
Start-Sleep -Seconds $WindowSeconds
$window.Refresh()
$alive = -not $window.HasExited
Check 'window process alive' $alive $(if ($alive) { 'pid ' + $window.Id } else { 'exited early' })
if ($alive) {
$title = $window.MainWindowTitle
Check 'window titled Luminary' ($title -eq 'Luminary') ("title '{0}'" -f $title)
}
if (-not $window.HasExited) { Stop-Process -Id $window.Id -Force }
}
} catch {
Say (" ERROR {0}" -f $_.Exception.Message)
$script:failed += 1
} finally {
if ($window -and -not $window.HasExited) { Stop-Process -Id $window.Id -Force -ErrorAction SilentlyContinue }
if ($server -and -not $server.HasExited) { Stop-Process -Id $server.Id -Force -ErrorAction SilentlyContinue }
Remove-Item -LiteralPath $dataDir -Recurse -Force -ErrorAction SilentlyContinue
Say ''
if ($script:failed -eq 0) {
Say 'RESULT: PASS'
} else {
Say ("RESULT: FAIL ({0} check(s))" -f $script:failed)
}
try { $script:lines | Set-Content -LiteralPath (Join-Path $Bundle 'smoke-report.txt') -Encoding UTF8 } catch { }
exit $(if ($script:failed -eq 0) { 0 } else { 1 })
}