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.
This commit is contained in:
2026-12-01 12:45:04 +00:00
parent 0525e496e0
commit f1f96f1f10
3 changed files with 139 additions and 0 deletions
+64
View File
@@ -144,6 +144,70 @@ try {
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)) {