M12.4: preserve exact biology across ownership candidates
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m18s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 5m33s
Foundation / checks (postgres) (push) Canceled after 5m29s
Foundation / checks (tsan) (push) Canceled after 5m28s
Foundation / checks (client) (push) Canceled after 5m37s
Foundation / checks (network) (push) Canceled after 5m39s

This commit is contained in:
dingo
2026-10-17 18:17:59 -04:00
parent 0a8962b57e
commit decd4f8043
27 changed files with 1408 additions and 61 deletions
+79 -1
View File
@@ -1,6 +1,7 @@
#include "evo/biology/lineage.hpp"
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <source_location>
@@ -478,9 +479,84 @@ void a_full_archive_round_trips() {
CHECK(bytes.size() <= max_archive_legacy_bytes);
const auto decoded = LineageArchive::decode(bytes);
CHECK(decoded && decoded->encode() == bytes && decoded->recorded() == max_archived_organisms);
LineageArchive destination;
const std::array<std::uint64_t, 1> selected{8191}; // Alive; carries the deepest genome.
const auto imported = destination.merge_living_from(archive, selected);
CHECK(imported && imported->recorded() == 1 && imported->archived() == max_archived_genomes);
const auto imported_ancestry = imported->ancestry(max_archived_genomes);
CHECK(imported_ancestry && imported_ancestry->size() == max_archived_genomes);
CHECK(archive.encode() == bytes && destination.recorded() == 0);
LineageArchive unrelated;
CHECK(unrelated.admit(descend(5'000'000, 0)));
CHECK(unrelated.record_birth(5'000'001, 5'000'000, evo::Tick{1}));
const auto full_before = imported->encode();
const auto overflow =
imported->merge_living_from(unrelated, std::array<std::uint64_t, 1>{5'000'001});
CHECK(!overflow && overflow.error() == HistoryError::archive_full &&
imported->encode() == full_before);
std::cout << "lineage_archive_full_bytes=" << bytes.size()
<< " max=" << max_archive_legacy_bytes << '\n';
}
void ownership_import_retains_exact_history() {
LineageArchive source;
CHECK(source.admit(descend(90, 0)));
CHECK(source.record_birth(500, 90, evo::Tick{10}));
CHECK(source.record_birth(501, 90, evo::Tick{10}));
source.upgrade_to_revision_format();
CHECK(source.record_mutation(500, descend(20, 90, 409), evo::Tick{11}));
CHECK(source.record_mutation(500, descend(10, 20, 418), evo::Tick{12}));
LineageArchive target;
CHECK(target.admit(descend(700, 0, 391)));
CHECK(target.record_birth(1000, 700, evo::Tick{1}));
CHECK(target.record_death(1000, evo::Tick{2}));
const auto source_before = source.encode(), target_before = target.encode();
const std::array<std::uint64_t, 1> selected{500};
const auto merged = target.merge_living_from(source, selected);
CHECK(merged && merged->recorded() == 2 && merged->archived() == 4);
CHECK(merged->organism(500) == source.organism(500));
CHECK(merged->current_genome(500) == source.current_genome(500));
CHECK(merged->ancestry(10) == source.ancestry(10));
CHECK(merged->revisions().size() == 2 && !merged->organism(501));
const auto retained_dead = merged->organism(1000);
CHECK(retained_dead && !retained_dead->alive && merged->find(700));
CHECK(source.encode() == source_before && target.encode() == target_before);
const auto repeated = merged->merge_living_from(source, selected);
CHECK(repeated && repeated->encode() == merged->encode());
const auto restored = LineageArchive::decode(merged->encode());
CHECK(restored && restored->encode() == merged->encode());
LineageArchive prefix;
CHECK(prefix.admit(descend(90, 0)));
CHECK(prefix.record_birth(500, 90, evo::Tick{10}));
prefix.upgrade_to_revision_format();
CHECK(prefix.record_mutation(500, descend(20, 90, 409), evo::Tick{11}));
const auto prefix_before = prefix.encode();
const auto continued = prefix.merge_living_from(source, selected);
CHECK(continued && continued->current_genome(500) == source.current_genome(500));
CHECK(!source.merge_living_from(prefix, selected)); // Older evidence cannot rewind history.
CHECK(prefix.encode() == prefix_before && source.encode() == source_before);
LineageArchive dead{*merged};
CHECK(dead.record_death(500, evo::Tick{20}));
const auto dead_before = dead.encode();
CHECK(!dead.merge_living_from(source, selected) && dead.encode() == dead_before);
CHECK(!target.merge_living_from(dead, selected));
LineageArchive conflict;
CHECK(conflict.admit(descend(90, 0, 300)));
const auto conflict_before = conflict.encode();
CHECK(!conflict.merge_living_from(source, selected) && conflict.encode() == conflict_before);
LineageArchive different_birth;
CHECK(different_birth.admit(descend(90, 0)));
CHECK(different_birth.record_birth(500, 90, evo::Tick{9}));
const auto birth_before = different_birth.encode();
CHECK(!different_birth.merge_living_from(source, selected) &&
different_birth.encode() == birth_before);
CHECK(!target.merge_living_from(source, std::array<std::uint64_t, 2>{500, 500}));
CHECK(!target.merge_living_from(source, std::array<std::uint64_t, 2>{501, 500}));
CHECK(!target.merge_living_from(source, std::array<std::uint64_t, 1>{0}));
CHECK(!target.merge_living_from(source, std::array<std::uint64_t, 1>{9999}));
CHECK(!target.merge_living_from(source, {}));
}
} // namespace
int main() try {
a_genome_outlives_every_organism_that_carried_it();
@@ -497,9 +573,11 @@ int main() try {
genome_revisions_preserve_birth_and_replay_current_genome();
mutation_history_upgrade_and_failures_are_explicit();
a_full_archive_round_trips();
ownership_import_retains_exact_history();
schemas_mix_without_rewriting();
std::cout << "PASS lineage retention, branching ancestry and provisional absence\n";
return 0;
} catch (...) {
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}