feat: make mode creation preview-only and cache-safe

This commit is contained in:
Miayui
2026-09-20 19:32:03 +08:00
parent bfff1b515c
commit 89707a42e2
28 changed files with 1375 additions and 165 deletions
@@ -26,17 +26,18 @@ CALLBACK_URL = "http://127.0.0.1:8765/api/internal/codex/vehicle-control"
@pytest.mark.parametrize(
("message", "expected_name"),
("message", "expected_name", "expected_operation_count"),
(
("构建一个星夜模式", "星夜模式"),
("创建学习模式", "学习模式"),
("创建中秋欢快模式", "中秋欢快模式"),
("构建一个星夜模式", "星夜模式", 13),
("创建学习模式", "学习模式", 13),
("创建中秋欢快模式", "中秋欢快模式", 13),
),
)
def test_structured_scene_turn_reaches_the_complete_local_dry_run_pipeline(
tmp_path: Path,
message: str,
expected_name: str,
expected_operation_count: int,
) -> None:
service = SeatDemoService(REPOSITORY_ROOT)
service.artifact_root = tmp_path / "runs"
@@ -107,20 +108,37 @@ def test_structured_scene_turn_reaches_the_complete_local_dry_run_pipeline(
assert result["orchestration_route"] == "mode_profile_create_preview"
assert draft["name"] == expected_name
assert draft["generation_source"] == "codex_scene_composition"
assert draft["operation_count"] == 2
assert draft["operation_count"] == expected_operation_count
capabilities = {
action["capability"] for action in result["actions"]
}
assert capabilities == {
expected_capabilities = {
"climate.set_power",
"climate.set_temperature",
"climate.set_fan_level",
"climate.set_cycle_mode",
"window.set_position",
"roof.set_shade_position",
"seat.set_ventilation",
"seat.set_backrest_recline",
"seat.set_legrest_height",
"ambient_light.set_power",
}
assert capabilities == expected_capabilities
window_actions = [
action for action in result["actions"]
if action["capability"] == "window.set_position"
]
assert {
action["target"]["zone"] for action in window_actions
} == {"front_left", "front_right", "rear_left", "rear_right"}
assert all(action["parameters"] == {"position_pct": 0} for action in window_actions)
assert not list((tmp_path / "user-modes").rglob("*.yaml"))
assert any(event.get("type") == "action.completed" for event in events)
assert all("request_token" not in str(event) for event in events)
def test_mid_autumn_cloud_scene_requires_authorized_flashing_light(
def test_mid_autumn_cloud_scene_requires_native_and_decorative_light_controls(
tmp_path: Path,
) -> None:
service = SeatDemoService(REPOSITORY_ROOT)
@@ -161,6 +179,45 @@ def test_mid_autumn_cloud_scene_requires_authorized_flashing_light(
"risk": "low",
"slot": 3,
},
{
"id": "ir-slot:light-strip:21",
"status": "learned",
"enabled": True,
"device_id": "light-strip",
"device_name": "灯带",
"object_names": ["灯带", "LED 灯条"],
"card_uid": "A1B2C3D4",
"action": "打开",
"action_names": ["打开", "开启"],
"risk": "low",
"slot": 21,
},
{
"id": "ir-slot:light-strip:23",
"status": "learned",
"enabled": True,
"device_id": "light-strip",
"device_name": "灯带",
"object_names": ["灯带", "LED 灯条"],
"card_uid": "A1B2C3D4",
"action": "切换为红色",
"action_names": ["切换为红色", "设置为红色"],
"risk": "low",
"slot": 23,
},
{
"id": "ir-slot:ambient-light:31",
"status": "learned",
"enabled": True,
"device_id": "ambient-light",
"device_name": "外设氛围灯",
"object_names": ["外设氛围灯", "氛围彩灯玩具"],
"card_uid": "B1C2D3E4",
"action": "打开",
"action_names": ["打开", "开启"],
"risk": "low",
"slot": 31,
},
]
)
handler = object.__new__(SeatDemoHandler)
@@ -235,5 +292,29 @@ def test_mid_autumn_cloud_scene_requires_authorized_flashing_light(
assert response["success"] is True
assert result["status"] == "succeeded"
assert result["execution_mode"] == "dry_run"
assert [item["slot"] for item in result["infrared_actions"]] == [2, 3]
assert [item["slot"] for item in result["infrared_actions"]] == [
2,
31,
21,
]
capabilities = {
action["capability"]
for action in result["actions"]
}
assert "climate.set_temperature" in capabilities
assert "ambient_light.set_power" in capabilities
assert "roof.set_shade_position" in capabilities
assert {
"climate.set_power",
"climate.set_temperature",
"climate.set_fan_level",
"climate.set_cycle_mode",
"window.set_position",
"seat.set_ventilation",
"seat.set_backrest_recline",
"seat.set_legrest_height",
"ambient_light.set_power",
"infrared.emit",
} <= capabilities
assert result["mode_profile_draft"]["operation_count"] == 16
assert result["mode_profile_draft"]["domains"][-1] == "self_extension"