"""Generates the golden-file chunk fixtures in this directory. These pin the world.md §3.6 binary format so the Python codec (app/services/chunk_codec.py) and any future Godot-side test fixture can be checked for drift (world_persistence_impl.md §5.5's "drift control" requirement). No Godot-side golden fixture existed at the time this was written (searched scripts/ and tests/ for AGPC / binary-format test vectors -- none found), so these are authored here, from this implementation, as the first golden files for the format. The client/editor follow-on task should decode these same files with `ChunkDataDecoder.decode_binary()` and assert the same logical values (see the note in chunk_codec.py about a confirmed float32 handling bug in that decoder that will need fixing for full byte parity on non-integer transforms). Run with: `python tests/fixtures/chunks/generate_fixtures.py` from `backend/`. Fixtures are checked in; this script is for regenerating them if the format or these examples change, not run as part of the test suite. """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[3])) # backend/ from app.services import chunk_codec as cc FIXTURES_DIR = Path(__file__).resolve().parent def _empty_chunk() -> cc.ChunkPayload: return cc.ChunkPayload( world_id="7", room_id="main", coord=(0, 0, 0), bounds=cc.ChunkBounds(min=(0.0, 0.0, 0.0), size=(32.0, 32.0, 1.0)), tile_layers=[], objects=[], flags=cc.ContentFlags(), created_at=1_700_000_000, updated_at=1_700_000_000, revision=1, author="fixture-gen", ) def _simple_tile_chunk() -> cc.ChunkPayload: layer = cc.TileLayer( name="ground", layer_id=0, width=4, height=4, depth=1, palette=[ cc.TileDef(id=0, asset_id="", solid=False, flags=0, variants=1), cc.TileDef(id=1, asset_id="tiles/grass", solid=False, flags=1, variants=4), cc.TileDef(id=2, asset_id="tiles/stone", solid=True, flags=2, variants=2), ], tiles=[0, 1, 1, 0, 1, 2, 2, 1, 1, 2, 2, 1, 0, 1, 1, 0], ) return cc.ChunkPayload( world_id="12", room_id="main", coord=(3, -1, 0), bounds=cc.ChunkBounds(min=(96.0, -32.0, 0.0), size=(32.0, 32.0, 1.0)), tile_layers=[layer], objects=[], flags=cc.ContentFlags(violence=0, mature=False, sources=[]), created_at=1_700_000_000, updated_at=1_700_000_500, revision=2, author="fixture-gen", ) def _chunk_with_objects() -> cc.ChunkPayload: layer = cc.TileLayer( name="ground", layer_id=0, width=2, height=2, depth=1, palette=[cc.TileDef(id=0, asset_id="", solid=False, flags=0, variants=1)], tiles=[0, 0, 0, 0], ) obj1 = cc.WorldObject( id="obj_0001", type="interactable", asset_id="props/chest", pos=(101.5, -110.25, 0.5), rot=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), dynamic=False, properties={"locked": False, "loot_table": "chest_basic"}, flags=cc.ContentFlags(violence=0, mature=False, sources=[]), ) obj2 = cc.WorldObject( id="obj_0002", type="spawn_point", asset_id="", pos=(96.0, -128.0, 1.0), rot=(0.0, 0.7071, 0.0, 0.7071), scale=(1.0, 1.0, 1.0), dynamic=True, properties={}, flags=cc.ContentFlags(violence=1, mature=False, sources=["asset:props/chest"]), ) return cc.ChunkPayload( world_id="12", room_id="main", coord=(3, -4, 0), bounds=cc.ChunkBounds(min=(96.0, -128.0, 0.0), size=(32.0, 32.0, 1.0)), tile_layers=[layer], objects=[obj1, obj2], flags=cc.ContentFlags(violence=1, mature=False, sources=["asset:props/chest"]), created_at=1_700_000_000, updated_at=1_700_001_000, revision=5, author="agent-bot", ) FIXTURES = { "empty_chunk.bin": _empty_chunk, "simple_tile_chunk.bin": _simple_tile_chunk, "chunk_with_objects.bin": _chunk_with_objects, } def main() -> None: for filename, builder in FIXTURES.items(): payload = builder() data = cc.encode_binary(payload) (FIXTURES_DIR / filename).write_bytes(data) print(f"wrote {filename} ({len(data)} bytes)") if __name__ == "__main__": main()