Files
aevolution/tests/cellular_admin_view_tests.cpp
T
dingoandClaude Opus 5.5 3c753970c8
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m29s
Foundation / image (push) Successful in 5m43s
feat(cellular): region ticks of up to 4,096 lives for testing (schema 68)
ADR-0182 section 17. The plan's 2,000-organism cap became the rules-12
key region.organism_cap, which was parsed but never enforced; the real
bound was max_cellular_tick_lives = 256 (ADR-0106), which rules 13's
organism cap could not exceed. The bound is now 4,096, for testing limits
only; the DEV tuning file keeps 256.

- max_cellular_tick_lives (4,096) bounds the raw region path: step, owner
  state, batch trace (cellular_batch_bytes_for) and current checkpoint
  traces. max_cellular_frozen_lives (256) keeps cohort populations,
  population batches, migration traces and pre-v3 cellular traces, whose
  database checks are fixed.
- Tuning: reproduction.organism_cap and wildlife_cap accept up to 4,096.
- Schema 68: the trace checker under the current publishers
  (cellular_births_v45) accepts 4,096 intents, births and mutations per
  tick; spawn_wildlife takes up to 256 cells a command.
- Region view and portal: the lineage archive's fill (births of 65,536,
  genomes of 4,096), at which a region stops ticking.
- PostgreSQL suite: 256 wildlife spawned in one command, then a 289-life
  tick published and recovered exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 17:30:22 -04:00

160 lines
7.8 KiB
C++

