Files
aevolution/tests/cellular_admin_view_tests.cpp
T
dingoandClaude Opus 5.5 757304437e
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m34s
Foundation / postgres-tools (push) Successful in 26s
Foundation / server-image (push) Successful in 4m30s
Foundation / image (push) Successful in 5m46s
feat(admin): take reserve, cull wildlife, wildlife cap, fresh bud costs (schema 67)
ADR-0182 section 16, from playtesting region 16 at its 256-life cap.

- Bud costs: the region host's cache of each genome's bud cost was keyed
  by genome only, so after a tuning adoption the client kept the old cost
  (or "cannot bud"). It now clears when the rules' encoding changes.
- Wildlife cap: reproduction.wildlife_cap (optional, 0..organism cap,
  0 = the organism cap) refuses buds of parents without an account at that
  many lives, keeping the slots above it for players. Bits 17-31 of the
  energy-cycle word, so older rules keep their bytes. DEV file: 200.
- Schema 67: admin command kinds take_reserve (8: up to the amounts from a
  life's reserve to the spent pool) and remove_wildlife (9: every life
  without an account, as remove_cell).
- Region view: caps; the portal shows lives against the cap.
- Portal: Take reserve in the inspector, Remove all wildlife, and marking
  cells on the map (shift+click, shift+drag) for bulk removal; the guided
  editor lists optional keys the base revision lacks.
- Client: a refused bud says the region may be full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 16:06:56 -04:00

158 lines
7.6 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) +
",\"cells_total\":") != std::string::npos,
"heat");
}
}
// 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;
}