Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/device-service-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4601,10 +4601,11 @@ and returns `timing.completion:"queued"`.
Cardputer and to `button` elsewhere. Chords use physical key names. Core2
touch buttons share a single contact and cannot form a simultaneous
chord. These host-timed controls are separate from the legacy virtual
key queue. Avoid overlapping queued and direct input on the same key. StopWatch
on esp32sim dispatches physical A/B chords and double clicks through its
existing GPIO mappings using host-timed edges. The chord presses both
controls before waiting and releases them in reverse order. The timing
key queue. Avoid overlapping queued and direct input on the same key.
- esp32sim uses the board's press and release mappings for button chords and
double clicks. The chord presses all controls before waiting and releases
them in reverse order. A board with missing or shared button edges returns
HTTP 409 `unsupported_input` before any edges are sent. The host timing
receipt describes dispatch. Check guest evidence for the application action.
- Cardputer and Cardputer-ADV on esp32sim accept the same keyboard chord
payload. A key without an esp32sim mapping, such as `alt_r` on the original
Expand Down
4 changes: 4 additions & 0 deletions docs/device-service.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7524,6 +7524,7 @@ components:
not:
required: [hold_seconds]
- type: object
description: esp32sim double clicks require a mapped press and release for the selected control.
required: [kind, control]
additionalProperties: false
properties:
Expand Down Expand Up @@ -7559,6 +7560,9 @@ components:
description: >-
Hold two to four distinct physical controls. Cardputer and
Cardputer-ADV keyboard chords are supported by QEMU and esp32sim.
esp32sim button chords require independent press and release
mappings for all selected controls. Missing or shared edges
return HTTP 409 unsupported_input before any input is sent.
Send physical keys for Fn combinations, for example [fn, comma].
required: [kind, keys]
additionalProperties: false
Expand Down
8 changes: 4 additions & 4 deletions docs/project-snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@

## 代码与文档规模

- `platform/tools`:`105` 个 Python 模块,`63237` 行;规模最大的模块如下。
- `platform/tools`:`105` 个 Python 模块,`63248` 行;规模最大的模块如下。

| 模块 | 行数 |
| --- | ---: |
| `device_service.py` | 16555 |
| `device_service.py` | 16564 |
| `firmware_manifest.py` | 3640 |
| `user_firmware_matrix.py` | 2347 |
| `network_sandbox.py` | 2171 |
Expand All @@ -168,11 +168,11 @@

- `tests/`:`184` 个可执行 Python 测试文件,分布在 `85` 个目录;`253` 个 evidence JSON。
- `patches/`:`17` 个补丁组,`386` 个 patch 文件。
- 文档:`762` 个 Markdown 页面;除本生成页外共 `84337` 行。
- 文档:`762` 个 Markdown 页面;除本生成页外共 `84338` 行。

## 文档与测试

- 平台测试:`2616` 项。
- 平台测试:`2617` 项。
- Docs 新鲜度登记:`290` 行;其中非历史页 `269` 行,历史固定页 `21` 行。
- 文档职责分布:待办 `3`,契约 `9`,证据/差异 `135`,历史固定 `21`,实现/设计 `15`,参考 `101`,工作流/导航 `6`。
- 全量文档盘点:`762` 个 Markdown 页面;职责分布:权威/专题页 `290`,设备档案 `41`,示例 `1`,治理/入口 `9`,文档导航 `1`,其他 `10`,补丁说明 `22`,平台说明 `26`,仓内历史记录 `5`,测试/用例说明 `249`,未登记 docs 页面 `4`,第三方来源说明 `104`。
Expand Down
70 changes: 38 additions & 32 deletions platform/tests/test_device_service_esp32sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,37 +213,43 @@ def test_cardputer_adv_fixed_softap_uses_only_the_private_fixture_socket(self):
with self.assertRaises(ValueError):
runtime.spawn_command(installation, board, 12, Path("/session/flash"), network=network)

