优化前端,优化前端指令,优化自定义控制
This commit is contained in:
@@ -128,18 +128,18 @@ class FrontendVehicleStateSyncContractTests(unittest.TestCase):
|
||||
):
|
||||
self.assertIn(f'{state_path} === "physical_can_ch1"', summary_source)
|
||||
|
||||
def test_orchestration_renders_only_the_physical_ch1_patch(self) -> None:
|
||||
def test_orchestration_renders_only_the_authoritative_ch1_patch(self) -> None:
|
||||
apply_source = function_source(
|
||||
self.app_source,
|
||||
"function applyAuthoritativeVehicleState(payload) {",
|
||||
'\nwindow.addEventListener("cognitive-agent:extension-vehicle-result"',
|
||||
)
|
||||
self.assertIn(
|
||||
"const actuatorPatch = physicalCh1StatePatch(payload.actuator_state)",
|
||||
"const actuatorPatch = authoritativeCh1StatePatch(payload.actuator_state)",
|
||||
apply_source,
|
||||
)
|
||||
self.assertIn(
|
||||
"const domainPatch = physicalCh1StatePatch(payload.domain_state)",
|
||||
"const domainPatch = authoritativeCh1StatePatch(payload.domain_state)",
|
||||
apply_source,
|
||||
)
|
||||
self.assertIn("renderSeatState(actuatorPatch)", apply_source)
|
||||
@@ -163,13 +163,18 @@ class FrontendVehicleStateSyncContractTests(unittest.TestCase):
|
||||
self.assertIn("renderSeatState(result.actuator_state)", ch1_branch)
|
||||
self.assertIn("renderDomainState(result.domain_state)", ch1_branch)
|
||||
|
||||
def test_physical_patch_does_not_promote_unmarked_sibling_domains(self) -> None:
|
||||
def test_authoritative_patch_accepts_wired_and_wireless_without_promoting_siblings(self) -> None:
|
||||
node = shutil.which("node")
|
||||
if node is None:
|
||||
self.skipTest("Node.js is required to execute the frontend patch helper")
|
||||
source_helper = function_source(
|
||||
self.app_source,
|
||||
"function isAuthoritativeCh1Source(value) {",
|
||||
"\nfunction renderCabinLiveStatus",
|
||||
)
|
||||
patch_source = function_source(
|
||||
self.app_source,
|
||||
"function physicalCh1StatePatch(value) {",
|
||||
"function authoritativeCh1StatePatch(value) {",
|
||||
"\nfunction isAuthoritativeVehicleStatePayload",
|
||||
)
|
||||
state = {
|
||||
@@ -178,14 +183,20 @@ class FrontendVehicleStateSyncContractTests(unittest.TestCase):
|
||||
"power": "on",
|
||||
},
|
||||
"roof": {"shade_position_pct": 100},
|
||||
"ambient_light": {
|
||||
"feedback_source": "wireless_mqtt_ch1",
|
||||
"power": "on",
|
||||
},
|
||||
"window": {
|
||||
"positions": {"front_left": {"position_pct": 50}}
|
||||
},
|
||||
}
|
||||
script = (
|
||||
'const AUTHORITATIVE_CH1_SOURCES = new Set(["physical_can_ch1", "wireless_mqtt_ch1"]);\n'
|
||||
f"{source_helper}\n"
|
||||
f"{patch_source}\n"
|
||||
f"const input = {json.dumps(state)};\n"
|
||||
"process.stdout.write(JSON.stringify(physicalCh1StatePatch(input)));"
|
||||
"process.stdout.write(JSON.stringify(authoritativeCh1StatePatch(input)));"
|
||||
)
|
||||
completed = subprocess.run(
|
||||
[node, "-e", script],
|
||||
@@ -195,7 +206,10 @@ class FrontendVehicleStateSyncContractTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(completed.stdout),
|
||||
{"climate": state["climate"]},
|
||||
{
|
||||
"climate": state["climate"],
|
||||
"ambient_light": state["ambient_light"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_dual_channel_runtime_polls_each_seat_without_aliasing(self) -> None:
|
||||
@@ -249,6 +263,24 @@ class FrontendVehicleStateSyncContractTests(unittest.TestCase):
|
||||
self.assertIn("}, physicalStatePollIntervalMs());", self.app_source)
|
||||
self.assertIn("restartPhysicalStatePolling();", self.app_source)
|
||||
|
||||
def test_transport_switch_clears_stale_vehicle_values_before_new_feedback(self) -> None:
|
||||
select_source = function_source(
|
||||
self.app_source,
|
||||
"function selectControlTransport(transport) {",
|
||||
"\nfunction renderHardwareAccess",
|
||||
)
|
||||
reset_source = function_source(
|
||||
self.app_source,
|
||||
"function resetVehicleStatusDisplay() {",
|
||||
"\nfunction mergeSeatActuatorState",
|
||||
)
|
||||
|
||||
self.assertIn("resetVehicleStatusDisplay();", select_source)
|
||||
self.assertIn('setText("#windowState", "UNKNOWN")', reset_source)
|
||||
self.assertIn('setText("#frontLightState", "UNKNOWN")', reset_source)
|
||||
self.assertIn('setText("#cabinSummaryDoors", "状态未知")', reset_source)
|
||||
self.assertIn('meter.dataset.state = "unknown"', reset_source)
|
||||
|
||||
def test_vehicle_selection_cannot_replay_unfiltered_state_in_ch1_mode(self) -> None:
|
||||
select_source = function_source(
|
||||
self.app_source,
|
||||
|
||||
Reference in New Issue
Block a user