feat(terminal): terminal app shell, pos-terminal image, LAN-only proxy port 8082 (platform-v2 3.1b)
- terminal/: new workspace app (Vite + React 19 + Router 7, Tailwind on the shared preset, @xenia/i18n namespace `terminal`, @xenia/api client sending X-Xenia-Device, @xenia/access bootstrap). Apps are lazy chunks by app_key (kds, pos_counter, customer_display placeholders); start screen; "unknown app" screen; dev-only /ui-gallery and /i18n-sample. Device + session tokens in a storage wrapper. - Image pos-terminal (terminal/Dockerfile, context client-services/); every frontend Dockerfile copies terminal/package.json for npm ci. - docker-compose(.dev).yml: service terminal; proxy publishes 8082. - Proxy (nginx-proxy/nginx.conf == install.sh heredoc, CS-5): server :8082, LAN-only allow/deny, WebSocket upgrade; the terminal upstream is resolved per request so the proxy still starts on a stack without the terminal container. - install.sh prints the screens address. - Tests: terminal unit tests + lint in run-all; new tests/e2e/stack.mjs (release images on one compose stack: :8082 serves the app, /api + WebSocket through both hops, 403 from a non-LAN docker network on 8082 and 8081, proxy up without terminal). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,8 @@ npm test -w @xenia/api # live client = the waiter's old WebSoc
|
||||
npm test -w @xenia/access # can(): one key, any/all
|
||||
npm test -w manager-dashboard # platform pages' logic: module states, what stops with a module, device status/usage/limits
|
||||
npm run lint -w manager-dashboard # ESLint (waiter rules) on the manager's v2 code; the file list is the `lint` script
|
||||
npm test -w terminal # terminal shell: which apps a screen can run, the device/session token store
|
||||
npm run lint -w terminal # ESLint on all of terminal/src (same rules)
|
||||
```
|
||||
|
||||
**DB tests** (`local_backend/tests/conftest.py`) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: `db` (session, rolled back after each test even if the code commits), `client` (TestClient with `get_db` overridden, license check open, no lifespan), `make_user(role=..., perms=...)` (password `password`, PIN `1234`), `login(user)` (auth headers). A test that uses any of them is marked `db` automatically.
|
||||
@@ -43,6 +45,7 @@ Or run one suite at a time:
|
||||
| `python license_e2e.py` | Offline licensing with a real cloud + site process: 400 days offline, tampered file, clock set back, expiry deferred to workday close, renewal, remote lock | Python deps of both backends | ~2 min |
|
||||
| `node ui.mjs` | `@xenia/ui` components on the dev-only gallery (`/ui-gallery`, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes; `@xenia/i18n` on `/i18n-sample` with the browser in New York: venue time, live language switch, el/en money and numbers, price input, translated component labels | Edge | ~40 s |
|
||||
| `node manager.mjs` | Manager on `@xenia/api`/`@xenia/access` (backend :8057 on a demo DB, manager Vite :5186): bootstrap before/after login, wrong password and wrong lock PIN stay on screen, sidebar from keys, KDS module off → "turned off" screen, session ended elsewhere → /login, a waiter's cancel approved by a manager PIN (wrong PIN first) and audited; Apps, Integrations, License, Devices (pairing played through the API, a device setting chosen when pairing and edited, the screen's live connection told of the edit and closed on app change and removal); the approvals log, "Signed in now" + end session, the staff permission editor (give, reset to role, a staff manager can't give what they lack); the notification bell (live, read, read all), sign-in/venue/print settings, log download; the **owner flow** (sign in → turn on KDS → pair a screen → give a chef the kitchen permissions → the chef signs in on that screen) | Edge | ~1 min |
|
||||
| `node stack.mjs` | The release images + the real `docker-compose.yml` and proxy config on one stack (:19080/:19081/:19082): the terminal on :8082 (app, deep links, assets, `/api`, WebSocket through both nginx hops); :8082 and :8081 refuse a non-LAN address (a second docker network, 100.64.50.0/24) and answer a LAN one; the proxy still starts without a terminal container | Docker | ~3 min (first build longer) |
|
||||
| `node browser.mjs` | Waiter web modes (same-origin, plain HTTP by LAN IP, venue mode), install dialog + drawer entry (Android / iPhone / desktop / no APK) | Docker, Edge | ~2 min |
|
||||
| `node android.mjs basics` | Pairing, wrong address / other venue's QR, login + live WS, back button, restart, two venues, camera permission | Android emulator | ~5 min |
|
||||
| `node android.mjs rediscovery` | Server IP change (logged in / out), server down + manual search, cold start while offline | Android emulator | ~4 min |
|
||||
|
||||
@@ -112,7 +112,7 @@ export async function startViteNative({ port = 5180, backendUrl }) {
|
||||
* Isolated docker-compose stack built from this repo (its own project name,
|
||||
* images, data dir and host ports) — never touches a developer's running stack.
|
||||
*/
|
||||
export function composeStack({ project, version, siteId, http, https, manager, extraEnv = {} }) {
|
||||
export function composeStack({ project, version, siteId, http, https, manager, terminal, extraEnv = {} }) {
|
||||
const dir = path.join(OUT, project)
|
||||
mkdirSync(path.join(dir, 'data'), { recursive: true })
|
||||
mkdirSync(path.join(dir, 'fiscal'), { recursive: true })
|
||||
@@ -138,6 +138,8 @@ export function composeStack({ project, version, siteId, http, https, manager, e
|
||||
ports: !reset []
|
||||
manager_dashboard:
|
||||
ports: !reset []
|
||||
terminal:
|
||||
ports: !reset []
|
||||
netinfo:
|
||||
profiles: ["off"]
|
||||
proxy:
|
||||
@@ -145,7 +147,8 @@ export function composeStack({ project, version, siteId, http, https, manager, e
|
||||
- "${http}:80"
|
||||
- "${manager}:8081"
|
||||
- "${https}:8443"
|
||||
`)
|
||||
${terminal ? ` - "${terminal}:8082"
|
||||
` : ''}`)
|
||||
const args = ['compose', '-p', project, '--env-file', envFile, '-f', 'docker-compose.yml', '-f', 'docker-compose.dev.yml', '-f', ports]
|
||||
const compose = (...a) => execFileSync('docker', [...args, ...a], { cwd: CS, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
return {
|
||||
@@ -159,7 +162,7 @@ export function composeStack({ project, version, siteId, http, https, manager, e
|
||||
},
|
||||
down() {
|
||||
try { compose('down', '-v') } catch {}
|
||||
for (const s of ['backend', 'waiter', 'manager']) {
|
||||
for (const s of ['backend', 'waiter', 'manager', 'terminal']) {
|
||||
try { execFileSync('docker', ['rmi', `e2e/pos-${s}:${version}`], { stdio: 'ignore' }) } catch {}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,11 +14,14 @@ const suites = [
|
||||
['unit: packages/access (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/access'], CS],
|
||||
['unit: manager_dashboard (node --test)', 'npm', ['test', '--silent', '-w', 'manager-dashboard'], CS],
|
||||
['lint: manager_dashboard (v2 code)', 'npm', ['run', 'lint', '--silent', '-w', 'manager-dashboard'], CS],
|
||||
['unit: terminal (node --test)', 'npm', ['test', '--silent', '-w', 'terminal'], CS],
|
||||
['lint: terminal', 'npm', ['run', 'lint', '--silent', '-w', 'terminal'], CS],
|
||||
['install.sh', 'node', ['install.mjs'], E2E],
|
||||
['license (cloud + site)', PYTHON, ['license_e2e.py'], E2E],
|
||||
['browser', 'node', ['browser.mjs'], E2E],
|
||||
['ui (@xenia/ui + @xenia/i18n)', 'node', ['ui.mjs'], E2E],
|
||||
['manager (login, bootstrap, approvals)', 'node', ['manager.mjs'], E2E],
|
||||
['stack (compose: terminal :8082, LAN only)', 'node', ['stack.mjs'], E2E],
|
||||
]
|
||||
if (!process.argv.includes('--no-android')) suites.push(['android (emulator)', 'node', ['android.mjs'], E2E])
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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)
|
||||
// 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, 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('<title>Xenia terminal</title>'), `${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))
|
||||
|
||||
// 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)
|
||||
|
||||
// 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)
|
||||
Reference in New Issue
Block a user