def test_stopwatch_semantic_inputs_drive_the_mapped_edges(self):
session = Esp32SimDeviceSession.__new__(Esp32SimDeviceSession)
session.spec = load_device_specs()["stopwatch"]
session.board = runtime.BOARDS["stopwatch"]
session.runtime = "esp32sim"
session.state = "running"
session.control = Mock()
session._lock = threading.Lock()
session._stop_event = Mock()
session._check_cancelled = Mock()
session._require_runtime_permission = Mock()
session._record_event = Mock()
session.snapshot = Mock(return_value={})
def test_semantic_button_inputs_drive_the_mapped_edges(self):
cases = [
({"kind": "button", "control": "a", "action": "double_click"},
[("a", 0), ("a", 1)] * 2, [0.12, 0.12, 0.12, 0], 2),
({"kind": "chord", "target": "button", "keys": ["a", "b"], "seconds": 1},
[("a", 0), ("b", 0), ("b", 1), ("a", 1)], [1, 0], 1),
({"kind": "button", "control": "b", "action": "double_click"},
[("b", 0), ("b", 1)] * 2, [0.12, 0.12, 0.12, 0], 2),
({"kind": "chord", "target": "button", "keys": ["a", "b"]},
[("a", 0), ("b", 0), ("b", 1), ("a", 1)], [0.45, 0], 1),
]
for payload, edges, waits, presses in cases:
with self.subTest(payload=payload):
session.control.reset_mock()
session._stop_event.reset_mock()
result = session.inject({**payload, "settle_seconds": 0})
self.assertTrue(result["accepted"])
self.assertEqual(result["timing"]["presses"], presses)
self.assertEqual([call.args for call in session.control.request.call_args_list],
[("button", (name, level, 0)) for name, level in edges])
self.assertEqual([call.args[0] for call in session._stop_event.wait.call_args_list], waits)

def _keyboard_session(self, device):
for device in ("stopwatch", "stickc-plus2", "basic-v27", "stackchan"):
for payload, edges, waits, presses in cases:
with self.subTest(device=device, payload=payload):
session = self._input_session(device)
result = session.inject({**payload, "settle_seconds": 0})
self.assertTrue(result["accepted"])
self.assertEqual(result["timing"]["presses"], presses)
self.assertEqual([call.args for call in session.control.request.call_args_list],
[("button", (name, level, 0)) for name, level in edges])
self.assertEqual([call.args[0] for call in session._stop_event.wait.call_args_list], waits)

def test_semantic_buttons_reject_unavailable_or_shared_edges_before_dispatch(self):
chord = {"kind": "chord", "target": "button", "keys": ["a", "b"]}
for device, payload in (
("papers3", chord),
("atoms3", chord),
("core2", chord),
("stopwatch", {**chord, "keys": ["a", "power"]}),
("cores3", {"kind": "button", "control": "power", "action": "double_click"}),
):
with self.subTest(device=device, payload=payload):
session = self._input_session(device)
with self.assertRaises(ServiceError) as error:
session.inject(payload)
self.assertEqual((error.exception.code, error.exception.status), ("unsupported_input", 409))
session.control.request.assert_not_called()

def _input_session(self, device):
session = Esp32SimDeviceSession.__new__(Esp32SimDeviceSession)
session.spec = load_device_specs()[device]
session.board = runtime.BOARDS[device]
Expand All @@ -261,7 +267,7 @@ def _keyboard_session(self, device):
def test_cardputer_keyboard_chords_use_physical_key_edges(self):
for device in ("cardputer", "cardputer-adv"):
with self.subTest(device=device):
session = self._keyboard_session(device)
session = self._input_session(device)
payload = {"kind": "chord", "keys": ["Fn", "shift", "comma"], "settle_seconds": 0.2}
receipt = session.inject(payload)
self.assertTrue(receipt["accepted"])
Expand Down Expand Up @@ -297,7 +303,7 @@ def test_cardputer_keyboard_chords_use_physical_key_edges(self):

def test_esp32sim_chords_check_every_qemu_profile_key(self):
for device in ("cardputer", "cardputer-adv"):
session = self._keyboard_session(device)
session = self._input_session(device)
for key in board_controls(session.spec)["keyboard"]:
with self.subTest(device=device, key=key):
session.control.reset_mock()
Expand All @@ -319,7 +325,7 @@ def test_esp32sim_chords_check_every_qemu_profile_key(self):
self.assertEqual(session.control.request.call_count, 4)

