Files
aevolution/tests/environment_checkpoint_tests.cpp
T
dingoandClaude Opus 5.5 51991ac7ff
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (deploy) (push) Successful in 4m51s
Foundation / checks (network) (push) Successful in 20m42s
Foundation / checks (client) (push) Successful in 21m53s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 40m19s
Foundation / checks (postgres) (push) Canceled after 40m9s
Foundation / checks (tsan) (push) Canceled after 37m53s
feat(persistence): admit durable cellular environment profile
ADR-0174 and schema 56 add checkpoint profile 6, which stores the joint
cell/environment envelope nesting population envelope 2 (bundles 10 and
11). Entry from a committed population head is explicit, one-way and
no-tick, with the source commit, manifest and payload digests bound in
immutable evidence. Joint intervals use schema 45's owned admission and
settlement; conversions cannot overtake a pending interval. The fenced
publisher validates the joint trace structurally, including the complete
nested population batch, and records per-commit imported and radiated
totals. Recovery replays the head's link and requires the payload
exactly, refusing a forged but structurally valid trace. A trigger
refuses profile-6 commits from every other publisher; profile 4/5 bytes,
parsers and rules are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:16:50 -04:00

170 lines
8.9 KiB
C++

#include "evo/persistence/region_checkpoint.hpp"
#include "fixtures/cellular_ecology.hpp"
namespace {
using namespace evo;
using namespace evo::server;
using namespace evo::persistence;
using namespace evo::fixture;
template <std::size_t N> std::array<std::uint8_t, N> filled(std::uint8_t byte) {
std::array<std::uint8_t, N> out{};
out.fill(byte);
return out;
}
std::unique_ptr<CellularEnvironment> joint() {
auto state = opening(7, true);
state = checked(state->migration_upgrade_candidate(), "boundary upgrade");
state = checked(state->maturation_upgrade_candidate(), "maturation upgrade");
auto population =
checked(CellularPopulation::create(std::move(state), {false, 900, 1'600}), "population");
CellularEnvironmentConfig config;
config.geometry.box = {{0}, {0}, {0}, {6'000}, {6'000}, {10}};
CellularInfallSource source;
source.id = 1;
source.width_um = 6'000;
source.height_um = 6'000;
source.start_tick = 1;
source.end_tick = ~std::uint64_t{0};
source.mean_interval_ticks = 20;
source.per_bubble.energy.value = 1'000;
source.entitlement.energy.value = 1'000'000;
config.sources.push_back(source);
config.radiation_cap = {5};
return checked(CellularEnvironment::create(std::move(population), std::move(config)), "joint");
}
// A committed profile-5 head at the joint fixture's cut (bundle 11, population envelope 2).
CheckpointManifest population_head(const CellularEnvironment& state) {
CheckpointManifest m;
m.profile = CheckpointProfile::cellular_population_v1;
m.key = {state.state().world(), state.state().region()};
m.frame = state.state().frame();
m.commit = filled<16>(3);
m.sequence = 4;
m.predecessor_commit = filled<16>(2);
m.predecessor_digest = filled<32>(5);
m.begin_tick = state.tick();
m.end_tick = state.tick();
m.holder = filled<16>(6);
m.epoch = 2;
m.tick_microseconds = 50'000;
m.versions = environmental_v1_versions;
m.cellular_versions = cellular_v11_versions;
m.build = filled<32>(7);
m.history_profile = population_history_profile;
const auto bytes = state.population().snapshot();
m.payload_bytes = bytes.size();
m.payload_sha256 = filled<32>(8);
return m;
}
} // namespace
int main() {
try {
auto state = joint();
const auto head = population_head(*state);
require(encode_manifest(head) && supported(head), "profile-5 fixture head");
const LeaseGrant lease{filled<16>(9), 3, head.frame, {}};
const auto payload = state->snapshot();
const auto transition = checked(
environment_profile_transition_manifest(head, filled<32>(10), filled<16>(11), lease,
filled<32>(12), payload.size(), filled<32>(13)),
"profile transition");
require(transition.profile == CheckpointProfile::cellular_environment_v1 &&
transition.history_profile == environment_history_profile &&
transition.cellular_versions == cellular_v11_versions &&
transition.begin_tick == transition.end_tick &&
transition.batch == BatchDigests{} &&
transition.sequence == head.sequence + 1 && supported(transition),
"transition changed bundle, tick or evidence");
const auto encoded = checked(encode_manifest(transition), "encode transition");
require(checked(decode_manifest(encoded), "decode transition") == transition,
"transition manifest round trip");
const auto restored =
checked(restore_environment_payload(payload, transition), "restore joint payload");
require(restored->snapshot() == payload, "joint payload restore changed bytes");
// Only a profile-5 owner-7 predecessor converts; there is no reverse transition.
require(!environment_profile_transition_manifest(transition, filled<32>(10), filled<16>(14),
lease, filled<32>(12), payload.size(),
filled<32>(13)),
"joint profile re-entered its own transition");
auto raw = head;
raw.profile = CheckpointProfile::cellular_lives_v1;
raw.history_profile = cellular_revision_history_profile;
require(!environment_profile_transition_manifest(raw, filled<32>(10), filled<16>(11), lease,
filled<32>(12), payload.size(),
filled<32>(13)),
"raw profile skipped the population profile");
auto old = head;
old.cellular_versions = cellular_v9_versions;
require(!environment_profile_transition_manifest(old, filled<32>(10), filled<16>(11), lease,
filled<32>(12), payload.size(),
filled<32>(13)),
"population envelope 1 entered the joint profile");
auto wrong_lease = lease;
wrong_lease.frame += 1;
require(!environment_profile_transition_manifest(head, filled<32>(10), filled<16>(11),
wrong_lease, filled<32>(12),
payload.size(), filled<32>(13)),
"transition under another frame's lease");
const BatchDigests batch{server::environment_batch_header_bytes +
server::population_batch_header_bytes + 16 + 48,
filled<32>(15),
0,
{}};
const auto next =
checked(environment_successor_manifest(transition, filled<32>(16), filled<16>(17),
lease, transition.end_tick + 1, filled<32>(12),
payload.size(), filled<32>(18), batch),
"joint successor");
require(next.profile == transition.profile && next.batch == batch &&
next.begin_tick == transition.end_tick && supported(next),
"joint successor changed profile or evidence");
const auto conversion =
checked(environment_successor_manifest(transition, filled<32>(16), filled<16>(17),
lease, transition.end_tick, filled<32>(12),
payload.size(), filled<32>(18), batch),
"joint conversion");
require(conversion.begin_tick == conversion.end_tick, "conversion advanced its tick");
require(!environment_successor_manifest(transition, filled<32>(16), filled<16>(17), lease,
transition.end_tick + 1, filled<32>(12),
payload.size(), filled<32>(18), {}),
"joint successor without a trace");
require(!environment_successor_manifest(transition, filled<32>(16), filled<16>(17), lease,
transition.end_tick + 65, filled<32>(12),
payload.size(), filled<32>(18), batch),
"joint interval above 64 ticks");
require(!environment_successor_manifest(head, filled<32>(16), filled<16>(17), lease,
head.end_tick + 1, filled<32>(12), payload.size(),
filled<32>(18), batch),
"population head published a joint successor");
auto history = transition;
history.history_profile = population_history_profile;
require(!encode_manifest(history) && !supported(history), "joint history 5 accepted");
auto bundle12 = transition;
bundle12.cellular_versions = cellular_v12_versions;
require(!supported(bundle12), "joint profile admitted bundle 12");
auto genesis = transition;
genesis.sequence = 0;
require(!encode_manifest(genesis), "joint profile provisioned without a source");
auto later = transition;
later.end_tick += 1;
later.begin_tick = later.end_tick;
require(!restore_environment_payload(payload, later), "payload restored at another tick");
require(!restore_environment_payload(state->population().snapshot(), transition),
"bare population restored as a joint result");
auto unsupported = transition;
unsupported.cellular_versions = cellular_v10_versions;
require(restore_environment_payload(payload, unsupported).error() ==
CheckpointError::unsupported,
"rules mismatch accepted");
std::cout << "environment checkpoint contracts passed\n";
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}