Files
windroost/tools/check_runtime_data_bundle.py
T
wushenghua 06aa9754ae fix: bundle runtime data inside project so exported builds can load content
Phase C1 of the release-readiness roadmap. Found and fixed a genuine release
blocker: Godot runtime scripts loaded content/rules/text from res://../data/,
which resolves in the editor but NOT in an export (packed res:// has no parent),
so a shipped game would fail on first load.

- Copied the 6 runtime JSON files into p2_godot_sample/data/ and redirected
  launch_content.gd, ui_text.gd, profile_store.gd, battle_sim.gd and
  battle_scene.gd to res://data/... . The repository root data/ stays the
  authoritative source for the Python validators; frozen_fixture.gd (test-only
  source-provenance checks) keeps its res://../ paths.
- Added tools/check_runtime_data_bundle.py: SHA-256 proves each bundled copy is
  byte-identical to the authoritative one, so runtime data cannot drift from
  validated data. Registered as a gate in run_p2_checks.sh.
- End-to-end proof: exported a Linux/X11 PCK with an include_filter for
  data/*.json, mounted it with --main-pack, and asserted all 6 data files plus
  the main scene exist under res:// (PCK_RESULT PASS). This verifies the fix in
  a real packed artifact, not just source.
- Added a minimal Linux/X11 export_presets.cfg for local smoke exports. It is
  NOT a signed/release artifact; build/ is gitignored so no binary is committed.

Full gate P2_CHECKS_PASS with the new gate. Roadmap 47 records the remaining
publisher-owned steps (owner-chosen Bundle ID / team / signing, archive, upload,
store review) and the pre-release cleanup item (exclude *_test.gd from exports).
Bundle ID, product name and business model are owner decisions (NAMING.md is
undecided) and were not invented here. prototype/ stays untracked and untouched.
2026-11-18 00:40:56 +08:00

55 lines
1.6 KiB
Python
Executable File

#!/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())