Files
aevolution/tests/cellular_admin_view_tests.cpp
T
dingoandClaude Opus 5.5 54beceb823 feat(admin): read-only admin portal and API (ADR-0182 step 1, schema 61)
evo-admin-api serves the portal at srs.aeternalisgames.com and read-only JSON
for world 100 behind Keycloak (realm role aevolution-admin, audience
aevolution-admin, client aevolution-admin-portal): accounts with session,
status, lives, deaths, resets and mutation choices; one account's lives; the
world's regions; and a live 2D region view of cells, wildlife, pools and
bubbles. The portal is plain HTML/CSS/JS with PKCE sign-in, a strict CSP and
no third-party code.

- Schema 61: three bounded SECURITY DEFINER read functions, fenced in the
  privilege audit; no table or existing function changes.
- Cellular regions answer GET /admin/view on the ops port (NetworkPolicy:
  Prometheus and the admin portal only); CellularLives::extent_of reads the
  existing phenotype budget. No simulation, checkpoint or wire change.
- TokenVerifier takes an optional realm role and returns the email; the ops
  server's response bound is configurable (16 KiB default unchanged).
- DEV component admin-portal-dev (Deployment, Service, NetworkPolicies); the
  Ingress and the aevolution-admin-pg Secret are created out of band.
- CI scripts pinned to schema 60 now expect 61.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 12:39:28 -04:00

75 lines
3.3 KiB
C++

#include "evo/server/lifecycle/cellular_admin_view.hpp"
#include "fixtures/cellular_ecology.hpp"
#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");
}
} // namespace
int main() {
try {
renders_cells_and_deposits();
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
std::puts("cellular admin view tests passed");
return 0;
}