"""WebUI 关键安全/稳定性源码锚点测试。""" from __future__ import annotations import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def _read(rel: str) -> str: return (ROOT / rel).read_text(encoding="utf-8") def test_config_form_bool_literal_coercion_guard(): src = _read("webui/js/config_form.js") assert 'if (type === "bool")' in src assert '["1", "true", "yes", "y", "on"]' in src assert '["0", "false", "no", "n", "off", ""]' in src def test_runtime_actions_reservation_fields_guarded(): src = _read("webui/js/runtime_actions.js") assert "safePrizeValue" in src assert "safePosSeen" in src assert "safeRoomPos" in src assert "safeReservationsCount" in src assert "safeTotal" in src assert "escapeHtml(item.future_str || '-')" in src def test_runtime_device_actions_send_back_key_handles_error(): src = _read("webui/js/runtime_device_actions.js") m = re.search( r"async function sendBackKey\(\)\s*\{(?P.*?)\n\}", src, flags=re.S, ) assert m, "sendBackKey function not found" body = m.group("body") assert "try {" in body assert "catch" in body