feat(waiter): sign-in v2 on the phones (platform-v2 step 4.2)

- Login follows auth.waiter_login_mode / auth.waiter_require_username from the
  bootstrap: name + PIN, name + password, typed username, or a "paired screens
  only" message for tap mode. POST /api/auth/login {client: "waiter"}; a miss
  shows the translated error without a reload.
- POST /api/auth/login-by-id removed; bootstrap login carries waiter_mode and
  waiter_require_username.
- Sign-out ends the session on the server (POST /api/auth/logout), so
  single_session_waiter = refuse_new no longer strands a waiter.
- Lock on the phone: menu "Lock", automatic lock / sign-out after inactivity
  (security.auto_lock*, auto_logout*), unlock with the PIN in the same session,
  lock kept across app restarts (restore() no longer clears it).
- e2e: new waiter.mjs (22 checks) in run-all; android.mjs signs in for real and
  locks/unlocks on the emulator; TLS live check waits for the socket; the
  rediscovery helper re-attaches to a stale WebView handle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 15:25:00 +02:00
co-authored by Claude Opus 5.5
parent 9f5498332a
commit 8299184e3a
14 changed files with 664 additions and 106 deletions
+40 -12
View File
@@ -71,14 +71,29 @@ async function basics() {
r.check('pairing saves and activates the venue', st?.active === 'test-site-1' && st.venues['test-site-1'].baseUrl.includes(`${H}:`), JSON.stringify(st))
r.check('login screen shows the venue + "Αλλαγή"', (await v.evaluate('document.body.innerText')).includes('Αλλαγή'))
await v.evaluate(`localStorage.setItem('xenia:test-site-1:token', ${JSON.stringify(token)})`)
v = await reloadApp(v, '/tables')
await sleep(7000)
r.check('logged in: /tables', (await v.evaluate('location.pathname')) === '/tables')
// 4.2: a real sign-in in the native app: pick your name, PIN on the pad, start the shift
await fetch(`${b1.url}/api/business-day/open`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` }, body: '{}' }).catch(() => {})
await tap(v, '[data-testid="waiter-card"]', 'Κωνσταντίνου')
for (const d of '3302') await tap(v, 'button.pin-btn', d)
await tap(v, 'button', 'Έναρξη Βάρδιας', { timeout: 15_000 })
await waitFor(() => v.evaluate("location.pathname === '/tables'"), 15_000, 500)
await sleep(3000)
r.check('signed in with name + PIN on the pad: /tables', (await v.evaluate('location.pathname')) === '/tables'
&& !!(await v.evaluate("localStorage.getItem('xenia:test-site-1:token')")))
const dbs = await v.evaluate('indexedDB.databases().then(d => d.map(x => x.name))')
r.check('IndexedDB namespaced per venue', dbs.includes('pos_snapshot__test-site-1'), dbs.join(','))
r.check('live WebSocket (green bar)', (await connectivityColor(v)) === GREEN)
// 4.2: lock from the menu, unlock with the PIN on the pad (same session)
const before = await v.evaluate("localStorage.getItem('xenia:test-site-1:token')")
await tap(v, 'button[title="Μενού χρήστη"]')
await tap(v, '[data-testid="menu-lock"]')
const lockedOk = await waitFor(() => v.evaluate("!!document.querySelector('[data-testid=lock-screen]')"), 5000, 300)
for (const d of '3302') await tap(v, '[data-testid="lock-screen"] button.pin-btn', d)
const unlocked = await waitFor(() => v.evaluate("!document.querySelector('[data-testid=lock-screen]')"), 8000, 300)
r.check('lock from the menu, unlock with the PIN: same session', !!lockedOk && !!unlocked
&& (await v.evaluate("localStorage.getItem('xenia:test-site-1:token')")) === before)
back()
await sleep(1500)
r.check('hardware back on /tables keeps the app open', focusedWindow().includes(APP_ID))
@@ -157,9 +172,21 @@ async function rediscovery() {
v = await reloadApp(v)
// waits for what the screen shows instead of fixed sleeps (KI-009): the app reloads at the
// new address, so the WebView handle may need re-attaching meanwhile
const onScreen = (check, ms = 30_000) => waitFor(async () => {
try { return await check(v) } catch { v = await attach().catch(() => v); return false }
}, ms, 500)
// A handle can also go stale without throwing (it keeps answering for a document that is
// gone): re-attach every ~5 s of "not yet". A timeout saves a real screenshot for the log.
let shots = 0
const onScreen = async (check, ms = 30_000) => {
let misses = 0
const ok = await waitFor(async () => {
try {
if (await check(v)) return true
if (++misses % 10 === 0) v = await attach().catch(() => v)
return false
} catch { v = await attach().catch(() => v); return false }
}, ms, 500)
if (!ok) shot(`android-rediscovery-timeout-${++shots}`)
return ok
}
r.check('setup: paired and logged in', !!(await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/tables', 45_000)))
const stale = async (vv) => {
@@ -173,19 +200,19 @@ async function rediscovery() {
v = await stale(v)
r.check('logged in: server "moved" → found and saved', !!(await found()))
r.check('logged in: back on /tables, live', !!(await onScreen(async vv =>
(await vv.evaluate('location.pathname')) === '/tables' && (await connectivityColor(vv)) === GREEN, 40_000)))
(await vv.evaluate('location.pathname')) === '/tables' && (await connectivityColor(vv)) === GREEN, 40_000)), `${await v.evaluate('location.pathname').catch(() => '?')} ${await connectivityColor(v).catch(() => '?')}`)
await v.evaluate("localStorage.removeItem('xenia:test-site-1:token')")
v = await stale(v)
r.check('logged out: found and saved', !!(await found()))
r.check('logged out: found and saved', !!(await found()), await v.evaluate('location.pathname + " | " + document.body.innerText.slice(0, 200)').catch(e => String(e)))
r.check('logged out: waiter list loads from the new address', !!(await onScreen(async vv =>
(await vv.evaluate('document.body.innerText')).includes('Manager'), 40_000)))
(await vv.evaluate('document.body.innerText')).includes('Manager'), 40_000)), await v.evaluate('location.pathname + " | " + document.body.innerText.slice(0, 200)').catch(e => String(e)))
await backend.stop()
v = await stale(v)
const offlineShown = await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/offline', 45_000)
r.check('server really down: saved address untouched', (await venuesState(v)).venues['test-site-1'].baseUrl.includes('.99:'))
r.check('server really down: offline screen', !!offlineShown)
r.check('server really down: offline screen', !!offlineShown, await v.evaluate('location.pathname + " | " + document.body.innerText.slice(0, 200)').catch(e => String(e)))
await v.evaluate("[...document.querySelectorAll('button')].find(e => e.textContent.includes('Αναζήτηση server')).click()")
const notFound = await waitFor(async () => (await v.evaluate('document.body.innerText')).includes('Ο server δεν βρέθηκε'), 60_000)
r.check('manual search ends with "not found" guidance', !!notFound)
@@ -252,7 +279,8 @@ server { listen 443 ssl; ssl_certificate /t/cert.pem; ssl_certificate_key /t/key
await sleep(1500)
v = await relaunch()
await waitFor(async () => (await v.evaluate('location.pathname')) === '/tables', 30_000)
r.check('TLS: /tables + live wss', (await connectivityColor(v)) === GREEN)
const t0 = Date.now(); const wssUp = await waitFor(async () => (await connectivityColor(v)) === GREEN, 20_000, 300)
r.check('TLS: /tables + live wss', !!wssUp, `after ${Date.now() - t0} ms: ` + `${await v.evaluate('location.pathname').catch(() => '?')} ${await connectivityColor(v).catch(() => '?')}`)
adb('logcat', '-c')
const impostor = await v.evaluate(`fetch('https://${H}:18444/api/system/identity').then(r => 'OK ' + r.status, () => 'FAILED')`)
const genuine = await v.evaluate(`fetch('https://${H}:18443/api/system/identity').then(r => 'OK ' + r.status, () => 'FAILED')`)