#include "evo/server/lifecycle/cellular_admin_view.hpp"
#include "fixtures/cellular_ecology.hpp"
#include <array>
#include <cstdio>
#include <string>
// ADR-0182 admin region view: every cell and deposit of a cellular owner, read without change.
namespace {
using namespace evo;
using namespace evo::server;
using namespace evo::fixture;
std::size_t count(const std::string& text, const std::string& part) {
std::size_t found = 0;
for (auto at = text.find(part); at != std::string::npos; at = text.find(part, at + 1))
++found;
return found;
}
void renders_cells_and_deposits() {
const auto state = opening(7, true);
const auto before = state->snapshot();
LifeAccount first{};
first.back() = 1;
const auto view = render_cellular_admin_view(
*state, [&](const LifeAccount& account) { return account == first; });
require(state->snapshot() == before, "rendering the view changed the owner");
require(view.starts_with("{\"world\":207,\"region\":1,\"tick\":" +
std::to_string(state->tick()) + ",\"rules\":"),
"view header");
require(view.ends_with("]}\n"), "view terminator");
require(view.find("\"area\":[6000,6000]") != std::string::npos, "view area");
require(view.find("\"cells_total\":4,") != std::string::npos, "cell total");
require(view.find("\"deposits_total\":" + std::to_string(state->habitat().patches().size())) !=
std::string::npos,
"deposit total");
// Four player cells, each with its account text; only the first is connected.
require(cellular_account_text(first) == "00000000-0000-0000-0000-000000000001", "account text");
require(count(view, "[\"10") == 4, "every life listed with its id as a string");
for (const auto& life : state->lives()) {
const auto extent = state->extent_of(life).value_or(0);
require(extent > 0, "a living cell has an extent");
const auto row =
"[\"" + std::to_string(life.identity.life) + "\",\"" +
std::to_string(life.identity.organism) + "\",\"" + cellular_account_text(life.account) +
"\"," + std::to_string(life.position.x_um) + "," + std::to_string(life.position.y_um) +
"," + std::to_string(extent) + "," + (life.account == first ? "2" : "0") + ",1,";
require(view.find(row) != std::string::npos, "cell row");
}
// Deposits by ascending id, and limits keep the lowest ids while totals stay complete.
const auto limited = render_cellular_admin_view(*state, {}, {.cells = 1, .deposits = 2});
require(count(limited, "[\"10") == 1, "cell limit");
require(limited.find("\"cells_total\":4,") != std::string::npos, "total beyond the limit");
require(limited.find("\"deposits\":[[1,") != std::string::npos &&
limited.find("],[2,") != std::string::npos &&
limited.find("],[3,") == std::string::npos,
"deposit limit keeps ids 1 and 2");
const auto none = render_cellular_admin_view(*state, {}, {.cells = 0, .deposits = 0});
require(none.find("\"cells\":[],\"deposits\":[]}") != std::string::npos, "empty lists");
// Counts and totals cover everything, whatever the limits; no drip before rules 13.
std::array<std::uint64_t, 5> reserve{}, body{}, bubbles{};
std::array<std::size_t, 3> kinds{};
const auto add = [](std::array<std::uint64_t, 5>& totals, const accounting::Inventory& stock) {
totals[0] += stock.energy.value;
for (std::size_t i = 0; i < 4; ++i)
totals[i + 1] += stock.matter[i].value;
};
for (const auto& life : state->lives()) {
add(reserve, life.reserve);
add(body, life.body);
}
for (const auto& patch : state->habitat().patches()) {
++kinds[static_cast<std::size_t>(patch.kind)];
if (patch.kind == biology::CellularDepositKind::mote)
add(bubbles, patch.stock);
}
const auto list = [](const std::array<std::uint64_t, 5>& totals) {
std::string text = "[";
for (std::size_t i = 0; i < totals.size(); ++i)
text += (i == 0 ? "" : ",") + std::to_string(totals[i]);
return text + "]";
};
const auto counts = "\"counts\":[4,0," + std::to_string(kinds[0]) + "," +
std::to_string(kinds[1]) + "," + std::to_string(kinds[2]) + "]";
require(reserve[0] > 0 && body[1] > 0, "the fixture's cells hold stock");
for (const auto& text : {view, none}) {
require(text.find(counts) != std::string::npos, "counts");
require(text.find("\"totals\":{\"reserve\":" + list(reserve) + ",\"body\":" + list(body) +
",") != std::string::npos,
"cell totals");
require(text.find(",\"bubbles\":" + list(bubbles) + "}") != std::string::npos,
"bubble totals");
require(text.find("\"drip\"") == std::string::npos, "a drip before rules 13");
require(text.find("],\"heat\":" + std::to_string(state->heat().energy.value) +
",\"archive\":[" + std::to_string(state->archive().recorded()) +
",65536," + std::to_string(state->archive().archived()) +
",4096],\"cells_total\":") != std::string::npos,
"heat and archive");
}
}
// The trial liquid rules (cellular_revamp_owner_tests).
CellularLiquidRules liquid() {
return {.currents = {5, 48'000, 48'000, 250, 2, 4, 3'000, 6'000, 60, 300},
.founder = {.thrust_q10 = 20'480,
.reverse_thrust_q10 = 20'480,
.forward_drag_ppm = 95'163,
.lateral_drag_ppm = 95'163,
.turn = 3'276},
.deposits = {.drift_radius_um = 200,
.max_drift_q10 = 100 * 1'024,
.drift_decay_ppm = 95'163,
.merged_cap = 8,
.bubble_radius_um = biology::cellular_mote_radius_um}};
}
// A rules-13 owner's view carries its spent-pool drip.
void renders_the_drip() {
auto state = opening(7, true, 2, false);
checked(state->advance_tick({}), "genesis tick");
state = checked(state->migration_upgrade_candidate(), "boundary upgrade");
state = checked(state->maturation_upgrade_candidate(), "maturation upgrade");
state = checked(state->inheritance_upgrade_candidate(), "inheritance upgrade");
state = checked(state->photosynthesis_upgrade_candidate({0, 1, {0}}), "light upgrade");
state = checked(state->liquid_upgrade_candidate(liquid()), "liquid upgrade");
CellularRevampRules rules{.body = {.essential_upkeep_per_thousand = 250},
.burn_pj_per_kfg = {2'000, 2'000, 2'000, 2'000},
.step = {.engulf_ratio_milli = 1'500,
.engulf_reserve_percent = 100,
.kill_bubble_per_thousand = 500},
.drip_interval_ticks = 20,
.drip_bubble_pj = 20'000'000,
.drip_bubble_fg = 1'000'000,
.heat_recycle_per_thousand = 1'000,
.drip_absorb = true,
.wildlife_cap = 200};
state = checked(state->revamp_upgrade_candidate(rules), "revamp upgrade");
const auto view = render_cellular_admin_view(*state, {});
require(view.find(",\"drip\":[20,20000000,1000000,1000,1],\"caps\":[256,200],"
"\"cells_total\":") != std::string::npos,
"rules-13 drip and energy cycle");
}
} // namespace
int main() {
try {
renders_cells_and_deposits();
renders_the_drip();
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
std::puts("cellular admin view tests passed");
return 0;
}