diff --git a/openpilot/starpilot/state_migration.py b/openpilot/starpilot/state_migration.py index 55c61c04ae..8b3616b6ff 100644 --- a/openpilot/starpilot/state_migration.py +++ b/openpilot/starpilot/state_migration.py @@ -23,12 +23,23 @@ RENAMED_BOOL_KEYS = {'AndroidAutoEnabled': 'StarPortEnabled'} MAX_VALUE_BYTES = 32 * 1024 * 1024 MAX_SNAPSHOT_BYTES = 256 * 1024 * 1024 MAX_KEYS = 4096 +VEHICLE_PREFERENCE_KEYS = frozenset({ + 'RemoteStartBootsComma', 'HKGRemoteStartBootsComma', 'IgnoreIgnitionLine', + 'TeslaWakeOnCAN', 'DisableOpenpilotLongitudinal', 'LongPitch', + 'VoltSNG', 'SNGHack', 'GMAutoHold', + 'VoltOnePedalMode', 'TeslaCoopSteering', 'TeslaAOLScreenTap', + 'TeslaAOLDisengageOnBrake', 'SubaruAvhStartup', 'SubaruStopStartOff', + 'SubaruSNG', 'SubaruRedneckCruise', 'ToyotaAutoHold', + 'JeepBrakeHold', 'DriveModeProfiles', 'DriveModeAcceleration', + 'DriveModeDeceleration', 'NostalgiaMode', 'RemapCancelToDistance', + 'FordHandsFreeCluster', +}) OPERATIONAL_KEYS = frozenset({ 'DongleId', 'HardwareSerial', 'GithubSshKeys', 'GithubUsername', 'SshEnabled', 'AlphaLongitudinalEnabled', 'HasAcceptedTerms', 'CompletedTrainingVersion', 'CellularDisabled', 'GsmApn', 'GsmMetered', 'GsmRoaming', 'NetworkMetered', 'BluetoothEnabled', 'ConnectProvider', 'PairingProvider', 'PairingEmail', 'PrimeType', 'AssistNowToken', 'SecOCKey', 'SecOCKeys', -}) +}) | VEHICLE_PREFERENCE_KEYS class MigrationRequired(RuntimeError): diff --git a/openpilot/starpilot/tests/test_first_start_migration.py b/openpilot/starpilot/tests/test_first_start_migration.py index 04258c9465..91b905ada8 100644 --- a/openpilot/starpilot/tests/test_first_start_migration.py +++ b/openpilot/starpilot/tests/test_first_start_migration.py @@ -64,6 +64,36 @@ class TestFirstStartMigration(unittest.TestCase): self.start() self.assertEqual({str(path): path.read_bytes() for path in self.storage.rglob('*') if path.is_file()}, before) + def test_vehicle_preferences_keep_canonical_choices_and_new_settings_survive_restart(self): + self.types.update(dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, 'BOOL')) + original = {key: b'1' if index % 2 else b'0' for index, key in enumerate(sorted(migration.VEHICLE_PREFERENCE_KEYS))} + original.update({'AlphaLongitudinalEnabled': b'1', 'CarParamsCache': b'old fingerprint', + 'CarParamsPersistent': b'old safety configuration', 'CarParamsPrevRoute': b'old route', 'SteerFriction': b'0.337'}) + self.write(original) + self.start() + expected = {key: raw for key, raw in original.items() if key in migration.OPERATIONAL_KEYS} + self.assertEqual(self.values(), expected) + self.assertEqual(migration.load_snapshot(next((self.storage / 'snapshots').iterdir())), original) + for key in migration.VEHICLE_PREFERENCE_KEYS: + (self.namespace / key).write_bytes(b'0' if expected[key] == b'1' else b'1') + changed = self.values() + self.start() + self.assertEqual(self.values(), changed) + + def test_invalid_vehicle_preferences_are_archived_without_enabling_them(self): + self.types.update(dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, 'BOOL')) + original = dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, b'true') + self.write(original) + self.start() + self.assertEqual(self.values(), {}) + self.assertEqual(migration.load_snapshot(next((self.storage / 'snapshots').iterdir())), original) + + def test_vehicle_preference_keys_are_registered_booleans(self): + from openpilot.common.params import Params + params = Params(str(self.root / 'native-params')) + for key in migration.VEHICLE_PREFERENCE_KEYS: + self.assertEqual(params.get_type(key).name, 'BOOL', key) + def test_onboarding_keeps_only_previously_saved_acceptance(self): self.write({'HasAcceptedTerms': b'2', 'CompletedTrainingVersion': b'0.2.0', 'ForceStops': b'1'}) self.start() diff --git a/prebuilt.json b/prebuilt.json index 13e726568a..fa950c290f 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "2757d3911f64e0e886f766807ed90f2b0af3149497d12b346dad955efcc698fc", "schema_version": 1} +{"protected_inventory_sha256": "aa8ef45fd68935ebf9b0f9885dcc6862763a00b0f3fa35f7f69ccfc6e515ce6a", "schema_version": 1}