feat(terminal): pairing, sign-in per mode, device app router and live states (platform-v2 3.1c)
- Pairing screen: requests a code, shows it big, polls with the secret, new code on expiry, keeps the device token; "removed from the venue" notice after a revoke. - Sign-in per device mode: PIN (name + PinPad), tap your name, password (name + password), none (straight into the app). Names = holders of <app>.access, refreshed every 30 s and on reconnect. Slim bar with screen, user and Sign out; idle sign-out after the device's auto_sign_out_minutes; hourly token refresh (same session). - DeviceProvider: GET /api/devices/me (retried while unreachable), session, the live connection with credentials in the first frame (device.updated -> reload, app moved -> sign out, device.revoked -> forget, session.ended -> sign out), offline banner; useLiveEvent for apps. Screen choice is pure (device/flow.js, unit-tested). - Blocked screen: app turned off / not licensed / device refused, recovers by itself. - @xenia/access AccessProvider: autoRetryMs (retry bootstrap while unreachable). - Tests: terminal unit tests (screen choice, live actions, idle, pairing polls), new tests/e2e/terminal.mjs (18 checks), manager.mjs owner flow now pairs and signs in on the real terminal screen; run-all runs terminal.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+26
-21
@@ -10,7 +10,7 @@ import { openSync, readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { chromium } from 'playwright'
|
||||
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
|
||||
import { killTree, startBackend, waitHttp } from './lib/proc.mjs'
|
||||
import { killTree, startBackend, startTerminalVite, waitHttp } from './lib/proc.mjs'
|
||||
import { SUPPORT_MASTER, codeFor, siteSecret, supportLogin } from './lib/support.mjs'
|
||||
|
||||
const PORT = 5186
|
||||
@@ -21,6 +21,7 @@ const vite = spawn('npx', ['vite', '--port', String(PORT), '--strictPort'], {
|
||||
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
|
||||
stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url },
|
||||
})
|
||||
const term = await startTerminalVite({ port: 5188, backendUrl: backend.url }) // the owner flow's kitchen screen (3.1c)
|
||||
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
||||
const r = reporter('manager: login + bootstrap on @xenia/api / @xenia/access')
|
||||
|
||||
@@ -567,7 +568,7 @@ try {
|
||||
|
||||
// ── 2.6g: the owner flow (plan step 2.6 "done when") ───────────────────────
|
||||
// log in → enable KDS → pair a device → give a chef kds.access → the chef logs in on it.
|
||||
// The device's side is played through the API until the terminal app exists (phase 3).
|
||||
// The device's side is the real terminal app (3.1c), on its own Vite (:5188).
|
||||
const ownerFlow = 'owner flow:'
|
||||
await api('PUT', '/api/platform/modules/kds', { token: boss, body: { enabled: false } }) // start with KDS off
|
||||
const chef = await api('POST', '/api/waiters/', { token: boss, body: { username: 'e2e_chef', full_name: 'Kostas Chef', pin: '4747', role: 'custom', is_active: true } })
|
||||
@@ -585,29 +586,28 @@ try {
|
||||
await kdsCard.getByRole('switch').click()
|
||||
await o.waitForFunction(() => document.querySelector('[data-testid="module-kds"]')?.getAttribute('data-state') === 'on', null, { timeout: 8000 }).catch(() => {})
|
||||
r.check(`${ownerFlow} 2. KDS turned on from its card`, offBefore === 'off' && await kdsCard.getAttribute('data-state') === 'on')
|
||||
// 3. the screen shows a code; the owner pairs it on the Devices page
|
||||
const kitchenReq = await deviceRequestsPairing()
|
||||
// 3. the screen (the real terminal app, 3.1c) shows a code; the owner pairs it on the Devices page
|
||||
const k = await (await browser.newContext({ viewport: { width: 1280, height: 800 } })).newPage()
|
||||
k.on('pageerror', e => errors.push(e.message))
|
||||
await k.goto(term.url)
|
||||
await k.getByTestId('pairing-code').waitFor({ timeout: 20_000 })
|
||||
const kitchenCode = await k.getByTestId('pairing-code').getAttribute('data-code')
|
||||
await o.goto(`${APP}/devices`)
|
||||
await o.getByTestId('device-usage').waitFor({ timeout: 10_000 })
|
||||
await o.getByRole('button', { name: 'Pair a device' }).first().click()
|
||||
const odlg = o.getByRole('dialog')
|
||||
await odlg.getByLabel('Code shown on the device').fill(kitchenReq.code)
|
||||
await odlg.getByLabel('Code shown on the device').fill(kitchenCode)
|
||||
await odlg.getByLabel('App to run').selectOption('kds')
|
||||
await odlg.getByLabel('Name').fill('Kitchen pass')
|
||||
await odlg.getByLabel('How staff sign in').selectOption('pin')
|
||||
await odlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await odlg.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
const kitchenToken = await devicePicksUpToken(kitchenReq)
|
||||
const kitchenMe = await asDevice(kitchenToken, '/api/devices/me').then(x => x.json())
|
||||
r.check(`${ownerFlow} 3. the screen is paired as "Kitchen pass", a kitchen display with PIN sign-in`,
|
||||
kitchenMe.app_key === 'kds' && kitchenMe.name === 'Kitchen pass' && kitchenMe.login_mode === 'pin', JSON.stringify(kitchenMe))
|
||||
const chefOnDevice = () => fetch(`${backend.url}/api/auth/login`, {
|
||||
method: 'POST', headers: { 'content-type': 'application/json', 'X-Xenia-Device': kitchenToken },
|
||||
body: JSON.stringify({ client: 'terminal', user_id: chef.id, pin: '4747' }),
|
||||
})
|
||||
const refused = await chefOnDevice()
|
||||
r.check(`${ownerFlow} …before the permission, the chef is refused on that screen`,
|
||||
refused.status === 403 && (await refused.json()).error.code === 'auth.client_not_allowed')
|
||||
const onSignIn = await k.getByTestId('sign-in-screen').waitFor({ timeout: 15_000 }).then(() => true).catch(() => false)
|
||||
r.check(`${ownerFlow} 3. the kitchen screen shows a code, the owner pairs it as "Kitchen pass" (PIN) and the screen asks who signs in`,
|
||||
onSignIn && await k.getByTestId('sign-in-screen').getAttribute('data-mode') === 'pin' && (await k.getByTestId('sign-in-screen').textContent()).includes('Kitchen pass'))
|
||||
await k.getByTestId('user-grid').waitFor({ timeout: 8000 }).catch(() => {})
|
||||
r.check(`${ownerFlow} …before the permission, the chef isn't offered on that screen`,
|
||||
await k.locator(`[data-user="${chef.id}"]`).count() === 0)
|
||||
// 4. give the chef the kitchen permissions in the editor
|
||||
await o.goto(`${APP}/management/staff`)
|
||||
await o.getByTestId(`staff-perms-${chef.id}`).getByRole('button').click()
|
||||
@@ -618,11 +618,15 @@ try {
|
||||
await o.getByTestId('perm-editor').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
const chefKeys = (await api('GET', `/api/waiters/${chef.id}/permissions`, { token: boss })).keys
|
||||
r.check(`${ownerFlow} 4. the chef now has kds.access and kds.bump`, chefKeys.includes('kds.access') && chefKeys.includes('kds.bump'), JSON.stringify(chefKeys))
|
||||
// 5. the chef signs in on the kitchen screen with their PIN
|
||||
const chefLogin = await chefOnDevice()
|
||||
const chefSession = chefLogin.status === 200 ? (await chefLogin.json()).access_token : null
|
||||
const kdsOrders = chefSession && await fetch(`${backend.url}/api/kds/orders`, { headers: { authorization: `Bearer ${chefSession}`, 'X-Xenia-Device': kitchenToken } })
|
||||
r.check(`${ownerFlow} 5. the chef signs in on that screen and sees the kitchen orders`, !!chefSession && kdsOrders.status === 200, String(chefLogin.status))
|
||||
// 5. the chef signs in on the kitchen screen with their PIN (the name list refreshes every 30 s; reload = now)
|
||||
await k.reload()
|
||||
await k.locator(`[data-user="${chef.id}"]`).click({ timeout: 15_000 })
|
||||
await k.keyboard.type('4747')
|
||||
await k.keyboard.press('Enter')
|
||||
const inKds = await k.getByTestId('app-kds').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||||
r.check(`${ownerFlow} 5. the chef signs in on that screen with their PIN and lands in the kitchen display`,
|
||||
inKds && (await k.getByTestId('signed-in-user').textContent()).includes('Kostas'))
|
||||
await k.screenshot({ path: path.join(OUT, 'manager-owner-flow-kitchen.png') })
|
||||
await o.goto(`${APP}/management/sessions`)
|
||||
const chefRow = o.locator(`[data-user="${chef.id}"][data-client="terminal"]`)
|
||||
await chefRow.waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
@@ -634,6 +638,7 @@ try {
|
||||
} finally {
|
||||
await browser.close()
|
||||
killTree(vite)
|
||||
term.stop()
|
||||
await backend.stop()
|
||||
}
|
||||
process.exit(r.done() ? 1 : 0)
|
||||
|
||||
Reference in New Issue
Block a user