Add cellular mutation replay trace v3
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 2m9s
Foundation / checks (ecs) (push) Successful in 2m2s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m11s
Foundation / checks (postgres) (push) Canceled after 1m3s
Foundation / checks (network) (push) Canceled after 1m9s

This commit is contained in:
dingo
2026-10-11 06:29:17 -04:00
parent a479ce2d95
commit d9bf60138e
14 changed files with 596 additions and 49 deletions
+85 -1
View File
@@ -98,6 +98,7 @@ void reserved_birth_is_funded_and_detached() {
auto trace_base = empty_cellular_owner(founder_price(1), {{0, 0}});
CellularBatch birth_batch;
birth_batch.format_version = cellular_batch_v2_format;
birth_batch.header = {trace_base->world(), trace_base->region(), trace_base->frame(), {}, {},
trace_base->tick(), trace_base->tick() + 1};
birth_batch.header.predecessor.fill(3);
@@ -123,7 +124,14 @@ void reserved_birth_is_funded_and_detached() {
(*legacy_bytes)[8] = static_cast<std::uint8_t>(cellular_batch_legacy_format);
legacy_bytes->erase(legacy_bytes->begin() + 116, legacy_bytes->begin() + 120);
const auto decoded_legacy = decode_cellular_batch(*legacy_bytes);
CHECK(decoded_legacy && decoded_legacy->ticks[0].births.empty());
CHECK(decoded_legacy && decoded_legacy->format_version == cellular_batch_legacy_format &&
decoded_legacy->ticks[0].births.empty());
auto v2_bytes = encode_cellular_batch(legacy_batch);
CHECK(v2_bytes);
const auto decoded_v2 = decode_cellular_batch(*v2_bytes);
CHECK(decoded_v2 && decoded_v2->format_version == cellular_batch_v2_format &&
decoded_v2->ticks[0].births.empty() &&
decoded_v2->ticks[0].lives == legacy_batch.ticks[0].lives);
auto invalid_birth_batch = birth_batch;
invalid_birth_batch.ticks[0].births[0].generation = 0;
CHECK(encode_cellular_batch(invalid_birth_batch).error() == CellularBatchError::format);
@@ -297,6 +305,82 @@ void retained_feeding_earns_a_persistent_mutation_offer() {
CHECK(owner.advance_tick(idle));
const auto after_tick = owner.mutation_offer(life_id);
CHECK(after_tick && after_tick == earned);
auto revision_owner = owner.migrate_to_v3();
CHECK(revision_owner && (*revision_owner)->format_version() == cellular_lives_revision_format);
const auto current_offer = (*revision_owner)->mutation_offer(life_id);
CHECK(current_offer && *current_offer);
const CellularMutationSelection selection{life_id,
(*revision_owner)->lives()[0].mutation.event_index,
(*revision_owner)->lives()[0].mutation.offer_tick,
999, (*current_offer)->candidates[0].operator_id};
CellularBatch mutation_batch;
mutation_batch.header = {(*revision_owner)->world(),
(*revision_owner)->region(),
(*revision_owner)->frame(),
{},
{},
(*revision_owner)->tick(),
(*revision_owner)->tick() + 1};
mutation_batch.header.predecessor.fill(0x31);
mutation_batch.header.predecessor_digest.fill(0x41);
CellularTickIntents mutation_tick;
mutation_tick.lives.push_back({life_id, {}});
mutation_tick.mutations.push_back(selection);
mutation_batch.ticks.push_back(mutation_tick);
const auto mutation_bytes = encode_cellular_batch(mutation_batch);
CHECK(mutation_bytes);
const auto decoded_mutation = decode_cellular_batch(*mutation_bytes);
CHECK(decoded_mutation && *decoded_mutation == mutation_batch);
const std::array mutation_actions{CellularMutationActionRecord{
(*revision_owner)->lives()[0].account,
44,
mutation_batch.header.end_tick,
{life_id, selection.event_index, selection.offer_tick, selection.operator_id}}};
const auto action_block = encode_cellular_mutation_action_block(
mutation_actions, mutation_batch.header.begin_tick, mutation_batch.header.end_tick);
CHECK(action_block);
const auto decoded_action_block = decode_cellular_mutation_action_block(
*action_block, mutation_batch.header.begin_tick, mutation_batch.header.end_tick);
CHECK(decoded_action_block &&
*decoded_action_block ==
std::vector<CellularMutationActionRecord>{mutation_actions.front()} &&
match_cellular_mutation_actions_to_trace(**revision_owner, *decoded_mutation,
*decoded_action_block));
const auto replayed_mutation = replay_cellular_batch(**revision_owner, *decoded_mutation);
CHECK(replayed_mutation && (*replayed_mutation)->tick() == mutation_batch.header.end_tick);
const std::array idle_next{CellularLifeIntent{life_id, {}}};
const std::array selections{selection};
const auto direct_mutation =
(*revision_owner)->advance_tick_with_mutations(idle_next, selections);
CHECK(direct_mutation && direct_mutation->mutations.size() == 1 &&
(*replayed_mutation)->snapshot() == (*revision_owner)->snapshot() &&
(*revision_owner)->current_total() == (*revision_owner)->opening_total());
if (direct_mutation->mutations[0].result == CellularMutationResult::applied) {
CHECK(direct_mutation->mutations[0].successor_id == selection.successor_id &&
(*revision_owner)->lives()[0].identity.genome == selection.successor_id &&
(*revision_owner)
->archive()
.current_genome((*revision_owner)->lives()[0].identity.organism) ==
selection.successor_id &&
(*revision_owner)->archive().revisions().size() == 1 &&
!(*revision_owner)->lives()[0].mutation.offer);
} else if (direct_mutation->mutations[0].result ==
CellularMutationResult::insufficient_funding) {
CHECK(direct_mutation->mutations[0].result ==
CellularMutationResult::insufficient_funding &&
(*revision_owner)->lives()[0].identity.genome ==
(*revision_owner)
->archive()
.organism((*revision_owner)->lives()[0].identity.organism)
->genome &&
(*revision_owner)->archive().revisions().empty() &&
(*revision_owner)->lives()[0].mutation.offer.has_value());
} else {
CHECK(direct_mutation->mutations[0].result == CellularMutationResult::life_died &&
(*revision_owner)->lives().empty() && (*revision_owner)->corpses().size() == 1 &&
(*revision_owner)->archive().revisions().empty());
}
}
void owner_advances_and_closes_death_atomically() {