def test_keyboard_chord_releases_on_partial_press_failure(self):
session = self._keyboard_session("cardputer-adv")
session = self._input_session("cardputer-adv")
failure = ServiceError("runtime_input_rejected", "second press failed", 409)
session.control.request.side_effect = [None, failure, None, None]
with self.assertRaises(ServiceError) as error:
Expand All @@ -332,10 +338,10 @@ def test_keyboard_chord_releases_on_partial_press_failure(self):
session._record_event.assert_not_called()

def test_chord_on_unmapped_board_returns_conflict(self):
session = self._keyboard_session("cores3")
session = self._input_session("cores3")
with self.assertRaises(ServiceError) as error:
session.inject({"kind": "chord", "keys": ["fn", "1"]})
self.assertEqual((error.exception.code, error.exception.status), ("not_supported_on_runtime", 409))
self.assertEqual((error.exception.code, error.exception.status), ("unsupported_input", 409))
session.control.request.assert_not_called()

def test_dual_kmeter_variant_preserves_control_board_and_bounds_fixture(self):
Expand Down
19 changes: 14 additions & 5 deletions platform/tools/device_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11795,11 +11795,13 @@ def _decode_frame_metrics(self, data, *, analyze):

def validate_input(self, payload):
if isinstance(payload, dict) and (
(payload.get("kind") == "chord" and self.spec.id in {"stopwatch", "cardputer", "cardputer-adv"})
or (self.spec.id == "stopwatch" and payload.get("kind") == "button"
and payload.get("action") == "double_click")
payload.get("kind") == "chord"
or (payload.get("kind") == "button" and payload.get("action") == "double_click")
):
command = normalize_semantic_input(self, payload, native=True)
command = normalize_semantic_input(
self, payload, native=True,
native_button_code=lambda name: esp32sim.gpio_button(self.spec.id, name),
)
if command["target"] == "keyboard":
for key in command["qcodes"]:
if esp32sim.KEY_ALIASES.get(key, key) not in esp32sim.KEYS:
Expand All @@ -11819,7 +11821,14 @@ def inject(self, payload):
target = command["target"]
field = "key" if target == "keyboard" else "control"
names = command["qcodes"] if target == "keyboard" else command["names"]
edges = self._input_edges(target, field, names)
try:
edges = self._input_edges(target, field, names)
except ServiceError as error:
if target != "button" or error.code not in {"invalid_input", "not_supported_on_runtime"}:
raise
raise ServiceError("unsupported_input",
"esp32sim requires an independent press and release mapping for each button",
409) from error
receipt = (
{key: value for key, value in command.items() if key not in {"op", "qcodes"}}
if command["kind"] == "chord" else command
Expand Down
4 changes: 3 additions & 1 deletion platform/tools/device_service_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def keyboard_code(spec, controls, key, *, in_chord=False):
return [key]


def normalize_semantic_input(session, payload, *, native):
def normalize_semantic_input(session, payload, *, native, native_button_code=None):
kind = payload["kind"]
if not native or getattr(session, "management_binding", None):
raise unavailable("semantic actions require an independent native QMP session")
Expand Down Expand Up @@ -143,6 +143,8 @@ def normalize_semantic_input(session, payload, *, native):
qcodes.extend(keyboard_code(session.spec, controls, name, in_chord=kind == "chord"))
else:
qcode = controls.get("buttons", {}).get(name)
if qcode is None and native_button_code is not None:
qcode = native_button_code(name)
if qcode is None:
raise unavailable(f"button {name} has no model input on this board")
qcodes.append(qcode)
Expand Down
2 changes: 1 addition & 1 deletion tests/uiflow2/api_sweep/inventory_api.source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scope": "Every documented Device Service HTTP operation; positive functionality and rejection-only coverage are distinct.",
"contract": "docs/device-service.openapi.yaml",
"contract_version": "1.103.0",
"contract_sha256": "d4c8895d8f98907d38005b4bef72629ebd36fb84f7d80eae19655b2cf2fe6961",
"contract_sha256": "22460745ac3d6d2edeb76853546aeeca680e85ecdf20cdf3591a8d57962a9834",
"validation_category": "virtual-device and live HTTP; hardware NOT RUN",
"operation_id_format": "METHOD /OpenAPI/path/{parameter}",
"operations": [
Expand Down
Loading