diff --git a/tools/ci/schema-policy.json b/tools/ci/schema-policy.json index 668dc9cadd..ef45d6d697 100644 --- a/tools/ci/schema-policy.json +++ b/tools/ci/schema-policy.json @@ -197,7 +197,7 @@ "reviewed_enum_additions": { "opendbc_repo/opendbc/car/car.capnp": { "enum": "SafetyModel", - "field": "teslaPreap @39;" + "fields": ["teslaPreap @39;", "leapmotor @40;"] } }, "reviewed_payload_children": { diff --git a/tools/ci/schema_policy.py b/tools/ci/schema_policy.py index 013be9c4a6..5c7332219c 100644 --- a/tools/ci/schema_policy.py +++ b/tools/ci/schema_policy.py @@ -256,11 +256,13 @@ def validate(schemas, policy, sync): source = candidate.decode() pattern = rf'(enum {re.escape(reviewed["enum"])}\s*\{{)([^}}]*)(\}})' match = re.search(pattern, source) - field = reviewed['field'] - if match is None or len(re.findall(rf'(?m)^\s*{re.escape(field)}\s*$', match[2])) != 1: + fields = reviewed.get('fields', [reviewed.get('field')]) + if match is None or any(len(re.findall(rf'(?m)^\s*{re.escape(field)}\s*$', match[2])) != 1 for field in fields): errors.append(f'{path}: reviewed enum addition is missing or changed') else: - body = re.sub(rf'(?m)^[ \t]*{re.escape(field)}[ \t]*\n', '', match[2]) + body = match[2] + for field in fields: + body = re.sub(rf'(?m)^[ \t]*{re.escape(field)}[ \t]*\n', '', body) source = source[:match.start(2)] + body + source[match.end(2):] candidate = source.encode() if sha256(candidate) != expected: diff --git a/tools/ci/tests/test_schema_policy.py b/tools/ci/tests/test_schema_policy.py index 06aaf407fa..df28dbfd42 100644 --- a/tools/ci/tests/test_schema_policy.py +++ b/tools/ci/tests/test_schema_policy.py @@ -246,8 +246,11 @@ class SchemaPolicyTest(unittest.TestCase): def test_reviewed_native_enum_is_only_permitted_core_extension(self): path = 'opendbc_repo/opendbc/car/car.capnp' - self.assertEqual(self.policy['reviewed_enum_additions'], {path: {'enum': 'SafetyModel', 'field': 'teslaPreap @39;'}}) + self.assertEqual(self.policy['reviewed_enum_additions'], + {path: {'enum': 'SafetyModel', 'fields': ['teslaPreap @39;', 'leapmotor @40;']}}) for before, after in ((b'teslaPreap @39;', b'teslaPreap @40;'), + (b'leapmotor @40;', b'leapmotor @41;'), + (b'leapmotor @40;', b'leapmotor @40;\n extraFork @41;'), (b'teslaPreap @39;', b'teslaPreap @39;\n extraFork @40;'), (b'teslaPreap @39;', b'teslaPreap @39;\n extraBool @62 :Bool;')): changed = copy.copy(self.schemas)