Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m40s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m46s
Foundation / image (push) Successful in 5m34s
The region view adds the rules-13 drip and complete counts and totals over every life and deposit. The region page is rebuilt around the map: a KPI strip (tick pace, population, deposit capacity, region energy and matter, spent pool, next drip), layer toggles that double as the legend, zoom and a scale, and tabs for inspecting cells and deposits, resources (where each channel sits, the spent pool and each channel's next drip), actions, the running tuning and session access. The admin API serves the region tuning file read only (--region-tuning). Light and dark themes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
7.2 KiB
C++
151 lines
7.2 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");
|
|
}
|
|
}
|
|
|
|
// 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};
|
|
state = checked(state->revamp_upgrade_candidate(rules), "revamp upgrade");
|
|
const auto view = render_cellular_admin_view(*state, {});
|
|
require(view.find("],\"drip\":[20,20000000,1000000],\"cells_total\":") != std::string::npos,
|
|
"rules-13 drip");
|
|
}
|
|
} // 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;
|
|
}
|