Make genome validity survive moves and freeze the v1 encoding
Two defects from review of 8584eb1.
Genome had implicit move operations, so moving one emptied the source's
capabilities while leaving its identity, origin and digest intact. The
result still reported its ID but no longer encoded to decodable bytes,
which contradicts the documented invariant that an invalid genome cannot
exist. Declaring the copy operations suppresses the implicit moves, so a
move decays to a copy and the invariant holds for every operation. The
record is at most seven capabilities and one parent, so the copy is cheap.
The move tests were confirmed to fail without the fix: Debug and ASan
exit 1 at runtime, and Release does not compile, because MSVC proves the
moved-from comparison always throws and rejects the unreachable code.
clang-tidy then flagged the deliberate decaying moves; those lines carry
a NOLINT explaining that the decay is the contract under test.
The encoding tests compared the current encoder against the current
decoder, so a coordinated change to layout or digest would have passed
while breaking existing v1 records. A frozen 83-byte fixture now holds
one schema 1 founder record, asserted in both directions: the encoder
must still produce those bytes and the decoder must still read them. Every
structural byte was verified by hand against schemas/genome-v1.md before
freezing. It is a golden, not a value to update when a test fails.
Native Release, clang-tidy analysis, ASan and format checks pass 17/17.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,13 @@ input; `Genome::create` either returns a validated record or an error, and
|
||||
`decode` applies the identical semantic checks to bytes. There is no way to hold
|
||||
an invalid `Genome`, so callers never revalidate.
|
||||
|
||||
That claim requires the type to be copy-only. An implicit move would empty the
|
||||
source's capabilities while leaving its identity, origin and digest intact, which
|
||||
is exactly the invalid record this type exists to make unrepresentable. Declaring
|
||||
the copy operations suppresses the implicit moves, so a move decays to a copy.
|
||||
The record is at most seven capabilities and one parent, so the copy is cheap and
|
||||
the invariant holds for every operation rather than all but two.
|
||||
|
||||
Genome v1 fixes seven capability kinds, matching the v0.1 list in GENOME_MODEL:
|
||||
energy conversion, membrane, movement, ingestion, reproduction, target size and
|
||||
thermal tolerance. These are capabilities, not genes, organs or species. A static
|
||||
@@ -104,6 +111,12 @@ or recombination, and no genome yet affects any simulation.
|
||||
|
||||
## Consequences
|
||||
|
||||
A frozen fixture holds the exact bytes of one schema 1 record, verified by hand
|
||||
against the documented layout. Round trips alone compare the current encoder with
|
||||
the current decoder, so a coordinated change to layout or digest would pass every
|
||||
such test while invalidating existing records. The fixture is a golden: changing
|
||||
it needs a schema version and a migration, not an edit.
|
||||
|
||||
Test canonical round trips, byte-exact encoding stability, strict ordering,
|
||||
truncation, trailing bytes, corrupted checksums, digest mismatch, unsupported and
|
||||
zero versions, unknown capability kinds and prerequisite bits, duplicates,
|
||||
|
||||
@@ -400,6 +400,31 @@ closure, which is tested. A later schema that mandates a capability without
|
||||
requiring it would exercise the remaining branch; this is recorded rather than
|
||||
covered by a test that could not fail.
|
||||
|
||||
Review of `8584eb1` found two defects (2026-09-22). First, `Genome` had implicit
|
||||
move operations, so moving one emptied the source's capabilities while leaving
|
||||
its identity, origin and digest intact: a record that still reported ID 7 but
|
||||
whose encoded bytes no longer decoded. That contradicted the documented invariant
|
||||
directly. The type is now copy-only, which suppresses the implicit moves so a
|
||||
move decays to a copy, and the invariant holds for every operation. The new move
|
||||
tests were confirmed to fail without the fix: the Debug and ASan builds exit 1 at
|
||||
runtime, and the Release build does not compile at all, because MSVC proves the
|
||||
moved-from comparison always throws and rejects the unreachable code under
|
||||
warnings-as-errors. clang-tidy then flagged the deliberate decaying moves in the
|
||||
tests as `performance-move-const-arg`; those two lines carry a NOLINT explaining
|
||||
that the decay is the contract under test.
|
||||
|
||||
Second, the encoding tests compared the current encoder against the current
|
||||
decoder, so a coordinated change to layout or digest would have passed while
|
||||
breaking existing v1 records. A frozen 83-byte fixture now holds one schema 1
|
||||
founder record. Every structural byte was verified by hand against
|
||||
schemas/genome-v1.md before being frozen: magic, both versions, ID 7, origin 1,
|
||||
zero parents, three records, kinds 0/1/5 with parameters 400/120/5000, and the
|
||||
`56 + 9N` length. The digest `9b2cdedef16ac87f` and the trailing checksum are
|
||||
computed values frozen alongside them. The fixture is asserted in both
|
||||
directions: the encoder must still produce those bytes, and the decoder must
|
||||
still read them into the expected record. It is a golden and must not be edited
|
||||
to make a test pass.
|
||||
|
||||
No genome affects any simulation, and nothing links the new library except its
|
||||
own tests. The M2 process fixtures still duplicate founder strategies and do not
|
||||
read the record. Development, phenotype derivation, mutation, recombination,
|
||||
|
||||
Reference in New Issue
Block a user