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
@@ -1193,26 +1193,34 @@ MAXIMUM_SCENE_REQUESTS = (
_scene_request("ambient_light.set_power", "vehicle", {"state": "off"}),
_scene_request("interior_light.set_indoor_power", "vehicle", {"state": "off"}),
_scene_request("interior_light.set_reading_power", "all", {"state": "off"}),
_scene_request("window.set_position", "rear_left", {"position_pct": 0}),
_scene_request("window.set_position", "rear_right", {"position_pct": 0}),
_scene_request("ambient_light.set_mode", "vehicle", {"mode": "romantic"}),
_scene_request("ambient_light.set_brightness_level", "vehicle", {"brightness_level": 2}),
_scene_request("ambient_light.set_color_index", "vehicle", {"color_index": 6}),
_scene_request("seat.set_heating", "passenger", {"state": "on", "level": 1}),
_scene_request("seat.set_backrest_recline", "passenger", {"position_pct": 45}),
_scene_request("seat.set_legrest_height", "passenger", {"position_pct": 35}),
)
def test_scene_request_limit_accepts_exactly_twelve_verified_actions(
def test_scene_request_limit_accepts_exactly_twenty_verified_actions(
mode_service: tuple[SeatDemoService, Path],
) -> None:
service, user_root = mode_service
assert len(MAXIMUM_SCENE_REQUESTS) == MAX_PLAN_REQUESTS == 12
assert len(MAXIMUM_SCENE_REQUESTS) == MAX_PLAN_REQUESTS == 20
result = _preview_without_hardware(
service,
"构建一个十二动作模式",
conversation_id="conv-twelve-scene-actions",
"构建一个二十动作模式",
conversation_id="conv-twenty-scene-actions",
assistant_plan=_scene_plan(*MAXIMUM_SCENE_REQUESTS),
)
_assert_successful_preview(result, name="十二动作模式", operation_count=12)
_assert_successful_preview(result, name="二十动作模式", operation_count=20)
assert not list(user_root.rglob("*.yaml"))
def test_scene_request_limit_rejects_thirteen_before_any_hardware_or_persistence(
def test_scene_request_limit_rejects_twenty_one_before_any_hardware_or_persistence(
mode_service: tuple[SeatDemoService, Path],
) -> None:
service, user_root = mode_service
@@ -1225,8 +1233,8 @@ def test_scene_request_limit_rejects_thirteen_before_any_hardware_or_persistence
with pytest.raises(ValueError, match="too many requests"):
_preview_without_hardware(
service,
"构建一个十三动作模式",
conversation_id="conv-thirteen-scene-actions",
"构建一个二十一动作模式",
conversation_id="conv-twenty-one-scene-actions",
assistant_plan=_scene_plan(*oversized),
)
assert not list(user_root.rglob("*.yaml"))