feat(lifecycle): rules 13 owner on format 11 with the revamp tuning file
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (checks) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 3s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m30s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m12s
Foundation / image (push) Successful in 4m40s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (checks) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 3s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m30s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m12s
Foundation / image (push) Successful in 4m40s
Phase 1 of the cellular revamp build plan (ADR-0179). The cellular owner gains rules 13 on owner format 11: an explicit no-tick format-10/rules-12 upgrade declares the region's revamp rules (so far the body's essential upkeep share), existing lives keep their genomes, and founders born afterwards are founder 6 (genome schema 7, development 7). Format 11 is format 10 plus the revamp rules block; it stays undeployed while later phases extend it. The tick, perception and wildlife controller derive budgets with the declared body tuning, which earlier development versions ignore. Revamp tunables live in their own Git file, deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning, parsed by parse_cellular_revamp_tuning with the same format and refusals as the rules-12 file, so images from before rules 13 never meet keys they do not know. Both parsers now share read_tuning_lines; the rules-12 file's behaviour is unchanged. The revamp file is not yet mounted into the region (build plan, phase 6). Tests cover the upgrade and its refusals, mixed founder 5 and founder 6 lives ticking with closure, exact restore and continuation, trace replay, and the new tuning file including the checked-in DEV copy. Refreshes the DEV session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#include "evo/server/lifecycle/cellular_batch.hpp"
|
||||
#include "fixtures/cellular_ecology.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
// Rules 13 owner (Cellular_Revamp_Build_Plan.md phase 1, ADR-0179): the format 10 -> 11 upgrade,
|
||||
// founder 6 births, the declared revamp rules and exact restore and replay.
|
||||
namespace {
|
||||
using namespace evo;
|
||||
using namespace evo::server;
|
||||
using namespace evo::fixture;
|
||||
|
||||
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}};
|
||||
}
|
||||
|
||||
CellularRevampRules revamp(std::uint32_t essential = 250) {
|
||||
return {.body = {.essential_upkeep_per_thousand = essential}};
|
||||
}
|
||||
|
||||
LifeAccount account(std::uint8_t last) {
|
||||
LifeAccount value{};
|
||||
value.back() = last;
|
||||
return value;
|
||||
}
|
||||
|
||||
// A rules-13 region with a founder 5 born before the upgrade and a founder 6 born after it.
|
||||
Owner revamp_region(std::uint32_t essential = 250) {
|
||||
auto state = opening(7, true, 2, false); // Funds two founders.
|
||||
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");
|
||||
require(!state->revamp_upgrade_candidate(revamp()), "revamp upgrade skipped rules 12");
|
||||
state = checked(state->liquid_upgrade_candidate(liquid()), "liquid upgrade");
|
||||
state = checked(state->birth_candidate({account(1), 1}, {100, 100, 100, 100, {state->tick()}}),
|
||||
"founder 5 birth");
|
||||
require(!state->revamp_upgrade_candidate(revamp(1'001)), "an invalid essential share accepted");
|
||||
state = checked(state->revamp_upgrade_candidate(revamp(essential)), "revamp upgrade");
|
||||
require(state->format_version() == cellular_lives_revamp_format &&
|
||||
state->rules_version() == cellular_lives_revamp_rules &&
|
||||
state->revamp_rules() == revamp(essential) && state->liquid_rules() == liquid() &&
|
||||
state->flow_field() != nullptr && !state->revamp_upgrade_candidate(revamp()),
|
||||
"revamp upgrade repeated, wrong versions or lost rules");
|
||||
state = checked(state->birth_candidate({account(2), 1}, {101, 101, 101, 101, {state->tick()}}),
|
||||
"founder 6 birth");
|
||||
const auto old = state->archive().find(100);
|
||||
const auto fresh = state->archive().find(101);
|
||||
require(old && old->schema_version() == biology::genome_schema_v6,
|
||||
"the founder 5 life lost its genome in the upgrade");
|
||||
require(fresh && fresh->schema_version() == biology::genome_schema_v7 &&
|
||||
fresh->development_version() == 7 &&
|
||||
fresh->cellular_traits() == biology::founder_cellular_traits,
|
||||
"a rules-13 founder is not founder 6");
|
||||
return state;
|
||||
}
|
||||
|
||||
std::vector<CellularLifeIntent> swim(const CellularLives& state, biology::CellularIntent movement) {
|
||||
std::vector<CellularLifeIntent> result;
|
||||
for (const auto& life : state.lives()) {
|
||||
CellularLifeIntent input{life.identity.life, {}};
|
||||
input.intent.movement = movement;
|
||||
result.push_back(input);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void closed(const CellularLives& state) {
|
||||
const auto& ledger = state.boundary_ledger();
|
||||
auto expected = state.opening_total();
|
||||
expected.energy.value += ledger.incoming.energy.value - ledger.outgoing.energy.value;
|
||||
for (std::size_t channel = 0; channel < expected.matter.size(); ++channel)
|
||||
expected.matter[channel].value +=
|
||||
ledger.incoming.matter[channel].value - ledger.outgoing.matter[channel].value;
|
||||
require(state.current_total() == expected, "revamp region broke closure");
|
||||
}
|
||||
|
||||
void upgrade_and_restore() {
|
||||
const auto state = revamp_region(400);
|
||||
const auto copy = restore(*state);
|
||||
require(copy->snapshot() == state->snapshot() && copy->revamp_rules() == revamp(400) &&
|
||||
copy->liquid_rules() == liquid(),
|
||||
"format 11 did not restore exactly");
|
||||
// A tampered rules block is refused rather than read as another share.
|
||||
auto bytes = state->snapshot();
|
||||
require(bytes.size() > 8, "empty snapshot");
|
||||
bytes[8] = 10; // Format field: format 10 bytes with the format 11 magic.
|
||||
require(!CellularLives::restore(bytes, state->world(), state->region(), state->frame(),
|
||||
state->tick()),
|
||||
"a format 11 checkpoint restored as format 10");
|
||||
}
|
||||
|
||||
// Both generations live and pay their way in one region, and restore continues exactly.
|
||||
void mixed_generations_tick_and_continue() {
|
||||
auto continuous = revamp_region();
|
||||
for (int tick = 0; tick < 30; ++tick)
|
||||
checked(continuous->advance_tick(swim(*continuous, {600, 800})), "continuous tick");
|
||||
require(continuous->lives().size() == 2, "a life died in thirty ticks");
|
||||
closed(*continuous);
|
||||
auto resumed = restore(*continuous);
|
||||
for (int tick = 0; tick < 30; ++tick) {
|
||||
checked(continuous->advance_tick(swim(*continuous, {-700, 300})), "continuous tick");
|
||||
checked(resumed->advance_tick(swim(*resumed, {-700, 300})), "resumed tick");
|
||||
}
|
||||
require(continuous->snapshot() == resumed->snapshot(), "restore diverged from a live run");
|
||||
closed(*continuous);
|
||||
}
|
||||
|
||||
// A recorded trace replays to the exact live result under rules 13.
|
||||
void trace_replays() {
|
||||
auto live = revamp_region();
|
||||
const auto base = restore(*live);
|
||||
CellularBatch batch;
|
||||
batch.format_version = cellular_batch_inheritance_format;
|
||||
batch.header = {live->world(), live->region(), live->frame(), {}, {}, live->tick(), 0};
|
||||
batch.header.predecessor.fill(1);
|
||||
batch.header.predecessor_digest.fill(2);
|
||||
for (int tick = 0; tick < 24; ++tick) {
|
||||
const auto intents = swim(*live, {static_cast<std::int16_t>(tick < 12 ? 1'000 : -400), 0});
|
||||
checked(live->advance_tick(intents), "recorded tick");
|
||||
batch.ticks.push_back({intents, {}, {}});
|
||||
}
|
||||
batch.header.end_tick = live->tick();
|
||||
const auto bytes = checked(encode_cellular_batch(batch), "trace encodes");
|
||||
const auto decoded = checked(decode_cellular_batch(bytes), "trace decodes");
|
||||
const auto replayed = checked(replay_cellular_batch(*base, decoded), "trace replays");
|
||||
require(replayed->snapshot() == live->snapshot(), "replay diverged from the live run");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
upgrade_and_restore();
|
||||
mixed_generations_tick_and_continue();
|
||||
trace_replays();
|
||||
std::puts("PASS rules 13 owner: upgrade, founder 6, restore and replay");
|
||||
return 0;
|
||||
} catch (...) {
|
||||
std::puts("FAIL rules 13 owner");
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "evo/biology/cellular_revamp_tuning.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
// The rules-13 revamp tuning file (ADR-0179): same format and refusals as the rules-12 file,
|
||||
// with its own keys.
|
||||
namespace {
|
||||
using namespace evo::biology;
|
||||
void check(bool condition, std::source_location at = std::source_location::current()) {
|
||||
if (!condition)
|
||||
throw std::runtime_error("cellular revamp tuning line " + std::to_string(at.line()));
|
||||
}
|
||||
#define CHECK(expression) check(static_cast<bool>(expression))
|
||||
|
||||
CellularRevampTuning trial() {
|
||||
return {.version = 1, .body_essential_upkeep_per_mille = 250};
|
||||
}
|
||||
|
||||
std::string with(std::string text, const std::string& key, const std::string& value) {
|
||||
const auto at = text.find(key + " = ");
|
||||
check(at != std::string::npos);
|
||||
const auto end = text.find('\n', at);
|
||||
return text.replace(at, end - at, key + " = " + value);
|
||||
}
|
||||
|
||||
CellularTuningErrorKind error_of(const std::string& text) {
|
||||
const auto parsed = parse_cellular_revamp_tuning(text);
|
||||
check(!parsed.has_value());
|
||||
return parsed.error().kind;
|
||||
}
|
||||
|
||||
void canonical_round_trip() {
|
||||
const auto text = encode_cellular_revamp_tuning(trial());
|
||||
const auto parsed = parse_cellular_revamp_tuning(text);
|
||||
CHECK(parsed && *parsed == trial());
|
||||
CHECK(encode_cellular_revamp_tuning(*parsed) == text);
|
||||
const auto commented =
|
||||
"# heading\n\n" + with(text, "body.essential_upkeep_per_mille", "2_50 # c");
|
||||
CHECK(parse_cellular_revamp_tuning(commented) == trial());
|
||||
}
|
||||
|
||||
void refusals() {
|
||||
const auto base = encode_cellular_revamp_tuning(trial());
|
||||
CHECK(error_of(base + "unknown.key = 1\n") == CellularTuningErrorKind::unknown_key);
|
||||
CHECK(error_of(base + "tuning.version = 1\n") == CellularTuningErrorKind::duplicate_key);
|
||||
CHECK(error_of(base + "no equals sign\n") == CellularTuningErrorKind::syntax);
|
||||
CHECK(error_of(with(base, "body.essential_upkeep_per_mille", "1001")) ==
|
||||
CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "body.essential_upkeep_per_mille", "x")) ==
|
||||
CellularTuningErrorKind::invalid_value);
|
||||
CHECK(error_of(with(base, "tuning.version", "2")) ==
|
||||
CellularTuningErrorKind::unsupported_version);
|
||||
auto missing = base;
|
||||
missing.erase(missing.find("body.essential_upkeep_per_mille"));
|
||||
const auto parsed = parse_cellular_revamp_tuning(missing);
|
||||
CHECK(!parsed && parsed.error().kind == CellularTuningErrorKind::missing_key &&
|
||||
parsed.error().key == "body.essential_upkeep_per_mille");
|
||||
// Rules-12 keys belong in the other file.
|
||||
CHECK(error_of(base + "region.width_um = 60000\n") == CellularTuningErrorKind::unknown_key);
|
||||
CHECK(error_of(std::string(max_cellular_revamp_tuning_bytes + 1, '#')) ==
|
||||
CellularTuningErrorKind::too_large);
|
||||
}
|
||||
|
||||
// The checked-in DEV revamp tuning file must parse; CTest passes its path when it is present.
|
||||
void repository_file(const char* path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
CHECK(file.good());
|
||||
const std::string text{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
const auto parsed = parse_cellular_revamp_tuning(text);
|
||||
if (!parsed)
|
||||
std::fprintf(stderr, "%s: line %zu %s: %s\n", path, parsed.error().line,
|
||||
parsed.error().key.c_str(),
|
||||
std::string{describe(parsed.error().kind)}.c_str());
|
||||
CHECK(parsed && *parsed == trial());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
canonical_round_trip();
|
||||
refusals();
|
||||
if (argc > 1)
|
||||
repository_file(argv[1]);
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
}
|
||||
std::puts("PASS cellular revamp tuning file");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user