acdream/tests/AcDream.Content.Tests
Erik 84d1956d84 fix(pipeline): MP1b review - pak format/reader hardening
Adversarially-verified review findings 2,3,4,5,6,9:

(2) PakFormat.CurrentFormatVersion=1 constant; PakWriter stamps it
unconditionally (caller header templates can no longer produce a
version-0 pak — the default-0 footgun); PakReader refuses any other
version with a message naming found/expected. Tests: versions 0 and 2
both rejected; writer stamps even when the template omits the field.

(3) Reader robustness, all under the documented corrupt-=-missing
CONTRACT (external-file input — surface loudly once, then behave as
absent; never garbage, never throw from a lookup): (a) per-TOC-entry
bounds validation at open (offset/length outside [header, toc) or
past EOF -> logged once, entry missing, siblings unaffected); (b)
TryReadObjectMeshData catches deserialization failures (malformed
structure behind a matching CRC) -> logged once per entry, false; (c)
structurally unopenable files throw at OPEN with a clear message:
unfinalized header (tocOffset < header size — the placeholder-header
crash signature) and TOC-past-EOF truncation. Tests: corrupt TOC
entry, truncated pak, half-written pak, malformed-blob-behind-valid-
CRC (tamper + CRC recompute) — each verifying sibling blobs still read.

(4) Single-pass read: TryReadObjectMeshData now does ONE ReadArray out
of the map; CRC and deserialization run over the same buffer (was: a
separate VerifyCrc traversal + a second ReadArray + a ToArray copy
inside Serializer.Read). New Serializer.Read(byte[]) overload avoids
the defensive copy. Verdict set stays a ConcurrentDictionary (MP1c
calls this from 4 decode workers). True span-over-mmap zero-copy is
deferred to MP1c profiling per the class doc comment.

(5) PakWriter.Dispose restored to try/finally: Finish() does real I/O
and can throw (disk full) — the stream must ALWAYS close so no file
handle leaks mid-unwind. (Reverts the a5926ebc simplification, which
was wrong about this.) Test: dispose after an AddBlob exception leaves
the file deletable.

(6) CRC-32 known-answer vectors: "123456789" -> 0xCBF43926, empty ->
0x00000000, single zero byte -> 0xD202EF8D. The suite was previously
blind to a self-consistent-but-wrong CRC.

(9) Equality comparator floats switched to bit-equality
(SingleToInt32Bits/DoubleToInt64Bits, incl. Vector2/3 + Matrix4x4
components): for byte-identity round-trip purposes `==` was both too
strict (NaN==NaN false — a surviving NaN payload would wrongly FAIL)
and too lax (-0.0==+0.0 true — a sign-bit flip would wrongly PASS).

Content.Tests: 54/54 green (was 43).
2026-07-05 22:08:59 +02:00
..
AcDream.Content.Tests.csproj test(pipeline): MP1b - live-vs-pak equivalence suite (dat-gated) 2026-07-05 21:33:32 +02:00
ContentConformanceDats.cs test(pipeline): MP1b - live-vs-pak equivalence suite (dat-gated) 2026-07-05 21:33:32 +02:00
ContentTestDatCollectionAdapter.cs test(pipeline): MP1b - live-vs-pak equivalence suite (dat-gated) 2026-07-05 21:33:32 +02:00
Crc32Tests.cs fix(pipeline): MP1b review - pak format/reader hardening 2026-07-05 22:08:59 +02:00
ObjectMeshDataEquality.cs fix(pipeline): MP1b review - pak format/reader hardening 2026-07-05 22:08:59 +02:00
ObjectMeshDataSerializerTests.cs feat(pipeline): MP1b - ObjectMeshData binary serializer (deterministic round-trip) 2026-07-05 21:19:02 +02:00
PakEquivalenceTests.cs test(pipeline): MP1b - live-vs-pak equivalence suite (dat-gated) 2026-07-05 21:33:32 +02:00
PakFormatTests.cs feat(pipeline): MP1b - pak key + header/TOC primitives 2026-07-05 21:14:10 +02:00
PakKeyTests.cs feat(pipeline): MP1b - pak key + header/TOC primitives 2026-07-05 21:14:10 +02:00
PakRoundTripTests.cs fix(pipeline): MP1b review - pak format/reader hardening 2026-07-05 22:08:59 +02:00