#!/usr/bin/env python3 import re import sys from pathlib import Path GENERATED = Path("backend/internal/controlplane/packs/platform_config_autonumber_formats.go") ROW_RE = re.compile( r'\{ObjectName: "([^"]+)", FieldApiName: "([^"]+)", Format: "([^"]*)", ' r'Scope: "([^"]+)", Start: ([0-9]+), LegacySource: "([^"]+)", ' r'TokenRefsJSON: "([^"]*)"\}' ) RT_RE = re.compile(r"\{Name: \"([^\"]+)\", Code: \"([^\"]+)\"\}") def main() -> int: text = GENERATED.read_text() failures = [] rows = list(ROW_RE.finditer(text)) if not rows: failures.append("no AutoNumberFormatSeeds rows parsed from generated file") for match in rows: object_name, field_api_name, _, scope, _, _, token_refs = match.groups() key = f"{object_name}.{field_api_name}" if object_name.endswith("__c") or "__" in object_name: failures.append(f"{key}: object name is tenant/private or namespaced") if field_api_name.endswith("__c") or "__" in field_api_name: failures.append(f"{key}: field api name is tenant/private or namespaced") if scope != "global": failures.append(f"{key}: scope={scope!r} must not ship in public generated output") if token_refs: failures.append(f"{key}: TokenRefsJSON must stay empty in public generated output") rt_rows = list(RT_RE.finditer(text)) if rt_rows: failures.append("public generated output must not ship RecordTypeCodeSeeds") if failures: print("FAIL: public autonumber generated output contains private/tenant seeds", file=sys.stderr) for failure in failures: print(f" - {failure}", file=sys.stderr) return 1 print(f"OK: {GENERATED} contains only public autonumber seeds") return 0 if __name__ == "__main__": raise SystemExit(main())