refactor(connect): one live connection, no token in any address (SSE removed)

Plan step 4.0. Owner (2026-11-17): no phone in use needs to keep working, so no
compatibility path.
- Removed the SSE channel: routers/sse.py (/api/sse/stream, which still accepted a JWT whose
  session had ended — a signed-out phone could keep listening), services/sse_bus.py (every
  backend module now calls services/ws_bus.broadcast_sync directly), waiter useSSE.js.
- Credentials only in the first frame: the waiter's useWebSocket and the manager's
  LiveProvider send {token} there like the terminal; routers/ws.py no longer reads ?token=
  (a token in a URL ends up in proxy and server logs).
- Waiter: SSEContext → LiveContext (LiveProvider, useLiveContext, liveAlive, the
  'live-event' / 'live-reconnected' window events), dead SSE compat code removed.
- Tests: a token in the address is refused, /api/sse/stream is 404; e2e browser (3 delivery
  modes) and manager assert no token in the live connection's address. Android taps now
  wait for their element (the fixed sleeps made the suite flaky, KI-009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 10:49:21 +02:00
co-authored by Claude Opus 5.5
parent d0c6a10e47
commit f85894a72e
43 changed files with 112 additions and 350 deletions
+2 -1
View File
@@ -103,7 +103,8 @@ async function basics() {
v = await attach()
let vs = await venuesState(v)
r.check('second venue paired and active', vs.active === 'test-site-2' && Object.keys(vs.venues).length === 2)
r.check('second venue starts logged out (own session)', (await v.evaluate('location.pathname')) === '/login')
const path2 = await v.evaluate('location.pathname')
r.check('second venue starts logged out (own session)', path2 === '/login', `${path2} ${JSON.stringify(vs)}`)
await tap(v, 'button', 'Αλλαγή')
await sleep(1200)
await tap(v, 'button', `${H}:8055`)
+1
View File
@@ -53,6 +53,7 @@ try {
const dbs = await page.evaluate(async () => (await indexedDB.databases()).map(d => d.name))
r1.check(`${m.name}: lands on /tables`, page.url().includes('/tables'), page.url())
r1.check(`${m.name}: live WebSocket via ${m.wsHost}`, frames.some(f => f.includes('"ready"')) && wsUrls.some(u => new URL(u).host === m.wsHost))
r1.check(`${m.name}: no token in the live connection's address (4.0)`, wsUrls.some(u => u.includes('/api/ws/')) && wsUrls.filter(u => u.includes('/api/')).every(u => !/token=/.test(u)), wsUrls.filter(u => u.includes('/api/')).join(' '))
r1.check(`${m.name}: IndexedDB "${m.db}"`, dbs.includes(m.db), dbs.join(','))
r1.check(`${m.name}: secure context = ${m.secure}`, (await page.evaluate(() => window.isSecureContext)) === m.secure)
if (m.name.startsWith('venue')) r1.check(`${m.name}: API calls go to the venue server`, [...apiHosts].every(h => h === '127.0.0.1:8055'), [...apiHosts].join(','))
+11 -4
View File
@@ -80,12 +80,19 @@ export async function reloadApp(v, target = '/') {
const statusBar = () => Number(adb('shell', 'dumpsys', 'window').match(/statusBars.*?frame=\[0,0\]\[\d+,(\d+)\]/s)?.[1] || 0)
/** Real tap on the element matching a CSS selector (and containing `text`). */
export async function tap(v, selector, text = '', { last = false } = {}) {
const r = await v.evaluate(`(() => {
export async function tap(v, selector, text = '', { last = false, timeout = 10_000 } = {}) {
// waits for the element (a relaunch or a route change on the emulator can take a few
// seconds; fixed sleeps made the suite flaky, KI-009) instead of failing at once
const find = () => v.evaluate(`(() => {
const els = [...document.querySelectorAll(${JSON.stringify(selector)})].filter(e => e.textContent.includes(${JSON.stringify(text)}))
const b = els[${last ? 'els.length - 1' : '0'}]?.getBoundingClientRect()
return b ? { x: b.x + b.width / 2, y: b.y + b.height / 2, dpr: devicePixelRatio } : null
})()`)
return b && b.width > 0 ? { x: b.x + b.width / 2, y: b.y + b.height / 2, dpr: devicePixelRatio } : null
})()`).catch(() => null)
let r = await find()
for (const until = Date.now() + timeout; !r && Date.now() < until;) {
await new Promise(res => setTimeout(res, 300))
r = await find()
}
if (!r) throw new Error(`nothing to tap: ${selector} "${text}"`)
adb('shell', 'input', 'tap', String(Math.round(r.x * r.dpr)), String(Math.round(r.y * r.dpr + statusBar())))
}
+3
View File
@@ -78,6 +78,8 @@ try {
page.on('pageerror', e => errors.push(e.message))
const bootstraps = []
page.on('request', q => { if (q.url().includes('/api/platform/bootstrap')) bootstraps.push(q.headers().authorization || 'anonymous') })
const managerWs = []
page.on('websocket', ws => managerWs.push(ws.url()))
// ── Wrong password: the message shows, no reload ───────────────────────────
await uiLogin(page, 'wrong-password')
@@ -751,6 +753,7 @@ try {
(await chefRow.textContent().catch(() => '')).includes('Kitchen pass · Kitchen display'))
await o.screenshot({ path: path.join(OUT, 'manager-owner-flow.png'), fullPage: true })
r.check('live: the manager connection carries no token in its address (4.0)', managerWs.some(u => u.includes('/api/ws/')) && managerWs.filter(u => u.includes('/api/')).every(u => !/token=/.test(u)), managerWs.filter(u => u.includes('/api/')).join(' ')) // (Vite's own dev socket has its token)
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
} finally {
await browser.close()