test(postgres): a cellular-v8 player feeds, is offered and chooses a mutation

A provisioned bundle-13 region with a contact pool at the spawn site runs
the live server's path end to end: host reservation, session batches with
the queued birth, contact feeding until an offer, host mutation admission
and its session publication with the mutation block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-20 16:06:32 -04:00
co-authored by Claude Opus 5.5
parent bbafaf6957
commit d1030b7dd1
+97
View File
@@ -748,6 +748,100 @@ void cellular_v8_provisioning_declares_light() {
#endif
}
#ifdef EVO_POSTGRES_M10
// A player on a cellular-v8 region feeds by contact until offered a mutation, chooses it
// and publishes the choice, all through the host and session builder as evo-server does.
void cellular_v8_player_chooses_a_mutation() {
using namespace evo::server;
const ServerRegion r{{9776, 1}, fresh("cellular-v8-mutation-9776")};
const std::string build(64, 'e');
int code = -1;
const auto provisioned =
provision_cellular(r, "9776", "cellular-v8", build, "c8a7e1d2b0b81e5c0f7e1d2ba1a0ce5d",
"2500,2500,3000,1,40000000000,4000000000,800000000,400000000,400000000",
code, "--pool", {"--light-pj", "40"});
CHECK(code == 0 && has(provisioned, "provisioned world=9776 region=1 sequence=5 tick=1"));
auto db = owner();
CHECK(db->query("INSERT INTO evolution.life_allocators VALUES(9776,1000)", {}, 5s));
const auto connect = [&]() -> std::expected<std::unique_ptr<Postgres>, PgFailure> {
return Postgres::connect({env("PGHOST"),
{},
env("PGPORT"),
env("PGDATABASE"),
env("EVO_PG_RUNTIME_USER"),
{},
{}},
5s);
};
Sha256Digest digest{};
digest.fill(0xEE);
auto objects = FilesystemObjectStore::open(r.root, r.key, max_cellular_lives_bytes);
CHECK(objects);
auto made =
CellularRegionHost::create({r.key, 9, {}, digest, {digest}}, connect, std::move(*objects));
CHECK(made);
auto host = std::move(*made);
CHECK(host->step().ready);
auto runtime = connect();
CHECK(runtime);
Uuid account{};
account[0] = 0x8F;
account.back() = 0x21;
const auto control =
claim_account_control(**runtime, r.key, *host->authority(), account, 1, 1, 60'000ms, 5s);
CHECK(control);
CHECK(host->create_primitive_life(account, control->generation, 7).result ==
evo::network::PrimitiveLifeResult::pending);
// One session batch of `ticks` still ticks, carrying queued births and choices.
const auto advance = [&](int ticks) {
CHECK(host->step().ready);
auto builder = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
CHECK(builder);
const std::vector births(host->queued_births().begin(), host->queued_births().end());
const std::vector mutations(host->queued_mutations().begin(),
host->queued_mutations().end());
for (int i = 0; i < ticks; ++i) {
std::vector<CellularLifeIntent> baseline;
for (const auto& life : builder->candidate().lives())
baseline.push_back({life.identity.life, {}});
std::ranges::sort(baseline, {}, &CellularLifeIntent::life_id);
const auto tick = builder->candidate().tick() + 1;
const std::span<const CellularTickIntents::Birth> born =
i == 0 ? std::span<const CellularTickIntents::Birth>{births}
: std::span<const CellularTickIntents::Birth>{};
const std::span<const evo::persistence::CellularMutationReservation> chosen =
i == 0 ? std::span<const evo::persistence::CellularMutationReservation>{mutations}
: std::span<const evo::persistence::CellularMutationReservation>{};
CHECK(builder->append_with_birth_refusals(tick, baseline, {}, born, chosen));
}
CHECK(builder->refused_births().empty());
const auto published =
host->publish(builder->batch(), builder->actions(), builder->mutation_actions());
CHECK(published);
return published->mutation_results;
};
advance(1);
CHECK(host->state()->lives().size() == 1 && host->state()->lives().front().account == account);
const auto life_id = host->state()->lives().front().identity.life;
for (int round = 0; round < 40 && !host->state()->lives().front().mutation.offer; ++round)
advance(64);
const auto& life = host->state()->lives().front();
CHECK(life.identity.life == life_id && life.mutation.offer.has_value());
const auto offer = *life.mutation.offer;
const CellularMutationActionInput choice{life_id, life.mutation.event_index,
life.mutation.offer_tick,
offer.candidates.front().operator_id};
const auto admitted = host->select_mutation(account, control->generation, 41, choice);
CHECK(admitted.status == CellularMutationAdmission::admitted &&
host->queued_mutations().size() == 1);
const auto results = advance(1);
CHECK(results.size() == 1 && host->queued_mutations().empty());
std::printf("cellular-v8 player mutation: operator %u result %u at tick %llu\n",
static_cast<unsigned>(choice.operator_id), static_cast<unsigned>(results.front()),
static_cast<unsigned long long>(host->state()->tick()));
}
#endif
void cellular_provisioning_survives_a_build_promotion() {
const ServerRegion r{{9761, 1}, fresh("cellular-provision-9761")};
const auto run = [&](const std::string& build, const std::string& commit,
@@ -785,6 +879,9 @@ void run_region_store_tests() {
cellular_v6_provisioning_uses_the_reproduction_bundle();
cellular_v7_provisioning_scatters_bubbles();
cellular_v8_provisioning_declares_light();
#ifdef EVO_POSTGRES_M10
cellular_v8_player_chooses_a_mutation();
#endif
full_volumes_publish_nothing();
failing_writes_leave_nothing();
check_store_qualifies_the_stores();