feat(backend): KDS settings as device config, zone enforced for kitchen screens, KDS-only API (platform-v2 3.2a)
- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
and signs waiter messages with its zone/name. New GET /api/kds/context and
POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
restart check (one flaky 403).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -186,6 +186,11 @@ try {
|
||||
r.check('devices: the code is normalized as typed (lower case, dash)', await dlg.getByLabel('Code shown on the device').inputValue() === req.code)
|
||||
await dlg.getByLabel('How staff sign in').selectOption('pin')
|
||||
await dlg.getByLabel('Sign out after').selectOption('10')
|
||||
r.check('devices: the kitchen screen settings come in sections, prep zone "All zones" by default (3.2a)',
|
||||
await dlg.locator('[data-config-group]').count() >= 4
|
||||
&& (await dlg.getByLabel('Prep zone').locator('option:checked').textContent()) === 'All zones'
|
||||
&& await dlg.locator('input[type="color"]').count() === 4)
|
||||
await dlg.getByLabel('Text size').fill('110')
|
||||
await dlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid^="device-"][data-status]').length === 1, null, { timeout: 8000 }).catch(() => {})
|
||||
const row = page.locator('[data-testid^="device-"][data-status]').first()
|
||||
@@ -193,7 +198,7 @@ try {
|
||||
const deviceToken = await devicePicksUpToken(req)
|
||||
const me = await asDevice(deviceToken, '/api/devices/me').then(x => x.json())
|
||||
r.check('devices: the device got its token and runs the kitchen display', me.app_key === 'kds' && me.name === 'Kitchen' && me.login_mode === 'pin', JSON.stringify(me))
|
||||
r.check('devices: the app setting chosen when pairing reaches the device (3.1a)', me.config?.auto_sign_out_minutes === 10, JSON.stringify(me.config))
|
||||
r.check('devices: the app setting chosen when pairing reaches the device (3.1a)', me.config?.auto_sign_out_minutes === 10 && me.config?.font_scale === 110, JSON.stringify(me.config))
|
||||
await page.reload()
|
||||
await row.waitFor({ timeout: 10_000 })
|
||||
r.check('devices: after it connected → "Online", sign-in PIN', await row.getAttribute('data-status') === 'online' && (await row.textContent()).includes('PIN'))
|
||||
|
||||
@@ -66,6 +66,10 @@ try {
|
||||
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')
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Backend :8059 (demo DB, licensing off), terminal Vite :5187 proxied to it.
|
||||
// - pairing through the real screen (code shown → paired from the manager's side)
|
||||
// - sign-in modes: PIN (wrong PIN first), tap your name, password; sign out
|
||||
// - 3.2a: the screen's prep zone is enforced, and every KDS call passes the device scope
|
||||
// - app turned off → "turned off" screen → on again, live
|
||||
// - device moved to another app → its user is signed out
|
||||
// - a customer display (no sign-in) goes straight into its app
|
||||
@@ -83,6 +84,61 @@ try {
|
||||
sessions.some(s => s.user_id === chef.id && s.client === 'terminal' && s.device_id === kitchen.id), JSON.stringify(sessions.map(s => [s.user_id, s.client, s.device_id])))
|
||||
await page.reload()
|
||||
r.check('reload keeps the screen paired and the chef signed in', await shown(page, 'app-kds'))
|
||||
|
||||
// ── 3.2a: the screen's prep zone and the KDS's own scope ─────────────────
|
||||
const grill = await api('POST', '/api/prep-zones', { token: boss, body: { name: 'Grill', notification_name: 'Grill station' } })
|
||||
const bar = await api('POST', '/api/prep-zones', { token: boss, body: { name: 'Bar' } })
|
||||
// a waiter orders one product for each zone (the demo's orders are all closed)
|
||||
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
|
||||
const maria = (await api('POST', '/api/auth/login', { body: { client: 'waiter', username: 'demo_maria', pin: '3302' } })).access_token
|
||||
await api('POST', '/api/shifts/start', { token: maria, body: {} }).catch(() => {})
|
||||
const table = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id)
|
||||
const opened = await api('POST', '/api/orders/', { token: maria, body: { table_id: table.id } })
|
||||
const [p1, p2] = (await api('GET', '/api/products/', { token: boss })).filter(p => p.is_active !== false)
|
||||
await api('POST', '/api/products/bulk-prep-zones', { token: boss, body: { product_ids: [p1.id], prep_zone_ids: [grill.id] } })
|
||||
await api('POST', '/api/products/bulk-prep-zones', { token: boss, body: { product_ids: [p2.id], prep_zone_ids: [bar.id] } })
|
||||
await api('POST', `/api/orders/${opened.id}/items`, { token: maria, body: { items: [p1, p2].map(p => ({ product_id: p.id, quantity: 1 })) } })
|
||||
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { config: { prep_zone_id: grill.id, font_scale: 120 } } })
|
||||
const order = (await api('GET', '/api/kds/orders', { token: boss })).orders.find(o => o.id === opened.id)
|
||||
const calls = [
|
||||
['get', '/api/kds/context'],
|
||||
['get', '/api/kds/orders'],
|
||||
['get', `/api/kds/orders?zone_id=${bar.id}`],
|
||||
['get', '/api/kds/on-shift-waiters'],
|
||||
['put', `/api/kds/orders/${order.id}/items/${order.items[0].id}/kds_status`, { status: 'preparing' }],
|
||||
['put', `/api/kds/orders/${order.id}/kds_status`, { status: 'preparing' }],
|
||||
['post', `/api/kds/orders/${order.id}/notify-items-ready`, { ready_count: 1, total_count: 2 }],
|
||||
['post', `/api/kds/orders/${order.id}/notify-complete`, {}],
|
||||
['post', `/api/kds/orders/${order.id}/call-waiter`, {}],
|
||||
['post', `/api/kds/orders/${order.id}/retry-print`],
|
||||
['put', `/api/kds/orders/${order.id}/kds_status`, { status: 'pending' }],
|
||||
]
|
||||
// every call the kitchen screen makes, through the screen's own client (device header + chef's session)
|
||||
const answers = await page.evaluate(async list => {
|
||||
const out = []
|
||||
for (const [method, url, body] of list) {
|
||||
try {
|
||||
const res = await window.__xeniaClient[method](url, body)
|
||||
out.push({ url, status: res.status, data: res.data })
|
||||
} catch (e) {
|
||||
out.push({ url, status: e.response?.status ?? 0, code: e.response?.data?.error?.code })
|
||||
}
|
||||
}
|
||||
return out
|
||||
}, calls)
|
||||
const refused = answers.filter(a => a.status >= 400)
|
||||
r.check('3.2a: no call the kitchen screen makes is refused (device scope kds.*)', refused.length === 0, JSON.stringify(refused))
|
||||
const ctx = answers[0].data ?? {}
|
||||
r.check('3.2a: the screen gets its zone and settings from /api/kds/context',
|
||||
ctx.zone?.name === 'Grill' && ctx.settings?.font_scale === 120 && ctx.prep_zones?.length >= 2, JSON.stringify(ctx).slice(0, 300))
|
||||
const items = answers.slice(1, 3).flatMap(a => (a.data?.orders ?? []).flatMap(o => o.items))
|
||||
r.check('3.2a: it only ever gets its own zone\'s items, even when it asks for another zone',
|
||||
items.length > 0 && items.every(i => i.prep_zone_ids.includes(grill.id)), `${items.length} items`)
|
||||
const outside = await page.evaluate(async () => {
|
||||
try { await window.__xeniaClient.get('/api/prep-zones'); return 'allowed' } catch (e) { return e.response?.data?.error?.code }
|
||||
})
|
||||
r.check('3.2a: what the old page used instead (/api/prep-zones) stays out of its scope', outside === 'device.out_of_scope', outside)
|
||||
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
r.check('sign out → back to the names', await shown(page, 'user-grid'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user