// Compose-stack suite (plan step 3.1b): the release images built from this repo, started // with the real docker-compose.yml + proxy config (the one install.sh writes, CS-5), on // their own project name and ports. Checks what only a real stack can show: // - the terminal image is served on :8082 (SPA fallback, its assets, /api and the // WebSocket through both nginx hops) // - the plain-HTTP ports (:8082, and :8081 as a control) refuse a non-LAN address and // answer a LAN one (two docker networks: 100.64.50.0/24 is not in the allow list) // - the proxy still starts when the stack has no terminal container (older compose file) // - a media upload bigger than nginx's 1 MB default gets through the proxy and the manager's // nginx (step 5.1), and its sizes come back with year-long cache headers // - a phone video gets its version for screens inside the backend image (ffmpeg, step 5.4e) // node stack.mjs (builds the images: a few minutes the first time, cached after) import { execFileSync, spawnSync } from 'node:child_process' import { reporter } from './lib/env.mjs' import { composeStack, login, waitHttp } from './lib/proc.mjs' const PROJECT = 'xenia-e2e-stack' const T = 19082 const WAN = 'xenia-e2e-wan' const r = reporter('stack: terminal on :8082 (compose)') const stack = composeStack({ project: PROJECT, version: 'e2es', siteId: 'test-site-1', http: 19080, https: 19443, manager: 19081, terminal: T }) const docker = (...a) => execFileSync('docker', a, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }) /** HTTP status of url fetched from a throwaway container on `network` (busybox wget). */ function statusFrom(network, url) { // busybox wget prints the response headers (-S) on stderr, also for a 200 const res = spawnSync('docker', ['run', '--rm', '--network', network, 'nginx:alpine', 'wget', '-S', '-O', '/dev/null', '-T', '5', url], { encoding: 'utf8' }) return Number(`${res.stdout}${res.stderr}`.match(/HTTP\/1\.\d (\d{3})/)?.[1] || 0) } /** The first frame the backend sends a socket opened through :8082 without credentials. */ function firstFrame(url) { return new Promise(resolve => { const ws = new WebSocket(url) const done = v => { clearTimeout(t); try { ws.close() } catch { /* closed */ } resolve(v) } const t = setTimeout(() => done(null), 15_000) ws.onopen = () => ws.send(JSON.stringify({ cursor: 0 })) ws.onmessage = e => done(JSON.parse(e.data)) ws.onerror = () => done(null) }) } try { try { docker('network', 'rm', WAN) } catch { /* not there */ } await stack.up() const home = await fetch(`http://127.0.0.1:${T}/`) const html = await home.text() r.check('terminal: :8082 serves the terminal app', home.status === 200 && html.includes('Xenia terminal'), `${home.status}`) const deep = await fetch(`http://127.0.0.1:${T}/app/kds`) r.check('terminal: deep links fall back to the app (SPA)', deep.status === 200 && (await deep.text()).includes('Xenia terminal')) const asset = html.match(/src="(\/assets\/[^"]+\.js)"/)?.[1] const js = asset ? await fetch(`http://127.0.0.1:${T}${asset}`) : null r.check('terminal: its script loads', js?.status === 200, asset || 'no script tag') const health = await fetch(`http://127.0.0.1:${T}/api/system/health`) r.check('terminal: /api reaches the backend through :8082', health.status === 200, `${health.status}`) const frame = await firstFrame(`ws://127.0.0.1:${T}/api/ws/connect`) r.check('terminal: the live connection upgrades through both proxies (refused: no credentials)', frame?.type === 'refused' && frame.data?.code === 'auth.session_ended', JSON.stringify(frame)) // Media library (5.1): a 3 MB upload through :8081 (proxy + the manager's nginx) const M = 'http://127.0.0.1:19081' const token = await login(M) const big = new Uint8Array(3 * 1024 * 1024) crypto.getRandomValues(big.subarray(0, 65536)) const form = new FormData() form.append('file', new Blob([big], { type: 'image/jpeg' }), 'big.jpg') const upload = await fetch(`${M}/api/media`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: form }) const refused = await upload.json().catch(() => ({})) r.check('media: a 3 MB upload reaches the backend through both nginx hops (not 413 from nginx)', upload.status === 422 && refused?.error?.code === 'media.type', `${upload.status} ${JSON.stringify(refused).slice(0, 120)}`) const photo = execFileSync('python', ['-c', "import io,sys;from PIL import Image;b=io.BytesIO();Image.new('RGB',(2400,1600),(90,140,60)).save(b,'JPEG');sys.stdout.buffer.write(b.getvalue())"]) const pf = new FormData() pf.append('file', new Blob([photo], { type: 'image/jpeg' }), 'Horiatiki.jpg') const item = await (await fetch(`${M}/api/media`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: pf })).json() const card = item?.urls ? await fetch(`http://127.0.0.1:19080${item.urls.card}`) : null r.check('media: a photo gets its sizes, served on :80 with year-long cache headers', card?.status === 200 && card.headers.get('content-type') === 'image/webp' && /immutable/.test(card.headers.get('cache-control') || ''), `${card?.status} ${card?.headers.get('cache-control')}`) // 5.4e: the backend image carries the video tool: a phone video gets its version for screens const ff = execFileSync('python', ['-c', 'import imageio_ffmpeg as i; print(i.get_ffmpeg_exe())'], { encoding: 'utf8' }).trim() const hevc = execFileSync(ff, ['-hide_banner', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc2=s=2560x1440:r=25:d=2', '-c:v', 'libx265', '-x265-params', 'log-level=error', '-tag:v', 'hvc1', '-metadata', `comment=${Date.now()}`, '-f', 'mov', '-movflags', 'frag_keyframe+empty_moov', 'pipe:1'], { maxBuffer: 64 << 20 }) const vf = new FormData() vf.append('file', new Blob([hevc], { type: 'video/quicktime' }), 'IMG_0001.MOV') const vid = await (await fetch(`${M}/api/media`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: vf })).json() let done = null for (let i = 0; i < 90 && vid?.id && !done; i++) { const m = await (await fetch(`${M}/api/media/${vid.id}`, { headers: { Authorization: `Bearer ${token}` } })).json() if (m.processing === 'done' || m.processing === 'failed' || m.processing == null) done = m else await new Promise(res => setTimeout(res, 1000)) } const play = done?.urls?.play ? await fetch(`http://127.0.0.1:19080${done.urls.play}`, { headers: { Range: 'bytes=0-15' } }) : null r.check('media (5.4e): the backend image makes the version for screens of a phone video (ffmpeg inside), served seekable on :80', vid?.processing === 'waiting' && done?.processing === 'done' && !!done.urls.thumb && play?.status === 206 && play.headers.get('content-type') === 'video/mp4', `${vid?.processing} → ${done?.processing} ${play?.status}`) // LAN vs not: the proxy joins a second network whose addresses aren't private const proxy = stack.compose('ps', '-q', 'proxy').trim() docker('network', 'create', '--subnet', '100.64.50.0/24', WAN) docker('network', 'connect', WAN, proxy) const wanIp = docker('inspect', '-f', `{{(index .NetworkSettings.Networks "${WAN}").IPAddress}}`, proxy).trim() const lan = `${PROJECT}_default` r.check('LAN: :8082 answers a LAN address', statusFrom(lan, 'http://proxy:8082/') === 200) r.check('not LAN: :8082 refuses (403)', statusFrom(WAN, `http://${wanIp}:8082/`) === 403) r.check('not LAN: :8081 refuses too (control)', statusFrom(WAN, `http://${wanIp}:8081/`) === 403) // Leave the non-LAN network first: with it attached, host traffic to the published ports // can arrive through its gateway after the restart below and get 403 (seen once in 3.2a) docker('network', 'disconnect', '-f', WAN, proxy) // An older docker-compose.yml without the terminal service must not take the proxy down stack.compose('rm', '-sf', 'terminal') stack.compose('restart', 'proxy') await waitHttp('http://127.0.0.1:19080/api/system/health', true, 60_000) const gone = await fetch(`http://127.0.0.1:${T}/`).catch(() => null) r.check('no terminal container: the proxy still starts, waiter :80 works, :8082 answers 502', (await fetch('http://127.0.0.1:19080/api/system/health')).status === 200 && gone?.status === 502, `${gone?.status}`) } catch (e) { r.check(`stack: ${e.message.split('\n')[0]}`, false) } finally { try { docker('network', 'disconnect', '-f', WAN, stack.compose('ps', '-q', 'proxy').trim()) } catch { /* not connected */ } stack.down() try { docker('network', 'rm', WAN) } catch { /* gone */ } } process.exit(r.done() ? 1 : 0)