Fix 3 real client/server chunk-codec interop bugs, caught by a new golden-fixture test
checkpoint / checkpoint (push) Successful in 2m13s
checkpoint / checkpoint (push) Successful in 2m13s
No test ever exercised the client ChunkDataDecoder against real byte data
before this (M2 chunk streaming was never fed real content on PC2/PC3).
Added scripts/smoke_test_chunk_codec_interop.gd, decoding the backend's
exact golden fixtures (backend/tests/fixtures/chunks/*.bin) and asserting
byte-identical logical values -- the real cross-language contract this
whole persistence system depends on. It found three bugs on first run:
1. chunk_data_decoder.gd's _read_float32/_write_float32 used `bits as
float`/`val as int`, a numeric cast in GDScript, not an IEEE-754
bitcast -- silently corrupted every non-integer position/rotation/
scale/bounds value (1.5 decoded as 1069547520.0, verified). Fixed with
PackedByteArray.decode_float/encode_float (real bitcast, same
little-endian order as the rest of this format).
2. backend/app/services/chunk_codec.py's binary codec wrote bounds as
min+size, disagreeing with world.md §3's documented min+max wire
format and with the client's actual (correct) decoder -- corrupted
every chunk's bounds on the wire despite the backend's own JSON path
using min+max correctly. Fixed the binary encode/decode to match the
spec; regenerated the golden fixtures.
3. chunk_data_decoder.gd's object-properties parsing used
`JSON.parse_string(props_str) or {}` -- GDScript's `or` is a boolean
operator, not Python/JS-style short-circuit-return, so this silently
evaluated to a bool for any object with real property data, crashing
on assignment to the typed `properties: Dictionary` field. Fixed with
an explicit type check.
Full backend suite (132/132) and 4 sibling client smoke tests re-verified
clean after all three fixes; no other `or {}`/`or []` instances of bug 3's
pattern found elsewhere in the codebase.
This commit is contained in:
@@ -127,10 +127,15 @@ class WorldObject:
|
||||
|
||||
@dataclass
|
||||
class ChunkBounds:
|
||||
"""Wire representation is min-corner + size (matching the Godot AABB
|
||||
the reference encoder builds from), not min/max as world.md §3.1's
|
||||
logical-model prose describes -- both are fully recoverable from each
|
||||
other; this is just the on-the-wire convention."""
|
||||
"""Stored here as min-corner + size (matching the Godot client's AABB
|
||||
type) for convenience, but the §3.6 BINARY wire format is min + max
|
||||
(world.md §3.1, and the client's actual ChunkDataDecoder) -- fixed
|
||||
2026-09-14 after a real client/server interop test caught this class's
|
||||
original binary codec writing min+size on the wire, which the client
|
||||
decoder (unaware of the "size" convention) read as a second min/max
|
||||
pair, corrupting every chunk's bounds. The two representations are
|
||||
fully recoverable from each other; `max` below is computed for exactly
|
||||
this reason."""
|
||||
|
||||
min: tuple[float, float, float] = (0.0, 0.0, 0.0)
|
||||
size: tuple[float, float, float] = (0.0, 0.0, 0.0)
|
||||
@@ -237,9 +242,9 @@ def _encode_metadata(payload: ChunkPayload) -> bytes:
|
||||
out += _w_f32(payload.bounds.min[0])
|
||||
out += _w_f32(payload.bounds.min[1])
|
||||
out += _w_f32(payload.bounds.min[2])
|
||||
out += _w_f32(payload.bounds.size[0])
|
||||
out += _w_f32(payload.bounds.size[1])
|
||||
out += _w_f32(payload.bounds.size[2])
|
||||
out += _w_f32(payload.bounds.max[0])
|
||||
out += _w_f32(payload.bounds.max[1])
|
||||
out += _w_f32(payload.bounds.max[2])
|
||||
return bytes(out)
|
||||
|
||||
|
||||
@@ -250,7 +255,8 @@ def _decode_metadata(data: bytes, result: ChunkPayload) -> None:
|
||||
coord = (_read_i32(data, off), _read_i32(data, off + 4), _read_i32(data, off + 8))
|
||||
off += 12
|
||||
min_pos = (_read_f32(data, off), _read_f32(data, off + 4), _read_f32(data, off + 8))
|
||||
size = (_read_f32(data, off + 12), _read_f32(data, off + 16), _read_f32(data, off + 20))
|
||||
max_pos = (_read_f32(data, off + 12), _read_f32(data, off + 16), _read_f32(data, off + 20))
|
||||
size = tuple(a - b for a, b in zip(max_pos, min_pos))
|
||||
result.coord = coord
|
||||
result.bounds = ChunkBounds(min=min_pos, size=size)
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user