feat: improve mode and peripheral orchestration
This commit is contained in:
@@ -157,6 +157,42 @@ def test_authorization_requires_exact_enabled_learned_bound_ability() -> None:
|
||||
authorize_extension_control_actions(parsed, disallowed)
|
||||
|
||||
|
||||
def test_authorization_injects_same_device_power_on_before_color() -> None:
|
||||
parsed = parse_extension_control_payload(
|
||||
encoded(request(action(3, "切换为红色")))
|
||||
)
|
||||
catalog = [
|
||||
capability("light-on", 2, "打开"),
|
||||
capability("light-red", 3, "切换为红色"),
|
||||
]
|
||||
|
||||
authorized = authorize_extension_control_actions(parsed, catalog)
|
||||
|
||||
ordered = sorted(
|
||||
authorized,
|
||||
key=lambda item: (item["at_ms"], item["sequence_order"]),
|
||||
)
|
||||
assert [item["action"]["parameters"]["slot"] for item in ordered] == [2, 3]
|
||||
assert ordered[0]["auto_inserted"] is True
|
||||
assert ordered[0]["dependency"] == "power_on_before_color"
|
||||
assert ordered[1]["auto_inserted"] is False
|
||||
|
||||
|
||||
def test_authorization_rejects_color_without_same_device_power_on() -> None:
|
||||
parsed = parse_extension_control_payload(
|
||||
encoded(request(action(3, "切换为红色")))
|
||||
)
|
||||
|
||||
with pytest.raises(
|
||||
ExtensionControlAuthorizationError,
|
||||
match="power-on action",
|
||||
):
|
||||
authorize_extension_control_actions(
|
||||
parsed,
|
||||
[capability("light-red", 3, "切换为红色")],
|
||||
)
|
||||
|
||||
|
||||
def test_consumer_validates_entire_request_then_executes_by_at_ms() -> None:
|
||||
catalog = [
|
||||
capability("light-on", 2, "打开"),
|
||||
@@ -184,15 +220,21 @@ def test_consumer_validates_entire_request_then_executes_by_at_ms() -> None:
|
||||
)
|
||||
)
|
||||
assert wait_until(lambda: consumer.snapshot()["state"] == "completed")
|
||||
assert [item[1]["parameters"]["slot"] for item in executions] == [3, 2]
|
||||
assert [item[1]["parameters"]["slot"] for item in executions] == [2, 3, 2]
|
||||
status = consumer.snapshot()
|
||||
assert status["processed_count"] == 1
|
||||
assert status["executed_action_count"] == 2
|
||||
assert [item["slot"] for item in status["last_results"]] == [3, 2]
|
||||
assert [item["slot"] for item in status["action_statuses"]] == [3, 2]
|
||||
assert status["executed_action_count"] == 3
|
||||
assert [item["slot"] for item in status["last_results"]] == [2, 3, 2]
|
||||
assert [item["slot"] for item in status["action_statuses"]] == [2, 3, 2]
|
||||
assert [item["auto_inserted"] for item in status["action_statuses"]] == [
|
||||
True,
|
||||
False,
|
||||
False,
|
||||
]
|
||||
assert [item["state"] for item in status["action_statuses"]] == [
|
||||
"submitted_unverified",
|
||||
"submitted_unverified",
|
||||
"submitted_unverified",
|
||||
]
|
||||
assert all(
|
||||
item["state_label"] == "已下发 · 物理效果未确认"
|
||||
|
||||
Reference in New Issue
Block a user