Files
xenia-pos-local/manager_dashboard/tests/v2-guards.test.mjs
T
bonaminandClaude Opus 5.5 2dc5da446e feat: foundations for the manager conversion (platform-v2 step 6.1)
- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes,
  texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read;
  bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions.
- Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them,
  tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make
  set-state-in-effect an error.
- src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now
  uses it.
- Dead manager files removed (3.1k lines unreachable from main.jsx).
- Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live
  bell check passed on a rerun).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 04:31:36 +02:00

55 lines
2.6 KiB
JavaScript

// Plan step 6.1: the manager's pages on the v2 rules (v2.json `paths`) keep them. Texts are
// keys in @xenia/i18n (namespace `manager`), so no Greek letter in their source; colours are
// @xenia/ui tokens, so no colour value in their code. Each phase 6 step adds what it converted
// to v2.json; at the end (6.14) the list is `src`.
// Colours the venue picks for its screens (signage slides, a device's colour setting) are data,
// not styling: the files in DATA hold such defaults.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const v2 = JSON.parse(readFileSync(path.join(ROOT, 'v2.json'), 'utf8'))
const DATA = new Set([
'src/pages/signage/signageLogic.js', 'src/pages/signage/SignageFields.jsx', 'src/pages/signage/SlideEditor.jsx',
'src/pages/signage/MenuEditor.jsx', 'src/pages/platform/DeviceConfigFields.jsx',
])
const GREEK = /[Ͱ-Ͽἀ-῿]/
const COLOUR = [
/(^|[^\w&])#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?(?:[0-9a-fA-F]{2})?\b/,
/\brgba?\(\s*\d/,
/\bhsla?\(\s*\d/,
/['"](white|black)['"]/,
]
const walk = p => (statSync(p).isDirectory() ? readdirSync(p).flatMap(n => walk(path.join(p, n))) : (/\.(jsx?|css)$/.test(p) ? [p] : []))
const files = () => v2.paths.flatMap(rel => walk(path.join(ROOT, rel))).map(f => path.relative(ROOT, f).split(path.sep).join('/'))
test('every v2 path exists (v2.json is current)', () => {
assert.deepEqual(v2.paths.filter(p => !existsSync(path.join(ROOT, p))), [])
assert.deepEqual(v2.strict.filter(p => !v2.paths.some(q => p === q || p.startsWith(`${q}/`))), [], 'strict paths must be v2 paths')
})
test('no Greek text in v2 pages (texts are i18n keys)', () => {
const hits = []
for (const rel of files()) {
readFileSync(path.join(ROOT, rel), 'utf8').split('\n').forEach((line, i) => {
if (GREEK.test(line)) hits.push(`${rel}:${i + 1}: ${line.trim().slice(0, 80)}`)
})
}
assert.deepEqual(hits, [], `Greek text found — make it a key in the manager namespace:\n${hits.join('\n')}`)
})
test('no colour literal in v2 pages (tokens only)', () => {
const hits = []
for (const rel of files()) {
if (DATA.has(rel)) continue
readFileSync(path.join(ROOT, rel), 'utf8').split('\n').forEach((line, i) => {
if (COLOUR.some(re => re.test(line))) hits.push(`${rel}:${i + 1}: ${line.trim().slice(0, 90)}`)
})
}
assert.deepEqual(hits, [], `colour values in page code — use a token (var(--x-…) / @xenia/ui):\n${hits.join('\n')}`)
})