Files
StarPilot/openpilot/starpilot/galaxy/tests/test_lead_approach_settings.py
T
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

90 lines
4.1 KiB
Python

from unittest.mock import Mock
"""Galaxy uses the shared approaching-lead setting and its fresh authority."""
from pathlib import Path
from types import SimpleNamespace
import pytest
from opendbc.car.honda.interface import CarInterface
from opendbc.car.honda.values import CAR
from openpilot.common.params import Params
from openpilot.starpilot.galaxy.settings import AuthorityContext, SettingsChanged, SettingsGateway
@pytest.fixture
def setup(tmp_path):
params = Params(str(tmp_path))
cp = CarInterface.get_non_essential_params(CAR.HONDA_CIVIC)
assert cp.openpilotLongitudinalControl and cp.pcmCruise
current = SimpleNamespace(parked=True, cp=cp, raw=b"current-honda-cp")
context = SimpleNamespace(sample=lambda: AuthorityContext(current.parked, current.cp, current.raw))
return params, current, SettingsGateway(params, Mock(wraps=context), clock=lambda: 10.0)
def page_row(gateway):
page = gateway.page("profiles", "session", b"generation")
index = next(index for index, row in enumerate(page["rows"]) if row["label"] == "Approaching lead buffer")
return page, index, page["rows"][index]
def test_galaxy_get_select_apply_without_cp_or_profile_health(setup):
params, current, gateway = setup
current.cp = None
current.raw = None
Path(params.get_param_path("LongitudinalPersonalityProfiles")).write_bytes(b"{invalid")
Path(params.get_param_path("CustomPersonalities")).write_bytes(b"invalid")
page, index, row = page_row(gateway)
assert row["value"] == "Off" and row["available"] and row["choices"] == ["Off", "On"]
intent = gateway.preview(page["view"], index, 0, "session", b"generation", value="On")
assert intent["proposed"] == "On"
assert gateway.confirm(intent["intent"], "session", b"generation")
assert Path(params.get_param_path("LeadApproachBuffer")).read_bytes() == b"1"
page, index, row = page_row(gateway)
assert row["value"] == "On"
intent = gateway.preview(page["view"], index, 0, "session", b"generation", value="Off")
assert gateway.confirm(intent["intent"], "session", b"generation")
assert Path(params.get_param_path("LeadApproachBuffer")).read_bytes() == b"0"
@pytest.mark.parametrize("field,value", [("openpilotLongitudinalControl", False), ("passive", True),
("dashcamOnly", True), ("notCar", True), ("carFingerprint", "")])
def test_galaxy_saved_preference_remains_editable_with_unqualified_cp(setup, field, value):
params, current, gateway = setup
setattr(current.cp, field, value)
page, index, row = page_row(gateway)
assert row["available"]
intent = gateway.preview(page["view"], index, 0, "session", b"generation", value="On")
assert gateway.confirm(intent["intent"], "session", b"generation")
assert Path(params.get_param_path("LeadApproachBuffer")).read_bytes() == b"1"
def test_galaxy_intent_rechecks_context_session_and_exact_saved_source(setup):
params, current, gateway = setup
path = Path(params.get_param_path("LeadApproachBuffer"))
for revocation in ("context", "session", "source"):
page, index, _ = page_row(gateway)
intent = gateway.preview(page["view"], index, 0, "session", b"generation", value="On")
if revocation == "context":
current.raw = b"different-car-source"
with pytest.raises(SettingsChanged):
gateway.confirm(intent["intent"], "session", b"generation")
current.raw = b"current-honda-cp"
elif revocation == "session":
with pytest.raises(SettingsChanged):
gateway.confirm(intent["intent"], "session", b"generation", session_valid=lambda: False)
else:
path.write_bytes(b"0")
assert not gateway.confirm(intent["intent"], "session", b"generation")
path.unlink()
assert not path.exists()
def test_saved_lead_approach_preference_remains_editable_onroad(setup):
params, current, gateway = setup
page, index, _ = page_row(gateway)
intent = gateway.preview(page["view"], index, 0, "session", b"generation", value="On")
current.parked = False
assert gateway.confirm(intent["intent"], "session", b"generation")
assert Path(params.get_param_path("LeadApproachBuffer")).read_bytes() == b"1"