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 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m25s
Foundation / postgres-tools (push) Successful in 1m12s
Foundation / server-image (push) Successful in 4m20s
Foundation / image (push) Successful in 4m54s
ADR-0178. Bundle 14 (rules 12 on owner format 10) is admitted by schema 58 through parser-local normalization to bundle 13, with an exact fenced 13 -> 14 upgrade whose only input, the liquid rules, recovery reads from the target. Schema 58 also widens the canonical action input: byte 13 bit 0 is brake. evo-world-clone gains the cellular-v9 opening: cellular-v8 followed by the liquid upgrade from --tuning FILE (region size must match) and an optional --current-seed; resumable and idempotent at bundle 14. Session v13 adds the owner's velocity, heading and the region's current configuration to its perception, each deposit's world velocity, and a brake on cellular actions; older sessions keep their layouts. A rules-12 server lists every pool and the nearest 256 moving bubbles. The client speaks v13, brakes on Space (rebindable; older controls files take the default), draws currents as drifting streaks and carries bubbles along their velocities between perceptions. Tests: protocol v13 round trips and refusals, action-input brake, controls files, and a PostgreSQL cellular-v9 provisioning test whose player is born, swims and brakes through the live host. Full local PostgreSQL qualification, the Linux debug suite and the Windows client suite pass. Refreshes the DEV session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1018 lines
52 KiB
C++
1018 lines
52 KiB
C++
// M8.3 store qualification (ADR-0070) against real PostgreSQL and real processes:
|
|
// the object volume's free-space reserve, a genuinely failing write, the
|
|
// check-store probe (retention across runs, missing-volume refusal, privilege
|
|
// boundary) and a server whose volume is full. Run by tools/ci/postgres-check.sh.
|
|
#include "evo/biology/cellular_tuning.hpp"
|
|
#include "evo/persistence/account_control_store.hpp"
|
|
#include "evo/persistence/checkpoint_store.hpp"
|
|
#include "evo/persistence/region_checkpoint.hpp"
|
|
#ifdef EVO_POSTGRES_M10
|
|
#include "evo/server/cellular_region_host.hpp"
|
|
#include "evo/server/cellular_session_batch.hpp"
|
|
#endif
|
|
#include "evo/server/lifecycle/primitive_lives.hpp"
|
|
#include "fixtures/server_process.hpp"
|
|
#include <algorithm>
|
|
#include <csignal>
|
|
#include <fstream>
|
|
#include <source_location>
|
|
#include <sys/resource.h>
|
|
|
|
void run_region_store_tests();
|
|
|
|
namespace {
|
|
using namespace evo::test::process;
|
|
using namespace evo::persistence;
|
|
void check(bool value, std::source_location at = std::source_location::current()) {
|
|
if (!value)
|
|
throw std::runtime_error("region store test line " + std::to_string(at.line()));
|
|
}
|
|
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
|
constexpr std::size_t budget = 8000000;
|
|
constexpr std::uint64_t unreachable_reserve = std::uint64_t{1} << 60U; // 1 EiB.
|
|
std::unique_ptr<FilesystemObjectStore> store(const fs::path& root, RegionKey key,
|
|
std::uint64_t reserve = 0) {
|
|
auto made = FilesystemObjectStore::open(root, key, max_lineage_payload_bytes, nullptr, reserve);
|
|
CHECK(made);
|
|
return std::move(*made);
|
|
}
|
|
fs::path fresh(const std::string& name) {
|
|
const auto root = fs::path(env("PGHOST")) / name;
|
|
fs::remove_all(root);
|
|
fs::create_directory(root);
|
|
fs::permissions(root, fs::perms::owner_all, fs::perm_options::replace);
|
|
return root;
|
|
}
|
|
std::size_t entries(const fs::path& dir) {
|
|
std::size_t n = 0;
|
|
for ([[maybe_unused]] const auto& entry : fs::directory_iterator(dir))
|
|
++n;
|
|
return n;
|
|
}
|
|
std::vector<std::uint8_t> bytes_of(std::size_t size, std::uint8_t seed) {
|
|
std::vector<std::uint8_t> out(size);
|
|
for (std::size_t i = 0; i < size; ++i)
|
|
out[i] = static_cast<std::uint8_t>(seed + (i * 7U));
|
|
return out;
|
|
}
|
|
|
|
// A full volume refuses new objects before writing; identical objects already
|
|
// stored stay usable; a batch against a full volume publishes nothing.
|
|
void full_volumes_publish_nothing() {
|
|
const RegionKey key{7, 81};
|
|
const auto root = fresh("store-full");
|
|
const auto stored = bytes_of(4096, 0x10);
|
|
auto roomy = store(root, key);
|
|
CHECK(roomy->available_bytes().value_or(0) > 0 && roomy->reserve_bytes() == 0);
|
|
CHECK(roomy->put(stored));
|
|
auto full = store(root, key, unreachable_reserve);
|
|
CHECK(full->reserve_bytes() == unreachable_reserve);
|
|
const auto before = entries(full->directory());
|
|
auto refused = full->put(bytes_of(4096, 0x20));
|
|
CHECK(!refused && refused.error() == ObjectError::full);
|
|
CHECK(entries(full->directory()) == before); // No temporary, no object.
|
|
CHECK(full->put(stored)); // Reuse needs no space.
|
|
|
|
// A lineage batch cannot publish through a full volume; the head stays.
|
|
const auto r = provision(82, 0xDE);
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
auto runtime = Postgres::connect(
|
|
{env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"), env("EVO_PG_RUNTIME_USER"), {}, {}},
|
|
5s);
|
|
CHECK(runtime);
|
|
Sha256Digest build{};
|
|
build.fill(0xB1);
|
|
auto lease = acquire_region_lease(**runtime, r.key, build, 20000ms, 5s);
|
|
CHECK(lease);
|
|
auto state = evo::test::lineage_region();
|
|
RegionBatch<evo::processes::LineageRegion> batch{*state};
|
|
for (int i = 0; i < 10; ++i)
|
|
CHECK(batch.advance(evo::test::region_input(batch.end_tick() + 1)));
|
|
batch.seal();
|
|
Uuid commit{};
|
|
commit.fill(0xDF);
|
|
auto blocked = store(r.root, r.key, unreachable_reserve);
|
|
auto published =
|
|
publish_lineage_batch(**runtime, *blocked, *lease, *head, batch, commit, build, budget, 5s);
|
|
CHECK(!published && published.error().kind == PublicationError::upload &&
|
|
published.error().object == ObjectError::full);
|
|
CHECK(load_region_checkpoint(*db, r.key, 5s)->head == head->head);
|
|
CHECK(release_region_lease(**runtime, r.key, *lease, 5s));
|
|
}
|
|
|
|
// A write the filesystem really refuses (RLIMIT_FSIZE stands in for a full disk:
|
|
// the kernel rejects the write mid-object) is an io error that leaves no object
|
|
// and no temporary behind.
|
|
void failing_writes_leave_nothing() {
|
|
const auto root = fresh("store-efbig");
|
|
auto objects = store(root, {7, 83});
|
|
rlimit old{};
|
|
CHECK(::getrlimit(RLIMIT_FSIZE, &old) == 0);
|
|
const auto previous = std::signal(SIGXFSZ, SIG_IGN);
|
|
rlimit limited = old;
|
|
limited.rlim_cur = 8192;
|
|
CHECK(::setrlimit(RLIMIT_FSIZE, &limited) == 0);
|
|
auto refused = objects->put(bytes_of(65536, 0x30));
|
|
CHECK(::setrlimit(RLIMIT_FSIZE, &old) == 0);
|
|
std::signal(SIGXFSZ, previous);
|
|
CHECK(!refused && refused.error() == ObjectError::io);
|
|
CHECK(entries(objects->directory()) == 0);
|
|
CHECK(objects->put(bytes_of(65536, 0x30))); // The same write succeeds with room.
|
|
}
|
|
|
|
std::vector<std::string> check_store(const fs::path& objects, const std::string& user,
|
|
std::vector<std::string> extra, int& code) {
|
|
std::vector<std::string> args{env("EVO_WORLD_CLONE_BIN"),
|
|
"check-store",
|
|
"--world",
|
|
"7",
|
|
"--region",
|
|
"84",
|
|
"--pg-host",
|
|
env("PGHOST"),
|
|
"--pg-port",
|
|
env("PGPORT"),
|
|
"--pg-database",
|
|
env("PGDATABASE"),
|
|
"--pg-user",
|
|
user,
|
|
"--objects",
|
|
objects.string()};
|
|
args.insert(args.end(), extra.begin(), extra.end());
|
|
Child tool{args};
|
|
code = tool.wait_exit(30s);
|
|
return tool.lines();
|
|
}
|
|
bool has(const std::vector<std::string>& lines, std::string_view prefix) {
|
|
for (const auto& l : lines)
|
|
if (l.starts_with(prefix))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
// The in-cluster qualification probe, exercised locally.
|
|
void check_store_qualifies_the_stores() {
|
|
const auto root = fresh("store-check");
|
|
const auto runtime = env("EVO_PG_RUNTIME_USER");
|
|
int code = -1;
|
|
auto first = check_store(root, runtime, {}, code);
|
|
CHECK(code == 0 && has(first, "objects available_mib=") && has(first, "probe created digest="));
|
|
CHECK(has(first, "database version=180006 user=" + runtime + " ssl=false"));
|
|
CHECK(has(first, "database tables=denied functions=reachable head=none"));
|
|
// A later run (a restarted or rescheduled pod) verifies the retained probe.
|
|
auto second = check_store(root, runtime, {}, code);
|
|
CHECK(code == 0 && has(second, "probe verified digest="));
|
|
// A missing or unmounted volume is refused, never created.
|
|
auto missing = check_store(root / "not-mounted", runtime, {}, code);
|
|
CHECK(code == 4 && has(missing, "objects refused missing-or-not-a-directory"));
|
|
CHECK(!fs::exists(root / "not-mounted"));
|
|
// A full volume refuses the probe (fresh namespace, reserve beyond any disk).
|
|
const auto other = fresh("store-check-full");
|
|
auto full = check_store(other, runtime, {"--reserve-mib", "1048576"}, code);
|
|
CHECK(code == 4 && has(full, "probe refused full"));
|
|
// The same check through a libpq service file, as the cluster Jobs run it.
|
|
const auto service = root / "pg_service.conf";
|
|
{
|
|
std::FILE* f = std::fopen(service.c_str(), "wb");
|
|
CHECK(f != nullptr);
|
|
const auto text = "[evolution]\nhost=" + env("PGHOST") + "\nport=" + env("PGPORT") +
|
|
"\ndbname=" + env("PGDATABASE") + "\nuser=" + runtime +
|
|
"\nsslmode=disable\nconnect_timeout=5\n";
|
|
CHECK(std::fwrite(text.data(), 1, text.size(), f) == text.size());
|
|
CHECK(std::fclose(f) == 0);
|
|
}
|
|
Child via_service{{env("EVO_WORLD_CLONE_BIN"), "check-store", "--world", "7", "--region", "84",
|
|
"--pg-service", service.string(), "--objects", root.string()}};
|
|
CHECK(via_service.wait_exit(30s) == 0 && via_service.printed("probe verified digest=") &&
|
|
via_service.printed("database tables=denied functions=reachable"));
|
|
// An owner login can read tables: not an acceptable runtime identity.
|
|
auto owner_run = check_store(root, env("PGUSER"), {}, code);
|
|
CHECK(code == 3 && has(owner_run, "database tables=READABLE"));
|
|
}
|
|
|
|
// A real server on a full volume keeps simulating but never acknowledges, and its
|
|
// bounded drain gives up without committing anything.
|
|
void full_volume_server_acknowledges_nothing() {
|
|
const auto r = provision(85, 0xE7);
|
|
const auto before = head_of(r.key);
|
|
Child server{server_args(r, {"--objects-reserve-mib", "1048576", "--drain-ms", "1500",
|
|
"--ops-listen", "127.0.0.1:0"})};
|
|
CHECK(server.wait_for([](const std::string& l) { return l == "ready 1"; }, 20s));
|
|
server.send(input_lines(1, 15, false));
|
|
server.pump(3000ms);
|
|
CHECK(!server.printed("ack "));
|
|
server.signal(SIGTERM);
|
|
CHECK(server.wait_exit(20s) == 3); // Drain deadline passed with the batch unpublished.
|
|
CHECK(!server.printed("ack "));
|
|
const auto after = head_of(r.key);
|
|
CHECK(after.tick == before.tick && after.sequence == before.sequence);
|
|
}
|
|
// M8.4: the provisioning tool creates a region once from the development opening;
|
|
// a rerun (every Argo sync) leaves it untouched, and a server then serves it.
|
|
void provisioning_is_idempotent() {
|
|
const ServerRegion r{{7, 86}, fresh("provision-86")};
|
|
const auto run = [&](const std::string& user, int& code) {
|
|
Child tool{{env("EVO_WORLD_CLONE_BIN"),
|
|
"provision",
|
|
"--world",
|
|
"7",
|
|
"--region",
|
|
"86",
|
|
"--opening",
|
|
"development-v1",
|
|
"--pg-host",
|
|
env("PGHOST"),
|
|
"--pg-port",
|
|
env("PGPORT"),
|
|
"--pg-database",
|
|
env("PGDATABASE"),
|
|
"--pg-user",
|
|
user,
|
|
"--objects",
|
|
r.root.string(),
|
|
"--build",
|
|
"b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1",
|
|
"--retain-build",
|
|
"true"}};
|
|
code = tool.wait_exit(30s);
|
|
return tool.lines();
|
|
};
|
|
int code = -1;
|
|
auto denied = run(env("EVO_PG_RUNTIME_USER"), code);
|
|
CHECK(code != 0 && !has(denied, "provisioned "));
|
|
auto first = run(env("PGUSER"), code);
|
|
CHECK(code == 0 && has(first, "provisioned world=7 region=86 sequence=0 tick=0"));
|
|
auto second = run(env("PGUSER"), code);
|
|
CHECK(code == 0 && has(second, "already-provisioned world=7 region=86 sequence=0 tick=0"));
|
|
Child server{server_args(r)};
|
|
CHECK(server.wait_for([](const std::string& l) { return l == "ready 1"; }, 20s));
|
|
server.send(input_lines(1, 5, false));
|
|
CHECK(server.wait_line("ack " + request_hex(5) + " 5 ", 15s));
|
|
server.signal(SIGTERM);
|
|
CHECK(server.wait_exit(20s) == 0);
|
|
auto after = run(env("PGUSER"), code);
|
|
CHECK(code == 0 && has(after, "already-provisioned world=7 region=86 sequence=1 tick=5"));
|
|
}
|
|
|
|
// M11.2d-4: primitive genesis requires an explicit owner opening, and retries
|
|
// cannot mistake a different profile or frame for an idempotent success.
|
|
void primitive_provisioning_is_explicit_and_profile_safe() {
|
|
using namespace evo::server;
|
|
using evo::biology::primitive_endowment;
|
|
const ServerRegion r{{7, 89}, fresh("primitive-provision-89")};
|
|
const auto endowed = primitive_endowment();
|
|
CHECK(endowed);
|
|
evo::accounting::Inventory funding = endowed->body;
|
|
funding.energy.value += endowed->reserve.energy.value + endowed->construction.value;
|
|
const auto run = [&](const std::string& user, std::uint64_t frame, bool complete,
|
|
bool retain_build, int& code, std::uint64_t energy_delta = 0) {
|
|
std::vector<std::string> args{
|
|
env("EVO_WORLD_CLONE_BIN"),
|
|
"provision",
|
|
"--world",
|
|
"7",
|
|
"--region",
|
|
"89",
|
|
"--opening",
|
|
"primitive-v1",
|
|
"--pg-host",
|
|
env("PGHOST"),
|
|
"--pg-port",
|
|
env("PGPORT"),
|
|
"--pg-database",
|
|
env("PGDATABASE"),
|
|
"--pg-user",
|
|
user,
|
|
"--objects",
|
|
r.root.string(),
|
|
"--build",
|
|
"c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2",
|
|
"--frame",
|
|
std::to_string(frame),
|
|
"--source-id",
|
|
"1",
|
|
"--funding-energy-pj",
|
|
std::to_string(funding.energy.value + energy_delta),
|
|
"--funding-carbon-fg",
|
|
std::to_string(funding.matter[0].value),
|
|
"--funding-nitrogen-fg",
|
|
std::to_string(funding.matter[1].value),
|
|
"--funding-phosphorus-fg",
|
|
std::to_string(funding.matter[2].value),
|
|
"--funding-other-fg",
|
|
std::to_string(funding.matter[3].value),
|
|
"--site",
|
|
"0,0",
|
|
"--site",
|
|
"10000000,0"};
|
|
if (retain_build) {
|
|
args.insert(args.end() - 6, {"--retain-build", "true"});
|
|
}
|
|
if (!complete) {
|
|
const auto field = std::find(args.begin(), args.end(), "--funding-other-fg");
|
|
args.erase(field, field + 2);
|
|
}
|
|
Child tool{args};
|
|
code = tool.wait_exit(30s);
|
|
return tool.lines();
|
|
};
|
|
auto db = owner();
|
|
CHECK(db->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
|
"(decode(repeat('c2',32),'hex')) ON CONFLICT DO NOTHING",
|
|
{}, 5s));
|
|
int code = -1;
|
|
const auto denied = run(env("EVO_PG_RUNTIME_USER"), 3, true, false, code);
|
|
CHECK(code != 0 && !has(denied, "provisioned "));
|
|
const auto first = run(env("PGUSER"), 3, true, true, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=7 region=89 sequence=0 tick=0"));
|
|
const auto retry = run(env("PGUSER"), 3, true, true, code);
|
|
CHECK(code == 0 && has(retry, "already-provisioned world=7 region=89 sequence=0 tick=0"));
|
|
const auto mismatch = run(env("PGUSER"), 4, true, true, code);
|
|
CHECK(code == 4 && has(mismatch, "provision refused existing profile/frame mismatch"));
|
|
const auto changed_opening = run(env("PGUSER"), 3, true, true, code, 1);
|
|
CHECK(code == 4 && has(changed_opening, "provision refused existing opening mismatch"));
|
|
const auto incomplete = run(env("PGUSER"), 3, false, false, code);
|
|
CHECK(code == 2);
|
|
|
|
const auto committed = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(committed);
|
|
const auto manifest = decode_manifest(committed->manifest);
|
|
CHECK(manifest && manifest->profile == CheckpointProfile::primitive_lives_v1 &&
|
|
manifest->frame == 3);
|
|
auto objects =
|
|
FilesystemObjectStore::open(r.root, r.key, evo::server::max_primitive_lives_bytes);
|
|
CHECK(objects);
|
|
Sha256Digest build{};
|
|
build.fill(0xC2);
|
|
const std::array<Sha256Digest, 1> retained{build};
|
|
const auto recovered = recover_primitive_checkpoint(*db, **objects, r.key, retained, 5s);
|
|
CHECK(recovered && recovered->state->config().source == 1 &&
|
|
recovered->state->config().funding == funding &&
|
|
recovered->state->config().sites == std::vector<SpawnSite>{{0, 0}, {10000000, 0}});
|
|
}
|
|
|
|
// ADR-0123: provisioning creates the world's life allocator once at the audited
|
|
// start; reruns leave it untouched, and a start above the existing counter refuses.
|
|
void provisioning_creates_the_life_allocator_once() {
|
|
using evo::biology::primitive_endowment;
|
|
const ServerRegion r{{9760, 1}, fresh("allocator-9760")};
|
|
const auto endowed = primitive_endowment();
|
|
CHECK(endowed);
|
|
evo::accounting::Inventory funding = endowed->body;
|
|
funding.energy.value += endowed->reserve.energy.value + endowed->construction.value;
|
|
const auto run = [&](const std::string& opening, std::uint64_t start, int& code) {
|
|
std::vector<std::string> args{
|
|
env("EVO_WORLD_CLONE_BIN"),
|
|
"provision",
|
|
"--world",
|
|
"9760",
|
|
"--region",
|
|
"1",
|
|
"--opening",
|
|
opening,
|
|
"--pg-host",
|
|
env("PGHOST"),
|
|
"--pg-port",
|
|
env("PGPORT"),
|
|
"--pg-database",
|
|
env("PGDATABASE"),
|
|
"--pg-user",
|
|
env("PGUSER"),
|
|
"--objects",
|
|
r.root.string(),
|
|
"--build",
|
|
"c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3",
|
|
"--retain-build",
|
|
"true",
|
|
"--life-allocator-start",
|
|
std::to_string(start)};
|
|
if (opening == "primitive-v1") {
|
|
const std::vector<std::string> primitive{"--frame",
|
|
"3",
|
|
"--source-id",
|
|
"1",
|
|
"--funding-energy-pj",
|
|
std::to_string(funding.energy.value),
|
|
"--funding-carbon-fg",
|
|
std::to_string(funding.matter[0].value),
|
|
"--funding-nitrogen-fg",
|
|
std::to_string(funding.matter[1].value),
|
|
"--funding-phosphorus-fg",
|
|
std::to_string(funding.matter[2].value),
|
|
"--funding-other-fg",
|
|
std::to_string(funding.matter[3].value),
|
|
"--site",
|
|
"0,0"};
|
|
args.insert(args.end(), primitive.begin(), primitive.end());
|
|
}
|
|
Child tool{args};
|
|
code = tool.wait_exit(30s);
|
|
return tool.lines();
|
|
};
|
|
const auto next_identity = [] {
|
|
auto db = owner();
|
|
auto rows = db->query(
|
|
"SELECT next_identity FROM evolution.life_allocators WHERE world_id = 9760", {}, 5s);
|
|
if (!rows || rows->size() != 1 || (*rows)[0].size() != 1)
|
|
return std::string{};
|
|
return (*rows)[0][0].value_or(std::string{});
|
|
};
|
|
int code = -1;
|
|
const auto development = run("development-v1", 5000, code);
|
|
CHECK(code == 2 && next_identity().empty()); // No lives, so no allocator.
|
|
const auto first = run("primitive-v1", 5000, code);
|
|
CHECK(code == 0 && has(first, "life-allocator world=9760 next=5000") &&
|
|
has(first, "provisioned world=9760 region=1 sequence=0 tick=0"));
|
|
const auto retry = run("primitive-v1", 5000, code);
|
|
CHECK(code == 0 && has(retry, "life-allocator world=9760 next=5000") &&
|
|
has(retry, "already-provisioned world=9760 region=1 sequence=0 tick=0"));
|
|
const auto lower = run("primitive-v1", 10, code);
|
|
CHECK(code == 0 && has(lower, "life-allocator world=9760 next=5000"));
|
|
const auto higher = run("primitive-v1", 6000, code);
|
|
CHECK(code == 4 && has(higher, "life-allocator refused existing below start"));
|
|
CHECK(next_identity() == "5000");
|
|
}
|
|
|
|
// ADR-0123: an image promotion changes --build, but a cellular genesis records the
|
|
// build that wrote it. A rerun under a new build still resolves the same genesis,
|
|
// while a different commit or opening is refused.
|
|
// One cellular provisioning run for region 1 of `world` with a one-founder opening.
|
|
std::vector<std::string> provision_cellular(const ServerRegion& r, const std::string& world,
|
|
const std::string& opening, const std::string& build,
|
|
const std::string& commit, const std::string& patch,
|
|
int& code, const std::string& food = "--patch",
|
|
const std::vector<std::string>& extra = {}) {
|
|
const auto endowed = evo::biology::primitive_endowment();
|
|
CHECK(endowed);
|
|
evo::accounting::Inventory funding = endowed->body;
|
|
funding.energy.value += endowed->reserve.energy.value + endowed->construction.value;
|
|
std::vector<std::string> arguments{env("EVO_WORLD_CLONE_BIN"),
|
|
"provision",
|
|
"--world",
|
|
world,
|
|
"--region",
|
|
"1",
|
|
"--opening",
|
|
opening,
|
|
"--pg-host",
|
|
env("PGHOST"),
|
|
"--pg-port",
|
|
env("PGPORT"),
|
|
"--pg-database",
|
|
env("PGDATABASE"),
|
|
"--pg-user",
|
|
env("PGUSER"),
|
|
"--objects",
|
|
r.root.string(),
|
|
"--build",
|
|
build,
|
|
"--retain-build",
|
|
"true",
|
|
"--commit",
|
|
commit,
|
|
"--frame",
|
|
"9",
|
|
"--source-id",
|
|
"1",
|
|
"--funding-energy-pj",
|
|
std::to_string(funding.energy.value),
|
|
"--funding-carbon-fg",
|
|
std::to_string(funding.matter[0].value),
|
|
"--funding-nitrogen-fg",
|
|
std::to_string(funding.matter[1].value),
|
|
"--funding-phosphorus-fg",
|
|
std::to_string(funding.matter[2].value),
|
|
"--funding-other-fg",
|
|
std::to_string(funding.matter[3].value),
|
|
"--site",
|
|
"2500,2500",
|
|
"--width-um",
|
|
"10000",
|
|
"--height-um",
|
|
"10000",
|
|
"--ambient-temperature-mk",
|
|
"293150",
|
|
food,
|
|
patch};
|
|
arguments.insert(arguments.end(), extra.begin(), extra.end());
|
|
Child tool{arguments};
|
|
code = tool.wait_exit(30s);
|
|
return tool.lines();
|
|
}
|
|
|
|
// ADR-0124: cellular-v2 provisions a rules-3 genesis under the v4 bundle (schema v34),
|
|
// resolves it again on rerun, and refuses the same region asked for as cellular-v1.
|
|
void cellular_v2_provisioning_uses_the_engulf_bundle() {
|
|
const ServerRegion r{{9762, 1}, fresh("cellular-v2-provision-9762")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit(32, 'f');
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = provision_cellular(r, "9762", "cellular-v2", build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9762 region=1 sequence=0 tick=0"));
|
|
const auto again = provision_cellular(r, "9762", "cellular-v2", build, commit, patch, code);
|
|
CHECK(code == 0 && has(again, "already-provisioned world=9762 region=1 sequence=0 tick=0"));
|
|
const auto older = provision_cellular(r, "9762", "cellular-v1", build, commit, patch, code);
|
|
CHECK(code == 4);
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v4_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
}
|
|
|
|
// ADR-0125: cellular-v3 is the rules-4 budding opening on the v5 bundle.
|
|
void cellular_v3_provisioning_uses_the_budding_bundle() {
|
|
const ServerRegion r{{9766, 1}, fresh("cellular-v3-provision-9766")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit(32, 'b');
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = provision_cellular(r, "9766", "cellular-v3", build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9766 region=1 sequence=0 tick=0"));
|
|
const auto again = provision_cellular(r, "9766", "cellular-v3", build, commit, patch, code);
|
|
CHECK(code == 0 && has(again, "already-provisioned world=9766 region=1 sequence=0 tick=0"));
|
|
const auto older = provision_cellular(r, "9766", "cellular-v2", build, commit, patch, code);
|
|
CHECK(code == 4);
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v5_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
}
|
|
|
|
// ADR-0128: cellular-v4 is the rules-5 presence opening on the v6 bundle.
|
|
void cellular_v4_provisioning_uses_the_presence_bundle() {
|
|
const ServerRegion r{{9769, 1}, fresh("cellular-v4-provision-9769")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit(32, 'd');
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = provision_cellular(r, "9769", "cellular-v4", build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9769 region=1 sequence=0 tick=0"));
|
|
const auto older = provision_cellular(r, "9769", "cellular-v3", build, commit, patch, code);
|
|
CHECK(code == 4);
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v6_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
// 11.9 (ADR-0130): the read-only summary reports account-free aggregates of the head.
|
|
Child summary{{env("EVO_WORLD_CLONE_BIN"), "summary", "--world", "9769", "--region", "1",
|
|
"--pg-host", env("PGHOST"), "--pg-port", env("PGPORT"), "--pg-database",
|
|
env("PGDATABASE"), "--pg-user", env("PGUSER"), "--objects", r.root.string()}};
|
|
CHECK(summary.wait_exit(30s) == 0);
|
|
const auto lines = summary.lines();
|
|
CHECK(has(lines, "cellular summary world=9769 region=1 sequence=0 tick=0") &&
|
|
has(lines, "living owned=0 wildlife=0 lingering=0 suspended=0") &&
|
|
has(lines, "deaths total=0 starved=0 engulfed=0 unrecorded=0 owned=0 wildlife=0") &&
|
|
has(lines, "evolution buds=0 mutations=0 living_genomes=0 deepest_lineage=0"));
|
|
}
|
|
|
|
// 2026-10-15 balance: cellular-v5 is the rules-6 opening on the v7 bundle (schema v41).
|
|
void cellular_v5_provisioning_uses_the_balance_bundle() {
|
|
const ServerRegion r{{9770, 1}, fresh("cellular-v5-provision-9770")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit = "ba1a0ce5c0f7e1d2ba1a0ce5c0f7e1d2"; // Unique to this test.
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = provision_cellular(r, "9770", "cellular-v5", build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9770 region=1 sequence=0 tick=0"));
|
|
// The same genesis resolves again; another opening for the region is refused.
|
|
const auto again = provision_cellular(r, "9770", "cellular-v5", build, commit, patch, code);
|
|
CHECK(code == 0);
|
|
const auto older = provision_cellular(r, "9770", "cellular-v4", build, commit, patch, code);
|
|
CHECK(code == 4);
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v7_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
}
|
|
|
|
// ADR-0137: cellular-v6 is the rules-7 opening on the v8 bundle (schema v42).
|
|
void cellular_v6_provisioning_uses_the_reproduction_bundle() {
|
|
const ServerRegion r{{9773, 1}, fresh("cellular-v6-provision-9773")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit = "b0d5ce5c0f7e1d2ba1a0ce5c0f7e1d2b"; // Unique to this test.
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = provision_cellular(r, "9773", "cellular-v6", build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9773 region=1 sequence=0 tick=0"));
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v8_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
}
|
|
|
|
// ADR-0136 step A: cellular-v7 is the rules-8 opening (pools and bubbles, no square
|
|
// patches) on the v9 bundle (schema v43); a --patch is refused.
|
|
void cellular_v7_provisioning_scatters_bubbles() {
|
|
const ServerRegion r{{9774, 1}, fresh("cellular-v7-provision-9774")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit = "b0b81e5c0f7e1d2ba1a0ce5c0f7e1d2c"; // Unique to this test.
|
|
int code = -1;
|
|
const auto patched = provision_cellular(r, "9774", "cellular-v7", build, commit,
|
|
"3000,3000,2,1000,1000,1000,1000,1000", code);
|
|
CHECK(code != 0);
|
|
const auto first = provision_cellular(r, "9774", "cellular-v7", build, commit,
|
|
"40,1,2000000,50000,20000,0,0", code, "--motes");
|
|
CHECK(code == 0 && has(first, "provisioned world=9774 region=1 sequence=0 tick=0"));
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v9_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
}
|
|
|
|
// ADR-0176: cellular-v8 is the cellular-v7 opening taken through one empty tick and the
|
|
// durable upgrades to bundle 13 with declared light; it is resumable and idempotent.
|
|
void cellular_v8_provisioning_declares_light() {
|
|
const ServerRegion r{{9775, 1}, fresh("cellular-v8-provision-9775")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit = "b0b81e5c0f7e1d2ba1a0ce5c0f7e1d2d"; // Unique to this test.
|
|
int code = -1;
|
|
const auto dark = provision_cellular(r, "9775", "cellular-v8", build, commit,
|
|
"40,1,2000000,50000,20000,0,0", code, "--motes");
|
|
CHECK(code != 0); // cellular-v8 requires --light-pj.
|
|
const auto first =
|
|
provision_cellular(r, "9775", "cellular-v8", build, commit, "40,1,2000000,50000,20000,0,0",
|
|
code, "--motes", {"--light-pj", "40"});
|
|
CHECK(code == 0 && has(first, "provisioned world=9775 region=1 sequence=5 tick=1"));
|
|
const auto again =
|
|
provision_cellular(r, "9775", "cellular-v8", build, commit, "40,1,2000000,50000,20000,0,0",
|
|
code, "--motes", {"--light-pj", "40"});
|
|
CHECK(code == 0 && has(again, "already-provisioned world=9775 region=1 sequence=5 tick=1"));
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v13_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
#ifdef EVO_POSTGRES_M10
|
|
// A player's birth on the provisioned head takes the live server's path: host
|
|
// reservation, session batch builder, host publication.
|
|
using namespace evo::server;
|
|
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);
|
|
};
|
|
CHECK(db->query("INSERT INTO evolution.life_allocators VALUES(9775,1000)", {}, 5s));
|
|
Sha256Digest digest{};
|
|
digest.fill(0xEE);
|
|
const auto start = [&] {
|
|
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 started = std::move(*made);
|
|
CHECK(started->step().ready && started->state());
|
|
return started;
|
|
};
|
|
auto host = start();
|
|
auto runtime = connect();
|
|
CHECK(runtime);
|
|
Uuid account{};
|
|
account[0] = 0x8E;
|
|
account.back() = 0x13;
|
|
const auto original =
|
|
claim_account_control(**runtime, r.key, *host->authority(), account, 1, 1, 20'000ms, 5s);
|
|
CHECK(original);
|
|
const auto requested = host->create_primitive_life(account, original->generation, 5);
|
|
CHECK(requested.result == evo::network::PrimitiveLifeResult::pending &&
|
|
host->queued_births().size() == 1);
|
|
// The server restarts before publishing and the client loses request 5. Claiming
|
|
// control under the new lease epoch cancels the unpublished reservation (schema 17),
|
|
// so the account's new request is not refused for that lost life.
|
|
host->drain();
|
|
host = start();
|
|
CHECK(host->queued_births().empty());
|
|
const auto control =
|
|
claim_account_control(**runtime, r.key, *host->authority(), account, 2, 2, 20'000ms, 5s);
|
|
CHECK(control);
|
|
CHECK(host->query_primitive_life(account, control->generation, 5).result ==
|
|
evo::network::PrimitiveLifeResult::cancelled);
|
|
const auto relogin = host->create_primitive_life(account, control->generation, 6);
|
|
CHECK(relogin.result == evo::network::PrimitiveLifeResult::pending &&
|
|
host->queued_births().size() == 1 && host->queued_births().front().request == 6);
|
|
const std::vector births(host->queued_births().begin(), host->queued_births().end());
|
|
auto builder = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
|
|
CHECK(builder);
|
|
const auto appended =
|
|
builder->append_with_birth_refusals(host->state()->tick() + 1, {}, {}, births, {});
|
|
if (!appended)
|
|
throw std::runtime_error(
|
|
"bundle 13 birth append failed: " + std::to_string(static_cast<int>(appended.error())) +
|
|
" lives " +
|
|
std::to_string(
|
|
builder->last_lives_error() ? static_cast<int>(*builder->last_lives_error()) : -1));
|
|
CHECK(builder->refused_births().empty());
|
|
// Rules 11 replays only the inheritance trace format; the builder must declare it.
|
|
CHECK(builder->batch().format_version == cellular_batch_inheritance_format);
|
|
const auto published =
|
|
host->publish(builder->batch(), builder->actions(), builder->mutation_actions());
|
|
if (!published) {
|
|
const auto& failure = published.error();
|
|
std::string message = "bundle 13 birth publish failed: kind " +
|
|
std::to_string(static_cast<int>(failure.kind));
|
|
if (failure.publication)
|
|
message += " publication " + std::to_string(static_cast<int>(*failure.publication));
|
|
if (failure.store && failure.store->cause.sqlstate[0] != '\0')
|
|
message += " sqlstate " + std::string(failure.store->cause.sqlstate.data(), 5);
|
|
throw std::runtime_error(message);
|
|
}
|
|
CHECK(host->query_primitive_life(account, control->generation, 6).result ==
|
|
evo::network::PrimitiveLifeResult::born);
|
|
// The player's next ordinary session tick publishes too.
|
|
std::vector<CellularLifeIntent> baseline;
|
|
for (const auto& life : host->state()->lives())
|
|
baseline.push_back({life.identity.life, {}});
|
|
std::ranges::sort(baseline, {}, &CellularLifeIntent::life_id);
|
|
auto next = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
|
|
CHECK(next && next->append(host->state()->tick() + 1, baseline, {}));
|
|
CHECK(host->publish(next->batch(), next->actions(), next->mutation_actions()));
|
|
// Every Argo sync reruns the provision hook while the region server holds the lease.
|
|
const auto served =
|
|
provision_cellular(r, "9775", "cellular-v8", build, commit, "40,1,2000000,50000,20000,0,0",
|
|
code, "--motes", {"--light-pj", "40"});
|
|
CHECK(code == 0 && has(served, "already-provisioned world=9775 region=1"));
|
|
#endif
|
|
}
|
|
|
|
// Rules 12 (ADR-0177): cellular-v9 is cellular-v8 followed by the 13 -> 14 liquid upgrade from
|
|
// the Git tuning file, whose region size must match the opening; resumable and idempotent.
|
|
void cellular_v9_provisioning_declares_liquid() {
|
|
const ServerRegion r{{9777, 1}, fresh("cellular-v9-provision-9777")};
|
|
const std::string build(64, 'e');
|
|
const std::string commit = "b0b81e5c0f7e1d2ba1a0ce5c0f7e1d2e"; // Unique to this test.
|
|
const std::string motes = "40,1,2000000,50000,20000,0,0";
|
|
const auto write_tuning = [&](std::uint32_t side) {
|
|
auto parsed = evo::biology::parse_cellular_tuning(
|
|
"tuning.version = 1\nregion.width_um = 60000\nregion.height_um = 60000\n"
|
|
"region.organism_cap = 2000\nregion.deposit_limit = 8192\n"
|
|
"region.perception_radius_um = 5000\nfounder.thrust_um_per_s2 = 400\n"
|
|
"founder.reverse_thrust_um_per_s2 = 400\nfounder.drag_ppm_per_tick = 95163\n"
|
|
"founder.lateral_drag_ppm_per_tick = 95163\nfounder.turn_heading_per_s = 65536\n"
|
|
"currents.min_count = 2\ncurrents.max_count = 4\ncurrents.min_width_um = 3000\n"
|
|
"currents.max_width_um = 6000\ncurrents.min_speed_um_per_s = 60\n"
|
|
"currents.max_speed_um_per_s = 300\ncurrents.grid_pitch_um = 250\n"
|
|
"food.merged_bubble_cap_multiple = 8\nfood.visible_moving_bubbles = 256\n"
|
|
"food.induced_drift_radius_um = 200\nfood.induced_drift_max_um_per_s = 100\n"
|
|
"food.induced_drift_decay_ppm_per_tick = 95163\nthermal.ambient_min_mk = 278150\n"
|
|
"thermal.ambient_max_mk = 313150\nfounder.preferred_mk = 293150\n"
|
|
"founder.comfort_band_mk = 5000\nfounder.body_tau_ms = 20000\n"
|
|
"founder.lethal_cold_mk = 273150\nfounder.lethal_heat_mk = 318150\n"
|
|
"thermal.off_preference_per_mille_per_k = 80\n"
|
|
"thermal.transition_per_mille_per_k = 40\nthermal.multiplier_cap_per_mille = 8000\n"
|
|
"lifecycle.logout_delay_ms = 10000\nmutation.step_points = 5\n"
|
|
"mutation.paired_points = 2\nmutation.recovery_floor_per_mille = 100\n"
|
|
"mutation.offer_interval_ms = 25000\nmutation.offer_options = 3\n");
|
|
CHECK(parsed);
|
|
parsed->region_width_um = parsed->region_height_um = side;
|
|
const auto path = r.root / ("cellular-" + std::to_string(side) + ".tuning");
|
|
std::ofstream{path, std::ios::binary} << evo::biology::encode_cellular_tuning(*parsed);
|
|
return path.string();
|
|
};
|
|
int code = -1;
|
|
provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code, "--motes",
|
|
{"--light-pj", "40"});
|
|
CHECK(code != 0); // cellular-v9 requires --tuning.
|
|
provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code, "--motes",
|
|
{"--light-pj", "40", "--tuning", write_tuning(20'000)});
|
|
CHECK(code != 0); // The tuning region size must match the opening's.
|
|
const auto tuning = write_tuning(10'000);
|
|
const auto first = provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code,
|
|
"--motes", {"--light-pj", "40", "--tuning", tuning});
|
|
CHECK(code == 0 && has(first, "provisioned world=9777 region=1 sequence=6 tick=1"));
|
|
const auto again = provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code,
|
|
"--motes", {"--light-pj", "40", "--tuning", tuning});
|
|
CHECK(code == 0 && has(again, "already-provisioned world=9777 region=1 sequence=6 tick=1"));
|
|
auto db = owner();
|
|
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
|
CHECK(head);
|
|
const auto manifest = decode_manifest(head->manifest);
|
|
CHECK(manifest && manifest->cellular_versions == cellular_v14_versions &&
|
|
manifest->history_profile == cellular_revision_history_profile);
|
|
#ifdef EVO_POSTGRES_M10
|
|
// A player is born on the liquid head and swims and brakes through the live server path:
|
|
// host reservation, session batch builder, host publication with a braking trace.
|
|
using namespace evo::server;
|
|
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);
|
|
};
|
|
CHECK(db->query("INSERT INTO evolution.life_allocators VALUES(9777,1000)", {}, 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 && host->state() &&
|
|
host->state()->rules_version() == cellular_lives_liquid_rules &&
|
|
host->state()->flow_field() != nullptr);
|
|
auto runtime = connect();
|
|
CHECK(runtime);
|
|
Uuid account{};
|
|
account[0] = 0x9E;
|
|
account.back() = 0x14;
|
|
const auto control =
|
|
claim_account_control(**runtime, r.key, *host->authority(), account, 1, 1, 20'000ms, 5s);
|
|
CHECK(control);
|
|
CHECK(host->create_primitive_life(account, control->generation, 5).result ==
|
|
evo::network::PrimitiveLifeResult::pending);
|
|
const std::vector births(host->queued_births().begin(), host->queued_births().end());
|
|
auto builder = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
|
|
CHECK(builder);
|
|
CHECK(builder->append_with_birth_refusals(host->state()->tick() + 1, {}, {}, births, {}));
|
|
CHECK(builder->refused_births().empty() &&
|
|
builder->batch().format_version == cellular_batch_inheritance_format);
|
|
CHECK(host->publish(builder->batch(), builder->actions(), builder->mutation_actions()));
|
|
CHECK(host->query_primitive_life(account, control->generation, 5).result ==
|
|
evo::network::PrimitiveLifeResult::born);
|
|
// Ticks of swimming then braking publish and leave the founder in motion state.
|
|
for (int tick = 0; tick < 6; ++tick) {
|
|
std::vector<CellularLifeIntent> intents;
|
|
for (const auto& life : host->state()->lives()) {
|
|
CellularLifeIntent intent{life.identity.life, {}};
|
|
intent.intent.movement = {1'000, 0};
|
|
intent.intent.brake = tick >= 4;
|
|
intents.push_back(intent);
|
|
}
|
|
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
|
|
auto next = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
|
|
CHECK(next && next->append(host->state()->tick() + 1, intents, {}));
|
|
CHECK(host->publish(next->batch(), next->actions(), next->mutation_actions()));
|
|
}
|
|
CHECK(host->state()->lives().front().identity.genome != 0);
|
|
const auto genome =
|
|
host->state()->archive().find(host->state()->lives().front().identity.genome);
|
|
CHECK(genome && genome->schema_version() == evo::biology::genome_schema_v6);
|
|
#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,
|
|
const std::string& patch, int& code) {
|
|
return provision_cellular(r, "9761", "cellular-v1", build, commit, patch, code);
|
|
};
|
|
const std::string first_build(64, 'c');
|
|
const std::string second_build = std::string(63, 'c') + "d";
|
|
const std::string commit(32, 'a');
|
|
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
|
int code = -1;
|
|
const auto first = run(first_build, commit, patch, code);
|
|
CHECK(code == 0 && has(first, "provisioned world=9761 region=1 sequence=0 tick=0"));
|
|
const auto promoted = run(second_build, commit, patch, code);
|
|
CHECK(code == 0 && has(promoted, "already-provisioned world=9761 region=1 sequence=0 tick=0"));
|
|
const auto other_commit = run(second_build, std::string(32, 'b'), patch, code);
|
|
CHECK(code == 4 && has(other_commit, "provision refused existing cellular region; use its "
|
|
"original --commit to resolve genesis"));
|
|
const auto other_opening =
|
|
run(second_build, commit, "4000,4000,2,1000,1000,1000,1000,1000", code);
|
|
CHECK(code == 4 && has(other_opening, "provision refused existing cellular region; use its "
|
|
"original --commit to resolve genesis"));
|
|
}
|
|
} // namespace
|
|
|
|
void run_region_store_tests() {
|
|
provisioning_is_idempotent();
|
|
primitive_provisioning_is_explicit_and_profile_safe();
|
|
provisioning_creates_the_life_allocator_once();
|
|
cellular_provisioning_survives_a_build_promotion();
|
|
cellular_v2_provisioning_uses_the_engulf_bundle();
|
|
cellular_v3_provisioning_uses_the_budding_bundle();
|
|
cellular_v4_provisioning_uses_the_presence_bundle();
|
|
cellular_v5_provisioning_uses_the_balance_bundle();
|
|
cellular_v6_provisioning_uses_the_reproduction_bundle();
|
|
cellular_v7_provisioning_scatters_bubbles();
|
|
cellular_v8_provisioning_declares_light();
|
|
cellular_v9_provisioning_declares_liquid();
|
|
#ifdef EVO_POSTGRES_M10
|
|
cellular_v8_player_chooses_a_mutation();
|
|
#endif
|
|
full_volumes_publish_nothing();
|
|
failing_writes_leave_nothing();
|
|
check_store_qualifies_the_stores();
|
|
full_volume_server_acknowledges_nothing();
|
|
}
|