fix: compose named cockpit modes from capabilities

This commit is contained in:
vee
2026-09-07 20:52:19 +08:00
parent cf9b89508c
commit 6b2b644ee6
23 changed files with 2917 additions and 124 deletions
+54
View File
@@ -178,6 +178,7 @@ class FakeVehicleService:
def __init__(self) -> None:
self.calls: list[dict[str, object]] = []
self.mode_save_calls: list[dict[str, object]] = []
self.mode_trial_calls: list[dict[str, object]] = []
self.fail = False
def preview_native_can(self, **kwargs: object) -> dict[str, object]:
@@ -286,6 +287,7 @@ class FakeVehicleService:
"conversation_id": kwargs["conversation_id"],
"status": "succeeded",
"execution_mode": "dry_run",
"hardware_execution_allowed": False,
"supplement_required": False,
"orchestration_route": "mode_profile_create_preview",
"mode_profile_draft": {
@@ -361,6 +363,31 @@ class FakeVehicleService:
"source_request_id": source_request_id,
}
def trial_mode_profile_draft(
self,
name: str,
instruction: str,
source_request_id: str,
vehicle_id: str | None = None,
) -> dict[str, object]:
self.mode_trial_calls.append(
{
"name": name,
"instruction": instruction,
"source_request_id": source_request_id,
"vehicle_id": vehicle_id,
}
)
return {
"request_id": source_request_id,
"status": "succeeded",
"execution_mode": "dry_run",
"hardware_execution_allowed": False,
"orchestration_route": "mode_profile_draft_trial",
"intent_ir": {"spec": {"actions": []}},
"function_configs": {},
}
def _auth_disabled() -> AuthRuntime:
return AuthRuntime(AuthConfig(False, "", "", b"", 3600, 5, 300, 120, False))
@@ -402,6 +429,7 @@ class TestCodexAssistantWebApi:
def setup_method(self) -> None:
AssistantApiHandler.service.calls.clear()
AssistantApiHandler.service.mode_save_calls.clear()
AssistantApiHandler.service.mode_trial_calls.clear()
AssistantApiHandler.service.fail = False
FAKE_CODEX.available = True
FAKE_CODEX.turn_calls.clear()
@@ -636,6 +664,32 @@ class TestCodexAssistantWebApi:
assert "预览" in events[-1]["answer"]
assert "已添加" not in events[-1]["answer"]
def test_mode_draft_trial_reuses_the_server_owned_preview(self) -> None:
status, content_type, payload = self._request_json(
"/api/mode-profile-drafts/trial",
{
"name": "午休模式",
"instruction": "进入午休模式",
"source_request_id": "req-api-mode-trial",
"vehicle_id": "denza_n7",
},
)
assert status == 200
assert content_type == "application/json"
assert payload["status"] == "succeeded"
assert payload["execution_mode"] == "dry_run"
assert payload["hardware_execution_allowed"] is False
assert payload["orchestration_route"] == "mode_profile_draft_trial"
assert AssistantApiHandler.service.mode_trial_calls == [
{
"name": "午休模式",
"instruction": "进入午休模式",
"source_request_id": "req-api-mode-trial",
"vehicle_id": "denza_n7",
}
]
def test_exact_movie_mode_request_streams_a_nine_action_preview(self) -> None:
events = self.post_assistant(
{