#!/usr/bin/env python3 """Build the isolated L54 native-caves fixture from the canonical owner input.""" from __future__ import annotations import argparse import hashlib import json from pathlib import Path def sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as stream: for block in iter(lambda: stream.read(1024 * 1024), b""): digest.update(block) return digest.hexdigest() def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--owner", type=Path, required=True) parser.add_argument("--out", type=Path, required=True) args = parser.parse_args() root = json.loads(args.owner.read_text(encoding="utf-8")) strates = root.get("strates") if not isinstance(strates, list): raise ValueError("owner input has no strates array") cave_candidates = [item for item in strates if isinstance(item, dict) and int(item.get("index", -1)) == 1 and int(item.get("asset", {}).get("GeneratorType", -1)) == 4] if len(cave_candidates) != 1: raise ValueError("fixture requires exactly one SurfaceWorld cave strate at index 1") upper_candidates = [item for item in strates if isinstance(item, dict) and int(item.get("index", -1)) == 0] if len(upper_candidates) != 1: raise ValueError("fixture requires one adjacent upper strate at index 0") passage = upper_candidates[0].get("passage_config") asset_passage = upper_candidates[0].get("asset", {}).get("PassageConfig") if (not isinstance(passage, dict) or not isinstance(asset_passage, dict) or int(passage.get("Connections", -1)) != 1 or int(asset_passage.get("Connections", -1)) != 1): raise ValueError("upper-strate passage config differs from the reviewed owner fixture") passage["Connections"] = 2 asset_passage["Connections"] = 2 args.out.parent.mkdir(parents=True, exist_ok=True) args.out.write_text(json.dumps(root, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"[CavesFixtureBuild] source={args.owner} source_sha256={sha256(args.owner)} " f"fixture={args.out} fixture_sha256={sha256(args.out)} changed=upper-strate-0-connections:1->2 " "owner_input_untouched=true status=PASS") return 0 if __name__ == "__main__": raise SystemExit(main())