fix: execute mode cards through deterministic assistant route
This commit is contained in:
@@ -757,6 +757,34 @@ class TestCodexAssistantWebApi:
|
||||
assert not FAKE_CODEX.turn_calls
|
||||
assert not FAKE_CODEX.bridge_results
|
||||
|
||||
def test_saved_mode_execution_uses_deterministic_route_over_http(self) -> None:
|
||||
message = "进入办公模式"
|
||||
FAKE_CODEX.available = False
|
||||
with patch.object(
|
||||
AssistantApiHandler,
|
||||
"assistant_capability_catalog",
|
||||
StaticSavedModeCatalog(),
|
||||
):
|
||||
events = self.post_assistant(
|
||||
{
|
||||
"message": message,
|
||||
"conversation_id": "conv-api-saved-mode-execute",
|
||||
"execution_mode": "dry_run",
|
||||
}
|
||||
)
|
||||
|
||||
assert events[0]["route"] == "mode_profile_execute"
|
||||
assert events[0]["engine"] == "n7web-mode-profile-runner"
|
||||
action = next(event for event in events if event["type"] == "action.completed")
|
||||
assert action["success"] is True
|
||||
assert action["payload"]["execution_mode"] == "dry_run"
|
||||
assert events[-1]["route"] == "mode_profile_execute"
|
||||
assert "模拟编排" in events[-1]["answer"]
|
||||
assert len(AssistantApiHandler.service.calls) == 1
|
||||
assert AssistantApiHandler.service.calls[0]["utterance"] == message
|
||||
assert not FAKE_CODEX.turn_calls
|
||||
assert not FAKE_CODEX.bridge_results
|
||||
|
||||
def test_saved_mode_update_uses_deterministic_management_route_over_http(
|
||||
self,
|
||||
) -> None:
|
||||
|
||||
@@ -621,7 +621,7 @@ operations:
|
||||
def test_static_console_and_runtime_endpoint(self) -> None:
|
||||
with self.opener.open(f"{self.base_url}/", timeout=3) as response:
|
||||
html = response.read().decode("utf-8")
|
||||
with self.opener.open(f"{self.base_url}/app.js?v=dual-seat-129", timeout=3) as response:
|
||||
with self.opener.open(f"{self.base_url}/app.js?v=dual-seat-130", timeout=3) as response:
|
||||
app_script = response.read().decode("utf-8")
|
||||
with self.opener.open(
|
||||
f"{self.base_url}/gesture-control.js?v=android-pad-9", timeout=3
|
||||
@@ -697,7 +697,7 @@ operations:
|
||||
self.assertIn("CMD 0x431 · FB 0x41A · CH1", html)
|
||||
self.assertIn("CMD 0x431 · FB 0x388 · CH1", html)
|
||||
self.assertNotIn("透明车体 · 实体设备", html)
|
||||
self.assertIn('src="/app.js?v=dual-seat-129"', html)
|
||||
self.assertIn('src="/app.js?v=dual-seat-130"', html)
|
||||
self.assertIn('href="/styles.css?v=dual-seat-23"', html)
|
||||
self.assertIn('src="/gesture-control.js?v=android-pad-9"', html)
|
||||
self.assertNotIn('class="vehicle-system-hud"', html)
|
||||
@@ -992,14 +992,14 @@ operations:
|
||||
self.assertIn("CAN 指令已提交,等待车辆状态确认", console_script)
|
||||
self.assertIn('canvas.addEventListener("webglcontextlost"', app_script)
|
||||
self.assertIn('"cognitive-agent:module-change"', app_script)
|
||||
self.assertIn('const CACHE_VERSION = "cognitive-agent-pad-v276"', service_worker)
|
||||
self.assertIn('const CACHE_VERSION = "cognitive-agent-pad-v277"', service_worker)
|
||||
self.assertIn('/console-v2.css?v=delivery-state-66', service_worker)
|
||||
self.assertIn('/console-v2.js?v=delivery-state-62', service_worker)
|
||||
self.assertIn('/assistant-chat.css?v=codex-assistant-26', service_worker)
|
||||
self.assertIn('/assistant-chat.js?v=codex-assistant-26', service_worker)
|
||||
self.assertIn('/energy-monitor.css?v=energy-monitor-4', service_worker)
|
||||
self.assertIn('/energy-monitor.js?v=energy-monitor-4', service_worker)
|
||||
self.assertIn('"/app.js?v=dual-seat-129"', service_worker)
|
||||
self.assertIn('"/app.js?v=dual-seat-130"', service_worker)
|
||||
self.assertIn('"/speech-input.js?v=sensevoice-13"', service_worker)
|
||||
self.assertIn('"/speech-input.css?v=sensevoice-7"', service_worker)
|
||||
self.assertIn('"/speech-audio-worklet.js?v=sensevoice-5"', service_worker)
|
||||
@@ -1456,7 +1456,7 @@ operations:
|
||||
) as response:
|
||||
extension_script = response.read().decode("utf-8")
|
||||
with self.opener.open(
|
||||
f"{self.base_url}/app.js?v=dual-seat-129", timeout=3
|
||||
f"{self.base_url}/app.js?v=dual-seat-130", timeout=3
|
||||
) as response:
|
||||
app_script = response.read().decode("utf-8")
|
||||
|
||||
|
||||
@@ -645,7 +645,7 @@ def test_every_assistant_callable_capability_reaches_the_real_tool_boundary(
|
||||
assert action_event["success"] is True
|
||||
|
||||
|
||||
def test_every_catalog_mode_can_execute_through_the_assistant_tool_boundary(
|
||||
def test_every_catalog_mode_executes_through_the_deterministic_assistant_route(
|
||||
vehicle_service: SeatDemoService,
|
||||
catalog: AssistantCapabilityCatalog,
|
||||
) -> None:
|
||||
@@ -690,7 +690,7 @@ def test_every_catalog_mode_can_execute_through_the_assistant_tool_boundary(
|
||||
return result
|
||||
|
||||
client.on_turn = invoke_tool
|
||||
_stream_with_catalog(
|
||||
result, events = _stream_with_catalog(
|
||||
assistant,
|
||||
catalog,
|
||||
message,
|
||||
@@ -700,9 +700,11 @@ def test_every_catalog_mode_can_execute_through_the_assistant_tool_boundary(
|
||||
|
||||
assert raw_results[0]["status"] == "succeeded", mode["id"]
|
||||
assert raw_results[0]["matched_modes"][0]["id"] == mode["id"]
|
||||
assert tool_results[0]["verified"] is False
|
||||
assert tool_results[0]["verification_status"] == "simulated"
|
||||
assert tool_results[0]["actions"], mode["id"]
|
||||
assert tool_results == []
|
||||
assert client.turn_calls == 0
|
||||
assert result["route"] == "mode_profile_execute"
|
||||
assert result["success"] is True
|
||||
assert events[0]["engine"] == "n7web-mode-profile-runner"
|
||||
|
||||
|
||||
def test_every_catalog_mode_rejects_incompatible_explicit_seat_scopes(
|
||||
|
||||
@@ -19,7 +19,7 @@ def test_console_contains_ai_assistant_surface():
|
||||
|
||||
def test_codex_assistant_assets_are_versioned_together_in_the_service_worker():
|
||||
service_worker = (ROOT / "apps/web-console/service-worker.js").read_text(encoding="utf-8")
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v276"' in service_worker
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v277"' in service_worker
|
||||
assert '"/assistant-chat.css?v=codex-assistant-26"' in service_worker
|
||||
assert '"/assistant-chat.js?v=codex-assistant-26"' in service_worker
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from cognitive_agent.application.codex_assistant import (
|
||||
CodexAssistantService,
|
||||
CodexVehicleToolError,
|
||||
_authorize_vehicle_request,
|
||||
_catalog_exact_mode_execution_id,
|
||||
_catalog_exact_mode_match_count,
|
||||
)
|
||||
|
||||
@@ -81,6 +82,60 @@ def test_catalog_mode_resolution_distinguishes_unknown_ambiguous_and_unavailable
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
(
|
||||
"进入小憩模式",
|
||||
"请进入小憩模式",
|
||||
"帮我启动午休模式吧",
|
||||
"麻烦帮我执行小憩模式一下",
|
||||
"立即开启小憩模式",
|
||||
"切换到午休模式",
|
||||
),
|
||||
)
|
||||
def test_catalog_resolves_bounded_saved_mode_execution_phrasings(message: str) -> None:
|
||||
catalog = {
|
||||
"modes": [
|
||||
{
|
||||
"id": "nap",
|
||||
"name": "小憩模式",
|
||||
"aliases": ["午休模式"],
|
||||
"assistant_callable": True,
|
||||
}
|
||||
],
|
||||
"source_status": {"modes": "ready"},
|
||||
}
|
||||
|
||||
assert _catalog_exact_mode_execution_id(catalog, message) == "nap"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
(
|
||||
"不要进入小憩模式",
|
||||
"小憩模式会执行什么",
|
||||
"能否进入小憩模式?",
|
||||
"进入不存在模式",
|
||||
),
|
||||
)
|
||||
def test_catalog_saved_mode_execution_rejects_denials_questions_and_unknown_modes(
|
||||
message: str,
|
||||
) -> None:
|
||||
catalog = {
|
||||
"modes": [
|
||||
{
|
||||
"id": "nap",
|
||||
"name": "小憩模式",
|
||||
"aliases": ["午休模式"],
|
||||
"assistant_callable": True,
|
||||
}
|
||||
],
|
||||
"source_status": {"modes": "ready"},
|
||||
}
|
||||
|
||||
assert _catalog_exact_mode_execution_id(catalog, message) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
(
|
||||
@@ -402,6 +457,59 @@ def test_general_question_streams_from_codex_without_vehicle_execution() -> None
|
||||
assert client.finished[0].turn_id == "turn-1"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
(
|
||||
"进入小憩模式",
|
||||
"请帮我启动午休模式吧",
|
||||
"麻烦执行小憩模式一下",
|
||||
),
|
||||
)
|
||||
def test_registered_mode_execution_uses_fast_local_route_without_codex(
|
||||
message: str,
|
||||
) -> None:
|
||||
client = FakeCodexClient(available=False)
|
||||
assistant = CodexAssistantService(client)
|
||||
calls: list[str] = []
|
||||
catalog = {
|
||||
"modes": [
|
||||
{
|
||||
"id": "nap",
|
||||
"name": "小憩模式",
|
||||
"aliases": ["午休模式"],
|
||||
"assistant_callable": True,
|
||||
}
|
||||
],
|
||||
"source_status": {"modes": "ready"},
|
||||
}
|
||||
|
||||
def execute(instruction: str, progress: Callable[[dict[str, object]], None]):
|
||||
calls.append(instruction)
|
||||
result = _sample_control_result(mode="dry_run")
|
||||
result["utterance"] = instruction
|
||||
progress(result)
|
||||
return result
|
||||
|
||||
result, events = _stream(
|
||||
assistant,
|
||||
message,
|
||||
execute_control=execute,
|
||||
capability_snapshot=catalog,
|
||||
)
|
||||
|
||||
assert result["route"] == "mode_profile_execute"
|
||||
assert result["success"] is True
|
||||
assert calls == [message]
|
||||
assert client.turn_calls == []
|
||||
assert events[0]["engine"] == "n7web-mode-profile-runner"
|
||||
assert events[1]["display_text"] == "正在载入并执行已保存的功能模式……"
|
||||
assert any(
|
||||
event.get("display_text") == "功能模式模拟编排已完成"
|
||||
for event in events
|
||||
)
|
||||
assert "模拟编排" in result["answer"]
|
||||
|
||||
|
||||
def test_registered_name_only_mode_keeps_the_fast_local_route_without_codex() -> None:
|
||||
client = FakeCodexClient(available=False)
|
||||
assistant = CodexAssistantService(client)
|
||||
|
||||
@@ -38,7 +38,7 @@ def test_energy_monitor_assets_are_versioned_and_cached() -> None:
|
||||
assert html.index("/assistant-chat.js?v=codex-assistant-26") < html.index(
|
||||
"/energy-monitor.js?v=energy-monitor-4"
|
||||
)
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v276"' in service_worker
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v277"' in service_worker
|
||||
|
||||
|
||||
def test_energy_monitor_uses_the_fifth_shared_dock_icon_and_starts_closed() -> None:
|
||||
|
||||
@@ -47,7 +47,7 @@ def test_theme_asset_versions_are_consistent_with_the_pwa_shell() -> None:
|
||||
):
|
||||
assert asset in html
|
||||
assert f'"{asset}"' in service_worker
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v276"' in service_worker
|
||||
assert 'const CACHE_VERSION = "cognitive-agent-pad-v277"' in service_worker
|
||||
|
||||
|
||||
def test_vehicle_twin_icons_and_nested_overlays_use_semantic_tokens() -> None:
|
||||
|
||||
@@ -271,6 +271,7 @@ const savedMode = {
|
||||
command_flow: { source_request_id: "saved-request" },
|
||||
};
|
||||
const context = {
|
||||
state: { pendingModeProfileId: null },
|
||||
Event: class Event {
|
||||
constructor(type, options = {}) { this.type = type; this.bubbles = options.bubbles; }
|
||||
},
|
||||
@@ -282,6 +283,7 @@ const context = {
|
||||
},
|
||||
modeProfiles() { return [savedMode]; },
|
||||
setModeRailSelection(mode) { calls.push(["select", mode?.id]); },
|
||||
setModeExecutionState(modeId, status) { calls.push(["state", modeId, status]); },
|
||||
closeModeGallery(options) { calls.push(["close", options.restoreFocus]); },
|
||||
showToast(message) { calls.push(["toast", message]); },
|
||||
$(selector) {
|
||||
@@ -295,6 +297,7 @@ console.log(JSON.stringify({
|
||||
calls,
|
||||
value: input.value,
|
||||
speechDataset: input.dataset,
|
||||
pendingModeProfileId: context.state.pendingModeProfileId,
|
||||
}));
|
||||
"""
|
||||
completed = subprocess.run(
|
||||
@@ -312,10 +315,12 @@ console.log(JSON.stringify({
|
||||
["close", False],
|
||||
["open"],
|
||||
["input", "input", True, "进入阅读模式"],
|
||||
["state", "reading-user", "running"],
|
||||
["submit", "进入阅读模式"],
|
||||
]
|
||||
assert result["value"] == "进入阅读模式"
|
||||
assert result["speechDataset"] == {}
|
||||
assert result["pendingModeProfileId"] == "reading-user"
|
||||
assert "executeSavedModeProfile" not in snippet
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user