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
+460
View File
@@ -0,0 +1,460 @@
#include "evo/server/lifecycle/cellular_migration.hpp"
#include "evo/server/lifecycle/cellular_population_batch.hpp"
#include "fixtures/cellular_ecology.hpp"
#include <limits>
namespace {
using namespace evo;
using namespace evo::server;
using namespace evo::fixture;
Inventory plus(Inventory a, const Inventory& b) {
const auto maximum = std::numeric_limits<std::uint64_t>::max();
require(b.energy.value <= maximum - a.energy.value, "test energy overflow");
a.energy.value += b.energy.value;
for (std::size_t c = 0; c < a.matter.size(); ++c) {
require(b.matter[c].value <= maximum - a.matter[c].value, "test matter overflow");
a.matter[c].value += b.matter[c].value;
}
return a;
}
void step(CellularLives& owner, bool freeze = true) {
auto intents = checked(wildlife_intents(owner, owner.tick() + 1), "migration fixture wildlife");
for (const auto& life : owner.lives()) {
if (life.account == LifeAccount{})
continue;
CellularLifeIntent intent{life.identity.life, {}};
intent.intent.frozen = freeze;
if (!freeze)
intent.intent.bud = (owner.tick() + 1 + life.identity.life) % 32 == 0;
intents.push_back(intent);
}
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
checked(owner.advance_tick(intents), "migration fixture tick");
}
Owner funded(bool suspend = true, std::uint32_t founders = 4, std::uint64_t region = 1) {
auto owner = opening(1, true, founders, true, region);
const auto wildlife = [&] {
return std::ranges::any_of(owner->lives(),
[](const auto& life) { return life.account == LifeAccount{}; });
};
for (unsigned attempts = 0; attempts < 8192 && !wildlife(); ++attempts)
step(*owner, false);
require(wildlife(), "migration fixture has no funded wildlife");
if (suspend)
for (std::uint64_t i = 0; i <= cellular_linger_ticks; ++i)
step(*owner);
return owner;
}
Owner destination(const CellularLives& source, std::uint32_t founders = 0, std::uint64_t world = 0,
bool food = false) {
const auto endowment = checked(biology::primitive_endowment(biology::primitive_founder_v3),
"destination endowment");
Inventory funding;
for (std::uint32_t i = 0; i < founders; ++i) {
funding = plus(plus(funding, endowment.body), endowment.reserve);
funding = plus(funding, {{endowment.construction.value}, {}});
}
std::vector<SpawnSite> sites;
sites.reserve(std::max(founders, 1U));
for (std::uint32_t i = 0; i < std::max(founders, 1U); ++i)
sites.push_back({1'000 + static_cast<std::int32_t>(i / 16) * 3'000,
1'000 + static_cast<std::int32_t>(i % 16) * 3'000});
const auto id = world == 0 ? source.world() : world;
const auto region = source.region() == 1 ? 2ULL : 1ULL;
auto primitive =
checked(PrimitiveLives::create({id, region, source.frame(), 27, funding, sites}),
"destination nursery");
const auto area = source.area();
biology::CellularHabitatConfig habitat{id,
region,
source.frame(),
static_cast<std::uint32_t>(area.width_um),
static_cast<std::uint32_t>(area.height_um),
{}};
habitat.format = biology::cellular_habitat_deposit_format;
habitat.next_deposit = 1;
if (food) {
// Independently funded finite destination food, placed at the incoming
// bodies so reproduction tests do not depend on a route to old pools.
for (const auto& life : source.lives())
for (std::uint32_t c = 0; c < 5; ++c) {
biology::CellularPatch mote;
mote.address = {static_cast<std::uint32_t>(life.position.x_um) + 1 + 2 * c,
static_cast<std::uint32_t>(life.position.y_um) + 1};
mote.id = habitat.next_deposit++;
mote.source = 28;
mote.radius_um = biology::cellular_mote_radius_um;
mote.kind = biology::CellularDepositKind::mote;
if (c == 0)
mote.stock.energy.value = 1'000'000'000'000ULL;
else
mote.stock.matter[c - 1].value = 1'000'000'000'000ULL;
habitat.patches.push_back(mote);
}
std::ranges::sort(habitat.patches, {}, &biology::CellularPatch::address);
}
auto owner = checked(
CellularLives::create(
*primitive, checked(biology::CellularHabitat::create(habitat), "destination habitat"),
{area, 0, source.ambient_temperature_millikelvin()}, CellularLivesProfile::foraging),
"destination owner");
const auto birth = source.tick() - (founders == 0 ? 0 : cellular_linger_ticks + 1);
while (owner->tick() < birth)
step(*owner);
for (std::uint32_t i = 0; i < founders; ++i) {
LifeRequest request{};
request.account.front() = 0xF1;
request.account[14] = static_cast<std::uint8_t>((i + 1) >> 8U);
request.account.back() = static_cast<std::uint8_t>(i + 1);
request.action = 1;
const auto identity = 1'000'000'000'000ULL + i;
owner = checked(owner->birth_candidate(
request, {identity, identity, identity, identity, {owner->tick()}}),
"destination funded birth");
}
while (owner->tick() < source.tick())
step(*owner);
require(owner->tick() == source.tick(), "destination cut mismatch");
return owner;
}
std::uint64_t wildlife_genome(const CellularLives& owner) {
const auto found = std::ranges::find_if(
owner.lives(), [](const auto& life) { return life.account == LifeAccount{}; });
require(found != owner.lives().end(), "no migration genome");
return found->identity.genome;
}
void put(std::vector<std::uint8_t>& bytes, std::size_t offset, std::uint64_t value,
unsigned width = 8) {
for (unsigned i = 0; i < width; ++i)
bytes[offset + i] = static_cast<std::uint8_t>(value >> (8U * i));
}
void checksum(std::vector<std::uint8_t>& bytes) {
std::uint64_t value = 14695981039346656037ULL;
for (const auto b : std::span{bytes}.first(bytes.size() - 8))
value = (value ^ b) * 1099511628211ULL;
put(bytes, bytes.size() - 8, value);
}
Owner decode(const CellularLives& trusted, const std::vector<std::uint8_t>& bytes) {
return checked(CellularLives::restore(bytes, trusted.world(), trusted.region(), trusted.frame(),
trusted.tick()),
"migration owner restore");
}
void upgrade_and_move() {
auto original = funded();
auto other = destination(*original, 1);
const auto original_bytes = original->snapshot();
auto source = checked(original->migration_upgrade_candidate(), "source explicit upgrade");
auto target = checked(other->migration_upgrade_candidate(), "destination explicit upgrade");
require(source->format_version() == 7 && source->rules_version() == 8 &&
source->snapshot().size() == original_bytes.size() + 88,
"upgrade rewrote biological format");
require(std::ranges::equal(source->lives(), original->lives()) &&
source->archive().encode() == original->archive().encode() &&
source->habitat().snapshot() == original->habitat().snapshot() &&
source->opening_total() == original->opening_total() &&
source->boundary_ledger() == CellularBoundaryLedger{} &&
original->snapshot() == original_bytes,
"upgrade changed biology/funding");
const auto source_before = source->snapshot(), target_before = target->snapshot();
const auto total = plus(source->current_total(), target->current_total());
const auto genome = wildlife_genome(*source);
auto moved = checked(CellularMigration::prepare(*source, *target, genome), "exact migration");
require(!moved.members.empty() && moved.source->tick() == source->tick() &&
moved.destination->tick() == target->tick(),
"migration aged biology");
require(source->snapshot() == source_before && target->snapshot() == target_before,
"migration mutated an input");
require(plus(moved.source->current_total(), moved.destination->current_total()) == total &&
moved.source->opening_total() == source->opening_total() &&
moved.destination->opening_total() == target->opening_total(),
"migration lost stock or rebased opening");
require(moved.source->archive().encode() == source->archive().encode() &&
moved.source->boundary_ledger().nonresident_organisms == moved.members,
"departure erased history or recorded death");
for (const auto id : moved.members) {
const auto before = std::ranges::find(source->lives(), id,
[](const auto& life) { return life.identity.life; });
const auto after = std::ranges::find(moved.destination->lives(), id,
[](const auto& life) { return life.identity.life; });
require(before != source->lives().end() && after != moved.destination->lives().end() &&
*before == *after,
"member was relabeled/healed/resampled");
require(moved.destination->archive().organism(id) == source->archive().organism(id),
"birth history changed");
}
require(moved.destination->next_bud_sequence() == target->next_bud_sequence(),
"import consumed a local bud identity");
auto source_after = decode(*moved.source, moved.source->snapshot());
auto target_after = decode(*moved.destination, moved.destination->snapshot());
const auto members = moved.members;
for (unsigned turn = 0; turn < 100; ++turn) {
const bool back = turn % 2 == 0;
auto next =
checked(CellularMigration::prepare(back ? *target_after : *source_after,
back ? *source_after : *target_after, genome),
"migration return trip");
if (back) {
source_after = std::move(next.destination);
target_after = std::move(next.source);
} else {
source_after = std::move(next.source);
target_after = std::move(next.destination);
}
source_after = decode(*source_after, source_after->snapshot());
target_after = decode(*target_after, target_after->snapshot());
require(plus(source_after->current_total(), target_after->current_total()) == total,
"return trip duplicated inventory");
}
// 101 total moves: the group remains at the destination with every body exact.
require(source_after->boundary_ledger().nonresident_organisms == members,
"nonresident history changed on oscillation");
step(*source_after);
step(*target_after);
require(plus(source_after->current_total(), target_after->current_total()) == total,
"continued biology broke boundary accounting");
bool died = false;
for (unsigned i = 0; i < 8192 && !died; ++i) {
step(*target_after);
died = std::ranges::any_of(members, [&](auto id) {
return !checked(target_after->archive().organism(id), "imported organism").alive;
});
}
require(died, "imported wildlife failed to die without food");
target_after = decode(*target_after, target_after->snapshot());
require(target_after->current_total() == moved.destination->current_total(),
"death/decay spent boundary history as stock");
std::cout << "migration members=" << members.size() << " source_bytes=" << source_before.size()
<< " target_bytes=" << target_before.size() << " oscillations=100\n";
}
void population_envelope() {
auto population = checked(CellularPopulation::create(funded()), "population before migration");
const auto genome = wildlife_genome(population->state());
checked(population->collapse(genome), "cohort before upgrade");
const auto old = population->snapshot();
auto next = checked(population->migration_upgrade_candidate(), "population explicit upgrade");
require(next->format_version() == 2 && population->format_version() == 1 &&
population->snapshot() == old &&
std::ranges::equal(next->members(), population->members()) &&
next->conversion_sequence() == population->conversion_sequence() &&
next->policy() == population->policy(),
"population upgrade lost tags/policy or changed its input");
const auto bytes = next->snapshot();
next = checked(CellularPopulation::restore(bytes, next->state().world(), next->state().region(),
next->state().frame(), next->state().tick()),
"population-2 restore");
require(next->snapshot() == bytes, "population-2 roundtrip changed");
auto bad = bytes;
bad[7] = '1';
put(bad, 8, 1, 4);
checksum(bad);
require(!CellularPopulation::restore(bad, next->state().world(), next->state().region(),
next->state().frame(), next->state().tick()),
"new owner admitted as historical envelope 1");
CellularPopulationBatch old_trace;
require(!execute_population_batch(*next, old_trace, true),
"old durable trace admitted new owner tuple");
auto peer = checked(
CellularPopulation::create(checked(
destination(next->state())->migration_upgrade_candidate(), "cohort peer upgrade")),
"cohort peer");
const auto peer_before = peer->snapshot();
auto migrated = checked(CellularMigration::prepare(*next, *peer, genome), "cohort transfer");
require(migrated.source->members().empty() &&
std::ranges::equal(migrated.destination->members(), next->members()) &&
migrated.source->conversion_sequence() == next->conversion_sequence() &&
migrated.destination->conversion_sequence() == peer->conversion_sequence() &&
migrated.source->policy() == next->policy() &&
migrated.destination->policy() == peer->policy() && next->snapshot() == bytes &&
peer->snapshot() == peer_before,
"migration changed representation, policy, sequence or input");
auto restored =
checked(CellularPopulation::restore(migrated.destination->snapshot(), peer->state().world(),
peer->state().region(), peer->state().frame(),
peer->state().tick()),
"migrated cohort restore");
require(std::ranges::equal(restored->members(), next->members()),
"cohort tags lost on restore");
checked(next->materialize(genome), "new envelope materialization");
std::vector<CellularLifeIntent> controlled;
for (const auto& life : next->state().lives())
if (life.account != LifeAccount{}) {
CellularLifeIntent frozen{life.identity.life, {}};
frozen.intent.frozen = true;
controlled.push_back(frozen);
}
checked(next->advance_tick(controlled), "new envelope continued biology");
}
void overlap_refusal() {
auto raw = funded(false);
for (unsigned i = 0; i < 128; ++i)
step(*raw, false);
for (std::uint64_t i = 0; i <= cellular_linger_ticks; ++i)
step(*raw);
auto source = checked(raw->migration_upgrade_candidate(), "overlap source upgrade");
auto target = checked(destination(*source)->migration_upgrade_candidate(), "overlap peer");
const auto first = wildlife_genome(*source);
auto initial =
checked(CellularMigration::prepare(*source, *target, first), "overlap first group");
source = std::move(initial.source);
target = std::move(initial.destination);
const auto second = wildlife_genome(*source);
require(second != first, "overlap fixture lacks an unrelated group");
const auto occupied = std::ranges::find_if(
target->lives(), [](const auto& life) { return life.account == LifeAccount{}; });
require(occupied != target->lives().end(), "missing occupied destination");
auto bytes = source->snapshot();
for (std::size_t i = 0; i < source->lives().size(); ++i)
if (source->lives()[i].account == LifeAccount{} &&
source->lives()[i].identity.genome == second) {
// This fixture has four founding sites; v7 header 308, life stride 504.
const auto record = 308 + 4 * 8 + i * 504;
put(bytes, record + 72, occupied->position.x_um);
put(bytes, record + 80, occupied->position.y_um);
}
checksum(bytes);
source = decode(*source, bytes); // Legal resident coordinates; transfer must test the peer.
const auto other = target->snapshot();
const auto result = CellularMigration::prepare(*source, *target, second);
require(!result && result.error() == CellularMigrationError::placement &&
source->snapshot() == bytes && target->snapshot() == other,
"overlapping transfer displaced/partially moved cells");
}
void refusal_and_codec() {
auto old = funded();
auto raw_target = destination(*old);
auto source = checked(old->migration_upgrade_candidate(), "codec source upgrade");
auto target = checked(raw_target->migration_upgrade_candidate(), "codec target upgrade");
const auto genome = wildlife_genome(*source);
const auto before = source->snapshot(), target_before = target->snapshot();
require(!CellularMigration::prepare(*old, *target, genome), "legacy owner silently migrated");
require(!CellularMigration::prepare(*source, *source, genome), "same owner migrated to itself");
require(!CellularMigration::prepare(*source, *target, 0) &&
!CellularMigration::prepare(*source, *target, 999999),
"absent group migrated");
auto late = decode(*target, target_before);
step(*late);
require(!CellularMigration::prepare(*source, *late, genome),
"different biological cuts migrated");
auto alien =
checked(destination(*source, 0, source->world() + 1)->migration_upgrade_candidate(),
"alien upgrade");
require(!CellularMigration::prepare(*source, *alien, genome), "world boundary relabeled");
auto active = funded(false);
auto active_target = destination(*active);
active = checked(active->migration_upgrade_candidate(), "active representation upgrade");
active_target = checked(active_target->migration_upgrade_candidate(), "active peer upgrade");
require(!CellularMigration::prepare(*active, *active_target, wildlife_genome(*active)),
"vulnerable controlled life entered transfer");
auto bad = before;
put(bad, 220, 1);
checksum(bad);
require(!CellularLives::restore(bad, source->world(), source->region(), source->frame(),
source->tick()),
"unfunded boundary credit admitted");
bad = before;
put(bad, 220 + 8, 1);
put(bad, 260 + 16, 1);
checksum(bad);
require(!CellularLives::restore(bad, source->world(), source->region(), source->frame(),
source->tick()),
"different chemical channels canceled");
const auto execution =
checked(CellularMigration::prepare(*source, *target, genome), "overflow amount reference");
std::array<std::uint64_t, 5> amounts{
execution.transferred.energy.value, execution.transferred.matter[0].value,
execution.transferred.matter[1].value, execution.transferred.matter[2].value,
execution.transferred.matter[3].value};
const auto channel = static_cast<std::size_t>(
std::ranges::find_if(amounts, [](auto value) { return value != 0; }) - amounts.begin());
require(channel < amounts.size(), "zero-stock organism migrated");
bad = before;
put(bad, 220 + channel * 8, UINT64_MAX);
put(bad, 260 + channel * 8, UINT64_MAX);
checksum(bad);
auto exhausted = decode(*source, bad); // Balanced huge flows never become spendable stock.
auto refused = CellularMigration::prepare(*exhausted, *target, genome);
require(!refused && refused.error() == CellularMigrationError::overflow, "outflow wrapped");
bad = target_before;
put(bad, 220 + channel * 8, UINT64_MAX);
put(bad, 260 + channel * 8, UINT64_MAX);
checksum(bad);
auto full = decode(*target, bad);
refused = CellularMigration::prepare(*source, *full, genome);
require(!refused && refused.error() == CellularMigrationError::overflow, "inflow wrapped");
for (const auto offset : {std::size_t{300}, std::size_t{304}}) {
bad = before;
put(bad, offset, UINT32_MAX, 4);
checksum(bad);
require(!CellularLives::restore(bad, source->world(), source->region(), source->frame(),
source->tick()),
"unbounded/reserved migration header admitted");
}
const auto stride = std::max(std::size_t{1}, before.size() / 32);
for (std::size_t length = 0; length < before.size(); length += stride)
require(!CellularLives::restore(std::span{before}.first(length), source->world(),
source->region(), source->frame(), source->tick()),
"truncated migration owner admitted");
require(source->snapshot() == before && target->snapshot() == target_before,
"rejection modified a peer");
}
void capacity() {
auto raw = funded(true, 1);
auto crowded = destination(*raw, 256);
auto source = checked(raw->migration_upgrade_candidate(), "capacity source upgrade");
auto target = checked(crowded->migration_upgrade_candidate(), "capacity target upgrade");
const auto before = source->snapshot(), other = target->snapshot();
const auto result = CellularMigration::prepare(*source, *target, wildlife_genome(*source));
require(!result && result.error() == CellularMigrationError::capacity &&
source->snapshot() == before && target->snapshot() == other,
"capacity pressure culled stock or partially moved a group");
}
void local_budding_among_imports() {
auto raw = funded(true, 4, 2);
auto source = checked(raw->migration_upgrade_candidate(), "higher namespace source");
auto target = checked(destination(*source, 1, 0, true)->migration_upgrade_candidate(),
"lower namespace funded destination");
auto moved = checked(CellularMigration::prepare(*source, *target, wildlife_genome(*source)),
"higher-to-lower namespace migration");
target = std::move(moved.destination);
const auto opening = target->current_total();
const auto next = target->next_bud_sequence();
const auto founder = std::ranges::find_if(target->lives(), [](const auto& life) {
return life.account != LifeAccount{};
})->identity.life;
bool local_parent = false;
for (unsigned i = 0; i < 8192 && target->next_bud_sequence() == next; ++i) {
auto intents = checked(wildlife_intents(*target, target->tick() + 1), "imported intents");
CellularLifeIntent controlled{founder, {}};
controlled.intent.bud = true;
intents.push_back(controlled);
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
checked(target->advance_tick(intents), "local real budding among imports");
for (const auto& life : target->lives())
if (life.identity.life >= cellular_bud_identity(1, next) &&
life.identity.life < cellular_bud_identity(2, 1) && life.parent_life == founder)
local_parent = true;
}
require(local_parent && target->next_bud_sequence() > next &&
target->current_total() == opening,
"local reproduction among imported IDs failed or spent boundary flows");
target = decode(*target, target->snapshot());
for (unsigned i = 0; i < 64; ++i)
step(*target);
require(std::ranges::is_sorted(target->lives(), {},
[](const auto& life) { return life.identity.life; }),
"local children displaced foreign namespace ordering");
}
} // namespace
int main() try {
upgrade_and_move();
refusal_and_codec();
capacity();
population_envelope();
overlap_refusal();
local_budding_among_imports();
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
+7 -7
View File
@@ -44,8 +44,8 @@ inline Owner restore(const CellularLives& state) {
"reference restore");
}
inline Owner opening(std::uint64_t seed, bool rich, std::uint32_t count = 4,
bool populated = true) {
inline Owner opening(std::uint64_t seed, bool rich, std::uint32_t count = 4, bool populated = true,
std::uint64_t region = 1) {
require(count > 0 && count <= biology::max_cellular_tick_lives, "fixture population bound");
const std::uint32_t side = count == 4 ? 6'000 : 48'000;
const auto world = 200 + seed;
@@ -61,8 +61,8 @@ inline Owner opening(std::uint64_t seed, bool rich, std::uint32_t count = 4,
for (std::int32_t index = 0; index < static_cast<std::int32_t>(count); ++index)
sites.push_back({1'000 + (index / 16) * 3'000, 1'000 + (index % 16) * 3'000});
}
auto primitive =
checked(PrimitiveLives::create({world, 1, 1, 17, funding, sites}), "reference nursery");
auto primitive = checked(PrimitiveLives::create({world, region, 1, 17, funding, sites}),
"reference nursery");
std::vector<biology::CellularPatch> pools;
for (const auto& site : sites) {
biology::CellularPatch pool;
@@ -78,9 +78,9 @@ inline Owner opening(std::uint64_t seed, bool rich, std::uint32_t count = 4,
Inventory amount{{rich ? 1'000'000ULL : 10'000ULL}, {}};
for (auto& channel : amount.matter)
channel.value = rich ? 100'000 : 10;
auto config = checked(
biology::scatter_deposits({world, 1, 1, side, side, {}}, pools, {64, 19, amount, seed}),
"reference deposits");
auto config = checked(biology::scatter_deposits({world, region, 1, side, side, {}}, pools,
{64, 19, amount, seed}),
"reference deposits");
if (rich) {
// Explicit finite contact food on each founding site. It is not a reserve grant
// or replenishment; the owner must acquire and spend it through real biology.
+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;
}
+10
View File
@@ -158,6 +158,16 @@ void manifests() {
"population payload changed");
require(!restore_cellular_payload(population->snapshot(), next),
"population mislabeled as cellular");
auto future = checked(population->migration_upgrade_candidate(), "future portable envelope");
auto mislabeled = next;
mislabeled.payload_bytes = future->snapshot().size();
auto refused = restore_population_payload(future->snapshot(), mislabeled);
require(!refused && refused.error() == CheckpointError::unsupported,
"portable envelope 2 bypassed durable bundle admission");
auto raw_mislabeled = source;
raw_mislabeled.payload_bytes = future->state().snapshot().size();
require(!restore_cellular_payload(future->state().snapshot(), raw_mislabeled),
"portable owner 7 bypassed raw durable bundle admission");
auto back = checked(population_profile_transition_manifest(
next, filled<32>(11), filled<16>(12), lease, source.build,
state->snapshot().size(), filled<32>(13)),