#!/usr/bin/env python3 """Runtime data bundle gate. The Godot sample loads content/rules/text from res://data/ (bundled inside the project) so it works in an exported build where res:// is packed and has no parent. The authoritative copies live in the repository's top-level data/ and are used by the Python validators. This gate proves the bundled copies are byte-identical to the authoritative ones, so the runtime can never silently drift from validated data. """ import hashlib import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SOURCE = ROOT / "data" BUNDLE = ROOT / "p2_godot_sample" / "data" FILES = [ "mvp_launch_content.json", "mvp_battle_rules.json", "mvp_validation_seed_pack.json", "mvp_content_fixture.json", "ui_text.zh_CN.json", "ui_text.en_US.json", ] def sha256(path: Path) -> str: return hashlib.sha256(path.read_bytes()).hexdigest() def main() -> int: problems = [] for name in FILES: src, dst = SOURCE / name, BUNDLE / name if not src.is_file(): problems.append(f"missing authoritative source data/{name}") continue if not dst.is_file(): problems.append(f"missing bundled copy p2_godot_sample/data/{name}") continue if sha256(src) != sha256(dst): problems.append(f"bundle drift for {name}: p2_godot_sample/data differs from data/") if problems: print("RUNTIME_DATA_BUNDLE_FAIL") for p in problems: print(" " + p) return 1 print(f"RUNTIME_DATA_BUNDLE_PASS {len(FILES)} files byte-identical") return 0 if __name__ == "__main__": sys.exit(main())