feat: update CAN integration and T2G seat firmware
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from cognitive_agent.application.domain_runtime import ConfiguredDomainRuntime
|
||||
from cognitive_agent.application.mode_profile import ModeProfileRegistry
|
||||
@@ -254,7 +254,24 @@ class MultiDomainServiceTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
by_capability["seat.set_legrest_height"]["parameters"],
|
||||
{"position_pct": 87, "angle_deg": 163},
|
||||
{"position_pct": 94, "angle_deg": 163},
|
||||
)
|
||||
|
||||
def test_named_mode_profile_suppresses_generic_local_parser_ambiguity(self) -> None:
|
||||
result = self.service.process(
|
||||
"副驾进入零重力模式",
|
||||
"local",
|
||||
"conv-zero-gravity-local-mode",
|
||||
vehicle_id="denza_n7",
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "succeeded")
|
||||
self.assertEqual(result["matched_modes"][0]["id"], "zero_gravity")
|
||||
self.assertFalse(
|
||||
any(
|
||||
issue.get("code") == "AMBIGUOUS_INTENT"
|
||||
for issue in result["validation"]
|
||||
)
|
||||
)
|
||||
|
||||
def test_named_mode_profile_combines_with_temporary_roof_request(self) -> None:
|
||||
@@ -294,6 +311,252 @@ class MultiDomainServiceTests(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_hardware_orchestration_uses_physical_passenger_seat_and_virtual_roof(
|
||||
self,
|
||||
) -> None:
|
||||
model_output = {
|
||||
"detected_domains": ["seat", "roof"],
|
||||
"requests": [
|
||||
{
|
||||
"domain": "seat",
|
||||
"capability": "seat.set_backrest_recline",
|
||||
"target_scope": "passenger",
|
||||
"operation": "set",
|
||||
"parameters": [{"name": "position_pct", "value": 55}],
|
||||
"reason": "调整副驾靠背。",
|
||||
},
|
||||
{
|
||||
"domain": "roof",
|
||||
"capability": "roof.set_transmittance",
|
||||
"target_scope": "vehicle",
|
||||
"operation": "set",
|
||||
"parameters": [{"name": "transmittance_pct", "value": 20}],
|
||||
"reason": "降低天幕透光率。",
|
||||
},
|
||||
],
|
||||
"ambiguities": [],
|
||||
"decision_summary": ["执行副驾与天幕联合模式。"],
|
||||
"confidence": 0.96,
|
||||
}
|
||||
physical_state = {
|
||||
"position": {
|
||||
"longitudinal": {"position_pct": 51, "position_valid": True},
|
||||
"cushion_tilt": {"position_pct": 11, "position_valid": True},
|
||||
"backrest_recline": {"position_pct": 54, "position_valid": True},
|
||||
"legrest_height": {"position_pct": 0, "position_valid": True},
|
||||
},
|
||||
"ventilation": {"state": "off", "level": 0},
|
||||
"heating": {"state": "off", "level": 0},
|
||||
"captured_at": "2026-07-31T04:00:00Z",
|
||||
"complete": True,
|
||||
"missing": [],
|
||||
}
|
||||
|
||||
def execute_hardware(plan, config, devices):
|
||||
del plan, devices
|
||||
operation = config["spec"]["operations"][0]
|
||||
return {
|
||||
"apiVersion": "cognitive-agent/v1alpha1",
|
||||
"kind": "ExecutionReport",
|
||||
"metadata": {
|
||||
"id": "report-hardware-test",
|
||||
"name": "T2G seat hardware execution report",
|
||||
"version": "1.0.0",
|
||||
"request_id": config["metadata"]["request_id"],
|
||||
"labels": {"simulation": "false"},
|
||||
},
|
||||
"spec": {
|
||||
"mode": "hil",
|
||||
"status": "succeeded",
|
||||
"started_at": "2026-07-31T04:00:00Z",
|
||||
"finished_at": "2026-07-31T04:00:01Z",
|
||||
"physical_state": physical_state,
|
||||
"results": [
|
||||
{
|
||||
"ref": operation["id"],
|
||||
"domain": "seat",
|
||||
"status": "succeeded",
|
||||
"message": "physical target reached",
|
||||
"telemetry": {
|
||||
"motion_axis": "backrest_recline",
|
||||
"effective_position_pct": 54,
|
||||
"position_valid": True,
|
||||
"simulated": False,
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
hardware_executor = MagicMock()
|
||||
hardware_executor.execute.side_effect = execute_hardware
|
||||
initial_driver_backrest = self.service.conversations.snapshot(
|
||||
"conv-mixed-hardware-success"
|
||||
)["devices"]["driver"]["position"]["backrest_recline"]["position_pct"]
|
||||
with (
|
||||
patch.object(self.service.openai, "interpret", return_value=model_output),
|
||||
patch.object(type(self.service.hardware_settings), "authorize"),
|
||||
patch.object(
|
||||
type(self.service.hardware_settings),
|
||||
"validate_function_config",
|
||||
),
|
||||
patch.object(
|
||||
self.service,
|
||||
"_new_hardware_executor",
|
||||
return_value=hardware_executor,
|
||||
) as executor_factory,
|
||||
):
|
||||
result = self.service.process(
|
||||
"副驾靠背调到55%,天幕透光率调到20%",
|
||||
"openai",
|
||||
"conv-mixed-hardware-success",
|
||||
execution_mode="hardware",
|
||||
approval_token="test-token",
|
||||
vehicle_id="denza_n7",
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "succeeded")
|
||||
self.assertEqual(result["execution_report"]["spec"]["mode"], "hil")
|
||||
self.assertEqual(
|
||||
result["execution_report"]["metadata"]["labels"]["simulation"],
|
||||
"mixed",
|
||||
)
|
||||
executor_factory.assert_called_once_with()
|
||||
hardware_executor.execute.assert_called_once()
|
||||
by_domain = {
|
||||
item["domain"]: item
|
||||
for item in result["execution_report"]["spec"]["results"]
|
||||
}
|
||||
self.assertFalse(by_domain["seat"]["telemetry"]["simulated"])
|
||||
self.assertTrue(by_domain["roof"]["telemetry"]["simulated"])
|
||||
self.assertEqual(
|
||||
result["actuator_state"]["passenger"]["position"][
|
||||
"backrest_recline"
|
||||
]["position_pct"],
|
||||
54,
|
||||
)
|
||||
self.assertEqual(
|
||||
result["actuator_state"]["driver"]["position"]["backrest_recline"][
|
||||
"position_pct"
|
||||
],
|
||||
initial_driver_backrest,
|
||||
)
|
||||
self.assertEqual(result["domain_state"]["roof"]["transmittance_pct"], 20)
|
||||
|
||||
def test_hardware_orchestration_failure_still_synchronizes_physical_seat(
|
||||
self,
|
||||
) -> None:
|
||||
model_output = {
|
||||
"detected_domains": ["seat", "roof"],
|
||||
"requests": [
|
||||
{
|
||||
"domain": "seat",
|
||||
"capability": "seat.set_longitudinal_position",
|
||||
"target_scope": "passenger",
|
||||
"operation": "set",
|
||||
"parameters": [{"name": "position_pct", "value": 100}],
|
||||
"reason": "移动副驾。",
|
||||
},
|
||||
{
|
||||
"domain": "roof",
|
||||
"capability": "roof.set_transmittance",
|
||||
"target_scope": "vehicle",
|
||||
"operation": "set",
|
||||
"parameters": [{"name": "transmittance_pct", "value": 20}],
|
||||
"reason": "降低天幕透光率。",
|
||||
},
|
||||
],
|
||||
"ambiguities": [],
|
||||
"decision_summary": ["执行副驾与天幕联合模式。"],
|
||||
"confidence": 0.96,
|
||||
}
|
||||
hardware_executor = MagicMock()
|
||||
|
||||
def execute_hardware(plan, config, devices):
|
||||
del plan, devices
|
||||
return {
|
||||
"apiVersion": "cognitive-agent/v1alpha1",
|
||||
"kind": "ExecutionReport",
|
||||
"metadata": {
|
||||
"id": "report-hardware-failure-test",
|
||||
"name": "T2G seat hardware execution report",
|
||||
"version": "1.0.0",
|
||||
"request_id": config["metadata"]["request_id"],
|
||||
"labels": {"simulation": "false"},
|
||||
},
|
||||
"spec": {
|
||||
"mode": "hil",
|
||||
"status": "failed",
|
||||
"started_at": "2026-07-31T04:00:00Z",
|
||||
"finished_at": "2026-07-31T04:00:01Z",
|
||||
"physical_state": {
|
||||
"position": {
|
||||
"longitudinal": {
|
||||
"position_pct": 63,
|
||||
"position_valid": True,
|
||||
}
|
||||
},
|
||||
"captured_at": "2026-07-31T04:00:01Z",
|
||||
"complete": False,
|
||||
"missing": ["cushion_tilt", "backrest_recline", "legrest_height"],
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"ref": config["spec"]["operations"][0]["id"],
|
||||
"domain": "seat",
|
||||
"status": "failed",
|
||||
"message": "Motor0 TIMEOUT",
|
||||
"telemetry": {"simulated": False},
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
hardware_executor.execute.side_effect = execute_hardware
|
||||
initial_roof = self.service.conversations.snapshot(
|
||||
"conv-mixed-hardware-failure"
|
||||
)["domain_devices"]["roof"]["transmittance_pct"]
|
||||
with (
|
||||
patch.object(self.service.openai, "interpret", return_value=model_output),
|
||||
patch.object(type(self.service.hardware_settings), "authorize"),
|
||||
patch.object(
|
||||
type(self.service.hardware_settings),
|
||||
"validate_function_config",
|
||||
),
|
||||
patch.object(
|
||||
self.service,
|
||||
"_new_hardware_executor",
|
||||
return_value=hardware_executor,
|
||||
),
|
||||
):
|
||||
result = self.service.process(
|
||||
"副驾水平移到100%,天幕透光率调到20%",
|
||||
"openai",
|
||||
"conv-mixed-hardware-failure",
|
||||
execution_mode="hardware",
|
||||
approval_token="test-token",
|
||||
vehicle_id="denza_n7",
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "execution_failed")
|
||||
self.assertEqual(result["execution_report"]["spec"]["status"], "failed")
|
||||
self.assertEqual(
|
||||
result["actuator_state"]["passenger"]["position"]["longitudinal"][
|
||||
"position_pct"
|
||||
],
|
||||
63,
|
||||
)
|
||||
self.assertEqual(
|
||||
result["actuator_state"]["passenger"]["position"]["longitudinal"][
|
||||
"feedback_source"
|
||||
],
|
||||
"physical_can",
|
||||
)
|
||||
self.assertEqual(
|
||||
result["domain_state"]["roof"]["transmittance_pct"],
|
||||
initial_roof,
|
||||
)
|
||||
|
||||
def test_reference_mode_library_modes_execute_for_denza(self) -> None:
|
||||
model_output = {
|
||||
"detected_domains": ["seat"],
|
||||
|
||||
Reference in New Issue
Block a user