M12.6: add scoped multi-region cellular census queries
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m22s
Foundation / checks (network) (push) Successful in 20m57s
Foundation / checks (client) (push) Successful in 22m5s
Foundation / checks (tsan) (push) Successful in 24m37s
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 45m14s
Foundation / checks (postgres) (push) Canceled after 45m8s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m22s
Foundation / checks (network) (push) Successful in 20m57s
Foundation / checks (client) (push) Successful in 22m5s
Foundation / checks (tsan) (push) Successful in 24m37s
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 45m14s
Foundation / checks (postgres) (push) Canceled after 45m8s
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "evo/server/lifecycle/cellular_census.hpp"
|
||||
#include "evo/server/lifecycle/cellular_census_set.hpp"
|
||||
#include "fixtures/cellular_ecology.hpp"
|
||||
|
||||
#include <limits>
|
||||
@@ -202,6 +203,16 @@ void cohorts_and_death() {
|
||||
verify(dead, *scarce);
|
||||
require(dead.rows().size() == 1 && dead.rows().front().totals == CellularCensusTotals{},
|
||||
"corpse/detritus counted as a living or reproductive reserve");
|
||||
const auto& dead_boundary = dead.boundary();
|
||||
const auto dead_set = checked(
|
||||
CellularCensusSet::observe({dead_boundary.world, dead_boundary.frame, dead_boundary.tick,
|
||||
dead_boundary.owner_format, dead_boundary.rules,
|
||||
dead_boundary.quantum_microseconds},
|
||||
std::array{dead_boundary.region}, std::array{dead}),
|
||||
"known absent scoped census");
|
||||
require(checked(dead_set.query(dead.rows().front().genome, Scope::descendants),
|
||||
"known absent scoped lineage") == CellularCensusTotals{},
|
||||
"retained zero-carrier lineage became unknown or living stock");
|
||||
const auto empty = opening(1, true, 1, false);
|
||||
require(checked(CellularCensus::observe(*empty), "empty census").rows().empty(),
|
||||
"empty owner invented history");
|
||||
@@ -218,11 +229,164 @@ void cohorts_and_death() {
|
||||
require(!unsupported && unsupported.error() == CellularCensusError::unsupported,
|
||||
"legacy rules silently reinterpreted by current census");
|
||||
}
|
||||
Owner regional_founder(std::uint64_t region, std::uint64_t life, std::uint64_t genome,
|
||||
std::uint64_t event, std::uint64_t organism = 0) {
|
||||
auto owner = opening(1, true, 1, false, region);
|
||||
step(*owner);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 1;
|
||||
request.action = 1;
|
||||
return checked(
|
||||
owner->birth_candidate(
|
||||
request, {life, organism == 0 ? life : organism, genome, event, {owner->tick()}}),
|
||||
"regional census funded founder");
|
||||
}
|
||||
CellularCensusSetBoundary set_boundary(const CellularCensus& census) {
|
||||
const auto& b = census.boundary();
|
||||
return {b.world, b.frame, b.tick, b.owner_format, b.rules, b.quantum_microseconds};
|
||||
}
|
||||
void regional_sets() {
|
||||
auto a = regional_founder(1, 100, 100, 100);
|
||||
auto b = regional_founder(2, 200, 200, 200);
|
||||
const auto ca = checked(CellularCensus::observe(*a), "set region A");
|
||||
const auto cb = checked(CellularCensus::observe(*b), "set region B");
|
||||
const std::array<std::uint64_t, 2> required{1, 2};
|
||||
const auto boundary = set_boundary(ca);
|
||||
const auto observe = [&](const auto& observations) {
|
||||
return CellularCensusSet::observe(boundary, required, observations);
|
||||
};
|
||||
const std::array reversed{cb, ca};
|
||||
const auto set = checked(observe(reversed), "complete regional set");
|
||||
require(set.regions()[0].boundary().region == 1 && set.regions()[1].boundary().region == 2 &&
|
||||
set.boundary() == boundary,
|
||||
"regional set lost its boundary/canonical region order");
|
||||
for (const auto scope : {Scope::exact_genome, Scope::descendants}) {
|
||||
require(
|
||||
checked(set.query(100, scope), "cross-region founder A") == direct(*a, 100, false) &&
|
||||
checked(set.query(200, scope), "cross-region founder B") == direct(*b, 200, false),
|
||||
"missing local anchor hid a known lineage or manufactured stock");
|
||||
const auto unknown = set.query(300, scope);
|
||||
require(!unknown && unknown.error() == CellularCensusError::unknown_genome,
|
||||
"unknown anchor became scoped absence");
|
||||
}
|
||||
require(!set.query(100, Scope::invalid) &&
|
||||
set.query(100, Scope::invalid).error() == CellularCensusError::invalid_scope,
|
||||
"set accepted invalid scope");
|
||||
const auto refuse = [&](const auto& observations, CellularCensusSetError expected) {
|
||||
const auto result = observe(observations);
|
||||
require(!result && result.error() == expected,
|
||||
"set accepted incomplete/conflicting evidence");
|
||||
};
|
||||
refuse(std::array{ca}, CellularCensusSetError::coverage);
|
||||
refuse(std::array{ca, ca}, CellularCensusSetError::coverage);
|
||||
refuse(std::array{ca, cb, cb}, CellularCensusSetError::coverage);
|
||||
for (unsigned field = 0; field < 6; ++field) {
|
||||
auto wrong = boundary;
|
||||
switch (field) {
|
||||
case 0:
|
||||
++wrong.world;
|
||||
break;
|
||||
case 1:
|
||||
++wrong.frame;
|
||||
break;
|
||||
case 2:
|
||||
++wrong.tick;
|
||||
break;
|
||||
case 3:
|
||||
++wrong.owner_format;
|
||||
break;
|
||||
case 4:
|
||||
++wrong.rules;
|
||||
break;
|
||||
case 5:
|
||||
++wrong.quantum_microseconds;
|
||||
break;
|
||||
default:
|
||||
require(false, "invalid boundary-field test selector");
|
||||
break;
|
||||
}
|
||||
const auto result = CellularCensusSet::observe(wrong, required, reversed);
|
||||
require(!result && result.error() == CellularCensusSetError::boundary,
|
||||
"regional set accepted foreign/stale/version-mismatched evidence");
|
||||
}
|
||||
for (const auto bad : {std::array<std::uint64_t, 2>{0, 2}, {2, 1}, {1, 1}}) {
|
||||
const auto result = CellularCensusSet::observe(boundary, bad, reversed);
|
||||
require(!result && result.error() == CellularCensusSetError::invalid_request,
|
||||
"invalid required region set accepted");
|
||||
}
|
||||
require(!CellularCensusSet::observe(boundary, {}, {}), "empty scope accepted");
|
||||
auto duplicate = regional_founder(2, 100, 100, 100);
|
||||
refuse(std::array{ca, checked(CellularCensus::observe(*duplicate), "duplicate organism")},
|
||||
CellularCensusSetError::resident_conflict);
|
||||
step(*b);
|
||||
refuse(std::array{ca, checked(CellularCensus::observe(*b), "stale boundary")},
|
||||
CellularCensusSetError::boundary);
|
||||
require(checked(set.query(200, Scope::exact_genome), "detached region query") ==
|
||||
direct(*regional_founder(2, 200, 200, 200), 200, false),
|
||||
"later biology mutated the detached set");
|
||||
std::vector<CellularCensus> empty_regions;
|
||||
std::vector<std::uint64_t> ids;
|
||||
for (std::uint64_t region = 1; region <= max_cellular_census_regions + 1; ++region) {
|
||||
auto empty = opening(1, true, 1, false, region);
|
||||
step(*empty);
|
||||
empty_regions.push_back(checked(CellularCensus::observe(*empty), "empty region"));
|
||||
ids.push_back(region);
|
||||
}
|
||||
require(CellularCensusSet::observe(boundary, std::span{ids}.first(64),
|
||||
std::span{empty_regions}.first(64))
|
||||
.has_value() &&
|
||||
!CellularCensusSet::observe(boundary, ids, empty_regions),
|
||||
"regional query work bound not enforced");
|
||||
}
|
||||
void conflicting_regional_genomes() {
|
||||
auto a = regional_founder(1, 100, 100, 100);
|
||||
auto b = regional_founder(2, 200, 200, 200);
|
||||
// Independently valid owners can allocate the same successor ID. Shared
|
||||
// world identity must not merge their different immutable parent records.
|
||||
for (auto* owner : {a.get(), b.get()}) {
|
||||
bool applied = false;
|
||||
for (unsigned tick = 0; tick < 8192 && !applied; ++tick) {
|
||||
const auto& life = owner->lives().front();
|
||||
std::vector<CellularMutationSelection> choices;
|
||||
if (life.mutation.offer) {
|
||||
const auto& offer = *life.mutation.offer;
|
||||
for (const auto& candidate : offer.candidates) {
|
||||
const auto genome = checked(owner->archive().find(life.identity.genome),
|
||||
"set conflict mutation genome");
|
||||
if (biology::fund_mutation(genome, offer.context, offer, candidate.operator_id,
|
||||
900, 900, life.reserve)) {
|
||||
choices.push_back({life.identity.life, life.mutation.event_index,
|
||||
life.mutation.offer_tick, 900, candidate.operator_id});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::array<CellularLifeIntent, 1> intent{{{life.identity.life, {}}}};
|
||||
const auto result = checked(owner->advance_tick_with_mutations(intent, choices),
|
||||
"set conflict funded mutation");
|
||||
applied = !result.mutations.empty() &&
|
||||
result.mutations.front().result == CellularMutationResult::applied;
|
||||
}
|
||||
require(applied, "set conflict fixture did not fund a mutation");
|
||||
}
|
||||
while (a->tick() < b->tick())
|
||||
step(*a);
|
||||
while (b->tick() < a->tick())
|
||||
step(*b);
|
||||
const auto ca = checked(CellularCensus::observe(*a), "conflict census A");
|
||||
const auto cb = checked(CellularCensus::observe(*b), "conflict census B");
|
||||
const auto result = CellularCensusSet::observe(
|
||||
set_boundary(ca), std::array<std::uint64_t, 2>{1, 2}, std::array{ca, cb});
|
||||
require(!result && result.error() == CellularCensusSetError::genome_conflict,
|
||||
"different immutable records merged under one world genome ID");
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
presence_and_detachment();
|
||||
mutation_and_retention();
|
||||
cohorts_and_death();
|
||||
regional_sets();
|
||||
conflicting_regional_genomes();
|
||||
std::cout << "PASS local census presence, exact lineage queries, conversion and retention\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "evo/server/lifecycle/cellular_census.hpp"
|
||||
#include "evo/server/lifecycle/cellular_census_set.hpp"
|
||||
#include "evo/server/lifecycle/cellular_migration.hpp"
|
||||
#include "evo/server/lifecycle/cellular_migration_trace.hpp"
|
||||
#include "evo/server/lifecycle/cellular_population_batch.hpp"
|
||||
@@ -440,6 +441,46 @@ void upgrade_and_move() {
|
||||
require(arrived.resident[0].body == migrant_bodies &&
|
||||
arrived.resident[0].reserve == migrant_reserves,
|
||||
"census migrant inventory differs from exact individual stock");
|
||||
const auto& cut = departure.boundary();
|
||||
const CellularCensusSetBoundary boundary{cut.world, cut.frame, cut.tick,
|
||||
cut.owner_format, cut.rules, cut.quantum_microseconds};
|
||||
const std::array<std::uint64_t, 2> regions{1, 2};
|
||||
const auto combined =
|
||||
checked(CellularCensusSet::observe(boundary, regions, std::array{arrival, departure}),
|
||||
"settled pair census set");
|
||||
const auto combined_stock = checked(combined.query(genome, CellularCensusScope::descendants),
|
||||
"settled cross-region lineage");
|
||||
require(combined_stock.resident[0] == arrived.resident[0] &&
|
||||
combined_stock.retained_nonresident_records == moved.members.size(),
|
||||
"cross-region census counted departed history twice");
|
||||
for (std::size_t kind = 0; kind < combined_stock.resident.size(); ++kind) {
|
||||
const auto& actual = combined_stock.resident[kind];
|
||||
const auto& left = departed.resident[kind];
|
||||
const auto& right = arrived.resident[kind];
|
||||
require(actual.count == left.count + right.count &&
|
||||
actual.body == plus(left.body, right.body) &&
|
||||
actual.reserve == plus(left.reserve, right.reserve),
|
||||
"combined lineage count/body/reserve differs from settled exact stock");
|
||||
}
|
||||
auto arrival_population =
|
||||
checked(CellularPopulation::create(restore(*moved.destination)), "mixed census population");
|
||||
checked(arrival_population->collapse(genome), "mixed census collapse");
|
||||
const auto cohort_arrival =
|
||||
checked(CellularCensus::observe(*arrival_population), "mixed census cohort arrival");
|
||||
const auto mixed = checked(
|
||||
CellularCensusSet::observe(boundary, regions, std::array{departure, cohort_arrival}),
|
||||
"mixed raw/cohort census set");
|
||||
const auto mixed_stock = checked(mixed.query(genome, CellularCensusScope::descendants),
|
||||
"mixed representation lineage");
|
||||
require(mixed_stock.resident[0] == CellularCensusStock{} &&
|
||||
mixed_stock.resident[1] == arrived.resident[0] &&
|
||||
mixed_stock.resident[4] == departed.resident[4],
|
||||
"mixed classification lost/fabricated stock or suspended parent");
|
||||
const auto old_source = checked(CellularCensus::observe(*source), "unsettled source census");
|
||||
const auto double_owned =
|
||||
CellularCensusSet::observe(boundary, regions, std::array{old_source, arrival});
|
||||
require(!double_owned && double_owned.error() == CellularCensusSetError::resident_conflict,
|
||||
"source plus uncommitted destination copy counted twice");
|
||||
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());
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "evo/persistence/population_interval_store.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/server/cellular_region_host.hpp"
|
||||
#include "evo/server/lifecycle/cellular_census_set.hpp"
|
||||
#include "fixtures/cellular_ecology.hpp"
|
||||
#include "fixtures/postgres_relay.hpp"
|
||||
|
||||
@@ -1600,6 +1601,38 @@ void migration_publication(Fixture& f, const RegionKey destination_key,
|
||||
std::ranges::equal(destination_history.entries[0].census.rows(),
|
||||
census_oracle(expected_destination, dh).rows()),
|
||||
"historical migration census differs from exact paired biology");
|
||||
const auto& source_census = source_history.entries[0].census;
|
||||
const auto& destination_census = destination_history.entries[0].census;
|
||||
const auto& boundary = source_census.boundary();
|
||||
std::array required_regions{sk.region, dk.region};
|
||||
std::ranges::sort(required_regions);
|
||||
const auto census_set =
|
||||
take(CellularCensusSet::observe(
|
||||
{boundary.world, boundary.frame, boundary.tick, boundary.owner_format,
|
||||
boundary.rules, boundary.quantum_microseconds},
|
||||
required_regions, std::array{source_census, destination_census}),
|
||||
"committed paired history census set");
|
||||
// Identity and complete per-region rows survive real raw/cohort
|
||||
// publication, replay and repeated direction changes.
|
||||
require(census_set.regions().size() == 2 &&
|
||||
census_set.regions()[0].boundary().region == required_regions[0] &&
|
||||
census_set.regions()[1].boundary().region == required_regions[1],
|
||||
"paired history query lost declared region coverage");
|
||||
for (const auto& row : destination_census.rows()) {
|
||||
const auto combined =
|
||||
take(census_set.query(row.genome, CellularCensusScope::descendants),
|
||||
"committed cross-region lineage query");
|
||||
const auto local =
|
||||
take(destination_census.query(row.genome, CellularCensusScope::descendants),
|
||||
"committed destination lineage");
|
||||
const auto other =
|
||||
source_census.query(row.genome, CellularCensusScope::descendants);
|
||||
for (std::size_t kind = 0; kind < local.resident.size(); ++kind)
|
||||
require(combined.resident[kind].count ==
|
||||
local.resident[kind].count +
|
||||
(other ? other->resident[kind].count : 0),
|
||||
"committed set duplicated/dropped resident lineage stock");
|
||||
}
|
||||
if (direction == 0) {
|
||||
outgoing_history = std::move(source_history.entries.front());
|
||||
incoming_history = std::move(destination_history.entries.front());
|
||||
|
||||
Reference in New Issue
Block a user