- WebSocket: credentials may come in the first frame ({cursor, token?, device?}).
A device token alone connects a paired screen (login-none apps get every event, a
sign-in app only events addressed to it); a terminal session's JWT needs its own
device, as over HTTP. Refusals send {type: refused, data: {code}} + close 4001/4003.
- ws_bus: registry of open sockets by user, session and device. Ending a session
closes its sockets (session.ended); revoke/reassign close the device's sockets
(device.revoked / device.updated); edits and module on/off send device.updated.
Events can target devices (device_ids=..., sync_events.target_device_ids, rev 0014).
Pushes go through each socket's own loop (call_soon_threadsafe).
- Device config: DeviceApp.config = typed ConfigFields, validated on pair/edit/
reassign (validation.device_config), effective values (defaults filled) in both
device views and the module catalogue. First field: auto_sign_out_minutes (KDS, POS).
- Manager: DeviceConfigFields renders an app's fields in the pair and edit dialogs.
- @xenia/api createLiveClient: `credentials` and `onRefused` options.
- Tests: tests/test_live.py (11), module texts for config fields, live client,
devices logic, manager.mjs device setting + live socket checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
3.0 KiB
Python
68 lines
3.0 KiB
Python
"""Every module (and each of its limits) has a name and description for staff in every
|
|
UI language (packages/i18n/locales/<lang>/modules.json, plan step 2.6c). A new module in
|
|
a manifest fails here until its texts exist."""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from core.modules.registry import registry
|
|
|
|
LOCALES = Path(__file__).resolve().parents[2] / "packages" / "i18n" / "locales"
|
|
|
|
|
|
@pytest.mark.parametrize("lang", ["en", "el"])
|
|
def test_every_module_has_texts(lang):
|
|
texts = json.loads((LOCALES / lang / "modules.json").read_text(encoding="utf-8"))
|
|
missing = []
|
|
for m in registry().values():
|
|
t = texts.get(m.key, {})
|
|
if not t.get("name") or not t.get("description"):
|
|
missing.append(m.key)
|
|
for lim in m.limits:
|
|
if not t.get("limits", {}).get(lim.key):
|
|
missing.append(f"{m.key}.limits.{lim.key}")
|
|
assert missing == []
|
|
assert set(texts) == set(registry()), "texts for modules that don't exist"
|
|
|
|
|
|
@pytest.mark.parametrize("lang", ["en", "el"])
|
|
def test_every_permission_has_a_label(lang):
|
|
"""modules:<module>.permissions.<rest of the key>, nested by its dots (plan step 2.6e)."""
|
|
texts = json.loads((LOCALES / lang / "modules.json").read_text(encoding="utf-8"))
|
|
missing, known = [], set()
|
|
for m in registry().values():
|
|
for p in m.permissions:
|
|
node = texts.get(m.key, {}).get("permissions", {})
|
|
for part in p.key.split(".", 1)[1].split("."):
|
|
node = node.get(part, {}) if isinstance(node, dict) else {}
|
|
if not isinstance(node, str) or not node:
|
|
missing.append(p.key)
|
|
known.add(p.key)
|
|
assert missing == []
|
|
|
|
def leaves(prefix, node):
|
|
for k, v in node.items():
|
|
yield from (leaves(f"{prefix}.{k}", v) if isinstance(v, dict) else [f"{prefix}.{k}"])
|
|
labelled = {k for mod, t in texts.items() for k in leaves(mod, t.get("permissions", {}))}
|
|
assert labelled - known == set(), "labels for permissions that don't exist"
|
|
|
|
|
|
@pytest.mark.parametrize("lang", ["en", "el"])
|
|
def test_every_device_config_field_has_texts(lang):
|
|
"""modules:<app>.config.<key>.label, and .choices.<value> for every choice (plan step 3.1a)."""
|
|
texts = json.loads((LOCALES / lang / "modules.json").read_text(encoding="utf-8"))
|
|
missing, known = [], set()
|
|
for m in registry().values():
|
|
for f in (m.device_app.config if m.device_app else ()):
|
|
t = texts.get(m.key, {}).get("config", {}).get(f.key, {})
|
|
if not t.get("label"):
|
|
missing.append(f"{m.key}.config.{f.key}.label")
|
|
for c in f.choices:
|
|
if not t.get("choices", {}).get(str(c)):
|
|
missing.append(f"{m.key}.config.{f.key}.choices.{c}")
|
|
known.add((m.key, f.key))
|
|
assert missing == []
|
|
extra = {(mod, k) for mod, t in texts.items() for k in t.get("config", {})} - known
|
|
assert extra == set(), "texts for device settings that don't exist"
|