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

This commit is contained in:
dingo
2026-10-18 15:11:51 -04:00
parent a180c41ae7
commit 82568da9cd
20 changed files with 621 additions and 4 deletions
+164
View File
@@ -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) {