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:
@@ -256,6 +256,78 @@ else
|
|||||||
check '--status reports stopped' 1
|
check '--status reports stopped' 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
say ''
|
||||||
|
say 'Offline import (proxy unreachable)'
|
||||||
|
# Every proxy variable points at a black hole, so a request that consults the
|
||||||
|
# system proxy fails instead of reaching 127.0.0.1. That is the shape of the
|
||||||
|
# bug where an import with the network unplugged reported that it could not
|
||||||
|
# reach the engine: the engine was fine, the request was routed through a proxy.
|
||||||
|
PROXY_VARS=(HTTP_PROXY HTTPS_PROXY ALL_PROXY http_proxy https_proxy all_proxy GLOBAL_AGENT_HTTP_PROXY)
|
||||||
|
for var in "${PROXY_VARS[@]}"; do export "$var=http://10.255.255.1:9"; done
|
||||||
|
unset NO_PROXY no_proxy
|
||||||
|
|
||||||
|
check 'app window bypasses proxies' "$(grep -q -- '--no-proxy-server' "$BUNDLE/luminary" && echo 0 || echo 1)"
|
||||||
|
|
||||||
|
"$BUNDLE/luminary" >"$WORK_DIR/offline-start.txt" 2>&1
|
||||||
|
offline_start=$?
|
||||||
|
check 'launcher starts with the proxy unreachable' "$offline_start" "$(head -n 1 "$WORK_DIR/offline-start.txt")"
|
||||||
|
|
||||||
|
OFFLINE_URL=""
|
||||||
|
if [ -f "$LUMINARY_DATA/runtime.json" ]; then
|
||||||
|
OFFLINE_URL="http://127.0.0.1:$("$NODE" -p "JSON.parse(require('fs').readFileSync('$LUMINARY_DATA/runtime.json','utf8')).port")"
|
||||||
|
check 'runtime.json written offline' 0
|
||||||
|
else
|
||||||
|
check 'runtime.json written offline' 1 "$LUMINARY_DATA/runtime.json"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$OFFLINE_URL" ]; then
|
||||||
|
code="$(http GET "$OFFLINE_URL/api/health")"
|
||||||
|
check 'health answers offline' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code"
|
||||||
|
|
||||||
|
# An import is an upload, a decode in the bundle and a preview read. TIFF
|
||||||
|
# takes the same server path as camera raw, so this exercises the real thing
|
||||||
|
# without shipping a raw fixture in the bundle.
|
||||||
|
"$NODE" -e '
|
||||||
|
const path = require("node:path");
|
||||||
|
const sharp = require(path.join(process.argv[1], "app", "node_modules", "sharp"));
|
||||||
|
sharp({ create: { width: 8, height: 8, channels: 3, background: { r: 200, g: 100, b: 50 } } })
|
||||||
|
.tiff()
|
||||||
|
.toFile(process.argv[2])
|
||||||
|
.then(() => process.exit(0))
|
||||||
|
.catch(() => process.exit(1));
|
||||||
|
' "$BUNDLE" "$WORK_DIR/offline-smoke.tiff"
|
||||||
|
check 'prepared a TIFF to import' "$?"
|
||||||
|
|
||||||
|
upload_status="$("$NODE" -e '
|
||||||
|
const fs = require("node:fs");
|
||||||
|
const [url, file, out] = process.argv.slice(-3);
|
||||||
|
fetch(url, { method: "POST", headers: { "Content-Type": "image/tiff" }, body: fs.readFileSync(file) })
|
||||||
|
.then(async (r) => { fs.writeFileSync(out, await r.text()); process.stdout.write(String(r.status)); })
|
||||||
|
.catch(() => process.stdout.write("0"));
|
||||||
|
' "$OFFLINE_URL/api/photos/smoke-offline/original?name=offline-smoke.tiff&mime=image%2Ftiff" "$WORK_DIR/offline-smoke.tiff" "$BODY")"
|
||||||
|
# A new upload is created (201); replacing one answers 200.
|
||||||
|
case "$upload_status" in
|
||||||
|
200|201) upload_ok=0 ;;
|
||||||
|
*) upload_ok=1 ;;
|
||||||
|
esac
|
||||||
|
check 'import upload accepted offline' "$upload_ok" "HTTP $upload_status"
|
||||||
|
|
||||||
|
preview="$(jget previewUrl)"
|
||||||
|
check 'decoded proxy offered offline' $([ -n "$preview" ] && echo 0 || echo 1) "$preview"
|
||||||
|
if [ -n "$preview" ]; then
|
||||||
|
case "$preview" in
|
||||||
|
http*) preview_url="$preview" ;;
|
||||||
|
*) preview_url="$OFFLINE_URL$preview" ;;
|
||||||
|
esac
|
||||||
|
code="$(http GET "$preview_url")"
|
||||||
|
check 'preview readable offline' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$BUNDLE/luminary" --stop >/dev/null 2>&1
|
||||||
|
check 'stopped the offline run' 0
|
||||||
|
for var in "${PROXY_VARS[@]}"; do unset "$var"; done
|
||||||
|
|
||||||
say ''
|
say ''
|
||||||
say 'Window'
|
say 'Window'
|
||||||
skip 'app window opens' 'visual check; the launcher opened nothing during this run'
|
skip 'app window opens' 'visual check; the launcher opened nothing during this run'
|
||||||
|
|||||||
@@ -237,12 +237,15 @@ open_window() {
|
|||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
if browser="$(command -v "$name" 2>/dev/null)"; then
|
if browser="$(command -v "$name" 2>/dev/null)"; then
|
||||||
say "Opening the app window with $name"
|
say "Opening the app window with $name"
|
||||||
|
# --no-proxy-server: the window only ever loads 127.0.0.1, and an
|
||||||
|
# offline machine cannot resolve the system proxy it would otherwise use.
|
||||||
setsid "$browser" \
|
setsid "$browser" \
|
||||||
--app="$url" \
|
--app="$url" \
|
||||||
--user-data-dir="$DATA_DIR/window-profile" \
|
--user-data-dir="$DATA_DIR/window-profile" \
|
||||||
--class=Luminary \
|
--class=Luminary \
|
||||||
--no-first-run \
|
--no-first-run \
|
||||||
--no-default-browser-check \
|
--no-default-browser-check \
|
||||||
|
--no-proxy-server \
|
||||||
>/dev/null 2>&1 &
|
>/dev/null 2>&1 &
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -144,6 +144,70 @@ try {
|
|||||||
Check '/api/sync answers' $false $_.Exception.Message
|
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 ''
|
||||||
Say 'Window (WebView2)'
|
Say 'Window (WebView2)'
|
||||||
if (-not (Test-Path -LiteralPath $windowExe)) {
|
if (-not (Test-Path -LiteralPath $windowExe)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user