feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view

- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations,
  token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs,
  welcome_checkin enqueue; badge_print_tests.sql (101 assertions)
- apps/printer: Python worker (Playwright render -> brother_ql via pyusb),
  comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token),
  arm64 image build + idempotent Pi setup/install scripts, 77 pytest
- apps/admin: Printing view, station management/DLQ, global printer status
  pill, Print button on Registrations, standalone print renderer entry
  (print.html -> dist-print) with bundled fonts
- docs: printing.md + architecture/schema/rpcs/tests/admin-app updates,
  apps/printer/AGENT.md operating manual
- e2e: printing.spec.ts

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-18 22:25:38 +02:00
1 parent 0f3720d48a
commit 00c89c1b48
55 files changed
+7406 -29

No files matched your search

+103
View File
@@ -0,0 +1,103 @@
from __future__ import annotations
import pytest
from PIL import Image
from worker.printer import Printer, map_status
from worker.config import Config
# Verbatim status dict reported by the real QL-1110NWB with DK-22246 loaded.
REAL_STATUS = {
"status_type": "Reply to status request",
"phase_type": "Waiting to receive",
"model_name": "QL-1100NWB",
"media_type": "Die-cut labels",
"media_width": 104,
"media_length": 164,
"identified_media": type(
"Label",
(),
{"identifier": "103x164", "dots_printable": (1200, 1822), "form_factor": 1},
)(),
"errors": [],
}
def cfg(label: str = "auto") -> Config:
return Config(
convivo_url="http://x",
convivo_anon_key="k",
station_token="t",
brother_label=label,
dry_run=True,
)
def test_maps_real_status():
st = map_status(REAL_STATUS, "auto")
assert st == {
"connected": True,
"model": "QL-1100NWB",
"ready": True,
"media_type": "die-cut",
"label_id": "103x164",
"media_width_mm": 104,
"media_length_mm": 164,
"errors": [],
}
def test_continuous_media_type():
raw = dict(REAL_STATUS, media_type="Continuous length tape")
st = map_status(raw, "auto")
assert st["media_type"] == "continuous" and st["ready"]
def test_errors_block_ready():
raw = dict(REAL_STATUS, errors=["Tape end"])
st = map_status(raw, "auto")
assert st["errors"] == ["Tape end"] and not st["ready"] and st["connected"]
def test_wrong_roll_mismatch():
st = map_status(REAL_STATUS, "103")
assert not st["ready"]
assert st["errors"] == ["wrong roll: loaded 103x164, expected 103"]
def test_matching_expected_label_ok():
assert map_status(REAL_STATUS, "103x164")["ready"]
def test_not_waiting_phase():
raw = dict(REAL_STATUS, phase_type="Printing data to receive buffer")
st = map_status(raw, "auto")
assert st["connected"] and not st["ready"]
def test_no_media():
raw = dict(REAL_STATUS, media_type="No media", identified_media=None)
st = map_status(raw, "auto")
assert st["media_type"] is None and st["label_id"] is None
assert "no media loaded" in st["errors"] and not st["ready"]
def test_unidentified_media_not_ready():
raw = dict(REAL_STATUS, identified_media=None)
st = map_status(raw, "auto")
assert not st["ready"]
def test_dry_run_status_and_print(tmp_path, monkeypatch):
monkeypatch.setattr("worker.printer.DRYRUN_DIR", tmp_path)
printer = Printer(cfg())
st = printer.get_status()
assert st["ready"] and st["label_id"] == "103x164"
result = printer.print_image(Image.new("RGB", (10, 10)), "103x164")
assert result["did_print"] is True
assert list(tmp_path.glob("dryrun-*.png"))
def test_dry_run_honours_expected_label():
st = Printer(cfg("103")).get_status()
assert st["label_id"] == "103" and st["media_type"] == "continuous"