"""Validate Excel↔JSON byte-equal sync (V2-M1D). Thin wrapper over build_config_from_excel: regenerate JSON from Excel and assert byte-equal with the committed runtime JSON. Equivalent to `build_config_from_excel.py --check`, exposed as a uniform validator for the config gate. """ from __future__ import annotations import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from scripts.build_config_from_excel import build from scripts.check_config_json_canonical import canonical_dumps def main() -> int: findings = [] for path_str, obj in build().items(): path = Path(path_str) ok = canonical_dumps(obj) == path.read_text(encoding="utf-8") finding = {"level": "fail" if not ok else "info", "check_id": "excel_json_sync", "config_path": str(path.relative_to(ROOT)), "byte_equal": ok} if not ok: finding["message"] = "Excel diverges from JSON; run build_config_from_excel.py --sync-excel (JSON wins) or --write (Excel wins)" findings.append(finding) status = "fail" if any(f["level"] == "fail" for f in findings) else "pass" print(json.dumps({"status": status, "findings": findings}, ensure_ascii=False, indent=2)) return 1 if status == "fail" else 0 if __name__ == "__main__": sys.exit(main())