ADR-0062 adds a canonical LineageArchive codec (parents before children, organisms by id, FNV) that decodes by replaying admit/record_birth/ record_death and requires byte-identical re-encoding; it never overwrites an existing archive. LineageRegion binds the environmental producer and consumer accounts to archived organisms with identity high-waters, enforces closure (lifecycle vs deaths, exact living set, tick bounds) and records deaths in the tick that causes them. Checkpoint profile 2 (environmental-lineage-v1, history profile 1) publishes that container; schema v4 admits it with a 4,268,144-byte cap and requires each commit to keep its predecessor's profile, RNG, history and durability declarations. Linux adds provision/publish/recover for the profile on the shared publication path. Qualification found WSL2 stepping CLOCK_REALTIME back ~0.5 s every ~32 s, which made two 1 s-lease tests flaky under ASan. Tests now wait on database-time expiry; ADR-0060 records the slewed-clock requirement. Validated: Windows CTest 57/57; Linux GCC Debug/Release, clang-tidy and ASan/UBSan CTest 57/57 each; PostgreSQL suites 2x Release, 2x analysis, 5x ASan; SQL and C++ mutations each caught. No Docker/Gitea CI, remote store, process kill or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
5.2 KiB
C++
127 lines
5.2 KiB
C++
#pragma once
|
|
// Rules-2 environmental community used by region checkpoint tests (M7.4).
|
|
#include "evo/processes/environmental_community.hpp"
|
|
#include "evo/processes/lineage_region.hpp"
|
|
#include <array>
|
|
#include <limits>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
|
|
namespace evo::test {
|
|
inline constexpr world::WorldIdentity region_identity{7, 9};
|
|
|
|
inline void require(bool ok, const char* what) {
|
|
if (!ok)
|
|
throw std::runtime_error(what);
|
|
}
|
|
inline processes::EnvironmentalConfig region_config() {
|
|
processes::EnvironmentalConfig c;
|
|
c.rules = 2;
|
|
c.world = region_identity.world;
|
|
c.frame = region_identity.frame;
|
|
c.producer = 1;
|
|
c.consumer = 2;
|
|
c.source = 3;
|
|
c.tick_microseconds = 50000;
|
|
c.area_um2 = 1;
|
|
c.irradiance_numerator = 11;
|
|
c.irradiance_denominator = 3;
|
|
c.efficiency = 600;
|
|
c.growth_numerator = 3;
|
|
c.growth_denominator = 2;
|
|
c.growth_cost = 1;
|
|
c.recipe = {1, 2, 1, 1, 1};
|
|
c.intake.fill(100);
|
|
c.assimilation = 1000;
|
|
c.producer_min_mK = c.consumer_min_mK = 270000;
|
|
c.producer_max_mK = c.consumer_max_mK = 310000;
|
|
c.decay.fill(1);
|
|
return c;
|
|
}
|
|
inline std::unique_ptr<processes::EnvironmentalCommunity> region_community() {
|
|
using namespace world;
|
|
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
|
std::array<std::uint64_t, 10> environment{200, 6, 6, 400, 0, 0, 200, 0, 2000, 0};
|
|
const FieldSite site{{0, 0, -16000}, {{0}, {0}, {0}, {10}, {20}, {3}}, {1}};
|
|
std::array<FieldOpening, 10> opening{};
|
|
for (std::size_t k = 0; k < 10; ++k)
|
|
opening[k] = {static_cast<Field>(k), {&environment[k], 1}};
|
|
const FieldDefaults defaults{
|
|
{accounting::Femtograms{0}, accounting::Femtograms{maximum}, accounting::Femtograms{0}}};
|
|
auto f = FieldStore::create(region_identity, 1, defaults, {&site, 1}, opening, 2000000);
|
|
require(f.has_value(), "field store");
|
|
auto t = ChunkStore::create({}, 1, 2000000, {{VolumeUnits{100}, VolumeUnits{100}}});
|
|
require(t.has_value(), "chunk store");
|
|
require((*t)->load({0, 0, -1000}).has_value(), "chunk load");
|
|
std::array<OrganismResources, 2> accounts{};
|
|
accounts[0].id = {1};
|
|
accounts[1].id = {2};
|
|
accounts[0].capacities.fill(100000000);
|
|
accounts[1].capacities.fill(100000000);
|
|
auto r = EnvironmentalTransfers::create(region_identity, std::move(*f), std::move(*t), accounts,
|
|
4000000);
|
|
require(r.has_value(), "transfers");
|
|
auto o = processes::EnvironmentalCommunity::create(region_config(), std::move(*r), 8000000);
|
|
require(o.has_value(), "community");
|
|
return std::move(*o);
|
|
}
|
|
// Deterministic input for tick t; the consumer dies at tick 20 when requested.
|
|
inline processes::EnvironmentalInput region_input(std::uint64_t tick, bool consumer_dies = false) {
|
|
processes::EnvironmentalInput in;
|
|
in.temperature_mK = 290000;
|
|
in.source_enabled = tick % 7 == 0 ? 0 : 1;
|
|
if (tick == 16)
|
|
in.bite = {2, 2, 2, 2, 1};
|
|
if (consumer_dies && tick == 20)
|
|
in.terminal[1] = 1;
|
|
return in;
|
|
}
|
|
inline void advance_region(processes::EnvironmentalCommunity& o, std::uint64_t ticks) {
|
|
for (std::uint64_t i = 0; i < ticks; ++i) {
|
|
const auto tick = o.progress().tick + 1;
|
|
require(o.advance(tick, region_input(tick)).has_value(), "advance");
|
|
}
|
|
}
|
|
|
|
// History-capable fixture: founder genome 1 and descendant 2; a long-dead organism
|
|
// 5 (genome 1); producer organism 10 (genome 1) and consumer 11 (genome 2).
|
|
inline biology::Genome region_genome(std::uint64_t id, std::uint64_t parent) {
|
|
biology::GenomeDraft draft;
|
|
draft.id = id;
|
|
draft.origin_event = id;
|
|
draft.development_version = 1;
|
|
if (parent != 0)
|
|
draft.parents = {parent};
|
|
draft.capabilities = {{biology::Capability::energy_conversion, 400, 0},
|
|
{biology::Capability::membrane, 120, 0},
|
|
{biology::Capability::target_size, 8'000'000, 0}};
|
|
auto genome = biology::Genome::create(draft);
|
|
require(genome.has_value(), "genome");
|
|
return *genome;
|
|
}
|
|
inline biology::LineageArchive region_archive() {
|
|
biology::LineageArchive archive;
|
|
require(archive.admit(region_genome(1, 0)).has_value(), "admit 1");
|
|
require(archive.admit(region_genome(2, 1)).has_value(), "admit 2");
|
|
require(archive.record_birth(5, 1, Tick{0}).has_value(), "birth 5");
|
|
require(archive.record_death(5, Tick{0}).has_value(), "death 5");
|
|
require(archive.record_birth(10, 1, Tick{0}).has_value(), "birth 10");
|
|
require(archive.record_birth(11, 2, Tick{0}).has_value(), "birth 11");
|
|
return archive;
|
|
}
|
|
inline constexpr processes::LineageBinding region_binding{10, 11, 12, 3};
|
|
inline std::unique_ptr<processes::LineageRegion> lineage_region() {
|
|
auto region =
|
|
processes::LineageRegion::create(region_community(), region_archive(), region_binding);
|
|
require(region.has_value(), "lineage region");
|
|
return std::move(*region);
|
|
}
|
|
inline void advance_lineage(processes::LineageRegion& r, std::uint64_t ticks,
|
|
bool consumer_dies = false) {
|
|
for (std::uint64_t i = 0; i < ticks; ++i) {
|
|
const auto tick = r.community().progress().tick + 1;
|
|
require(r.advance(tick, region_input(tick, consumer_dies)).has_value(), "advance lineage");
|
|
}
|
|
}
|
|
} // namespace evo::test
|