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:
dingo
2026-09-22 21:23:33 -04:00
co-authored by Claude Opus 5
parent 8584eb1f6f
commit 64a12c4dfc
4 changed files with 117 additions and 0 deletions
+7
View File
@@ -93,6 +93,13 @@ class Genome {
[[nodiscard]] static std::expected<Genome, GenomeError> create(const GenomeDraft& draft);
[[nodiscard]] static std::expected<Genome, GenomeError>
decode(std::span<const std::uint8_t> bytes);
// Copy-only on purpose. A moved-from record would keep its identity, origin
// and digest while losing its capabilities, which is precisely the invalid
// genome 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 that is cheap.
Genome(const Genome&) = default;
Genome& operator=(const Genome&) = default;
[[nodiscard]] std::vector<std::uint8_t> encode() const;
[[nodiscard]] std::uint64_t id() const noexcept {
return id_;