fix(web): reveal NFC peripherals after detection

This commit is contained in:
Miayui
2026-09-21 11:04:18 +08:00
parent 448c8b31a0
commit b3bd90f748
9 changed files with 75 additions and 14 deletions
+2 -2
View File
@@ -1024,7 +1024,7 @@ operations:
) as response:
speech_worklet = response.read().decode("utf-8")
with self.opener.open(
f"{self.base_url}/self-extension.js?v=nfc-persistent-57", timeout=3
f"{self.base_url}/self-extension.js?v=nfc-session-58", timeout=3
) as response:
extension_script = response.read().decode("utf-8")
with self.opener.open(
@@ -1105,7 +1105,7 @@ operations:
self.assertIn('id="v2BootScreen"', template)
self.assertIn('正在加载车机控制与实时状态', template)
self.assertIn(
f'src="{runtime_url("self-extension.js", "/self-extension.js?v=nfc-persistent-57")}"',
f'src="{runtime_url("self-extension.js", "/self-extension.js?v=nfc-session-58")}"',
html,
)
self.assertIn('import "../self-extension.css";', vite_entry)
@@ -143,6 +143,7 @@ def test_each_detection_publishes_three_frames_per_device_and_then_stops() -> No
nfc["card"] = None
assert wait_until(lambda: service.snapshot()["state"] == "waiting_for_nfc")
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
nfc["card"] = {"action": "present", "uid": "E113B203"}
assert wait_until(lambda: len(publications) == 12)
assert service.snapshot()["state"] == "burst_complete"
@@ -150,6 +151,29 @@ def test_each_detection_publishes_three_frames_per_device_and_then_stops() -> No
service.close()
def test_detected_devices_remain_latched_until_publisher_stops() -> None:
nfc: dict[str, Any] = {"card": {"action": "present", "uid": "E113B203"}}
service = NfcExtensionToyPublisher(
nfc_provider=lambda: nfc,
catalog_provider=lambda: [capability("light-on")],
publisher=lambda _payload: {"delivery_status": "queued"},
burst_window_s=0.03,
poll_interval_s=0.005,
)
service.start()
try:
assert wait_until(
lambda: service.snapshot()["detected_nfc_ids"] == ["E113B203"]
)
nfc["card"] = None
assert wait_until(lambda: service.snapshot()["state"] == "waiting_for_nfc")
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
finally:
service.close()
assert service.snapshot()["detected_nfc_ids"] == []
def test_no_matching_ability_publishes_nothing() -> None:
nfc = {"card": {"action": "present", "uid": "E113B203"}}
publications: list[dict[str, Any]] = []
@@ -168,6 +192,7 @@ def test_no_matching_ability_publishes_nothing() -> None:
assert wait_until(
lambda: service.snapshot()["state"] == "no_matching_extension"
)
assert service.snapshot()["detected_nfc_ids"] == ["E113B203"]
time.sleep(0.05)
assert publications == []
finally:
@@ -94,7 +94,7 @@ def test_performance_assets_have_a_new_cache_generation() -> None:
for asset in (
"/app.js?v=dual-seat-147-video-media",
"/console-v2.js?v=local-first-79-cinema-status",
"/self-extension.js?v=nfc-persistent-57",
"/self-extension.js?v=nfc-session-58",
"/energy-monitor.js?v=energy-monitor-5-performance",
):
assert asset in html
+3 -3
View File
@@ -65,15 +65,15 @@ def test_unified_console_exposes_device_id_based_nfc_authorization() -> None:
assert 'async function hydratePeripheralCatalog()' in script
assert 'api("peripherals")' in script
assert 'signalSource: "backend_catalog"' in script
assert '当前没有已绑定外设' in script
assert '外设绑定 NFC 后将持续显示,解除绑定后移除' in script
assert '等待 NFC 外设靠近' in script
assert '检测到已绑定的 NFC 后,外设将在本次运行期间持续显示' in script
assert '.v2-nfc-inline' in styles
assert '.v2-nfc-dialog' in styles
assert '.v2-nfc-command-list' in styles
assert '.v2-nfc-command-option' in styles
assert '.v2-nfc-select-all' in styles
assert 'self-extension.js?v=nfc-persistent-57' in html
assert 'self-extension.js?v=nfc-session-58' in html
assert 'import "../self-extension.css";' in vite_entry
@@ -102,3 +102,17 @@ def test_device_card_surfaces_extension_toy_mqtt_delivery() -> None:
assert "extensionToySnapshot.last_error" in apply_toy
assert "applyExtensionToySnapshot(value.extension_toy" in apply_nfc
assert "正在准备 extension/toy 消息" in apply_nfc
def test_homepage_only_reveals_nfc_devices_detected_in_this_run() -> None:
source = SOURCE_PATH.read_text(encoding="utf-8")
unified = _function_source(
source,
" function buildUnifiedExtensionSync() {",
"\n function init()",
)
assert "detected_nfc_ids" in source
assert "const detectedNfcIds = new Set(" in unified
assert "detectedNfcIds.has(normalizeCardUid(device.cardUid))" in unified
assert "检测到已绑定的 NFC 后,外设将在本次运行期间持续显示" in unified