Implement M7.4a checkpoint publication and verified recovery
ADR-0061 publishes environmental-v1 full checkpoints. Manifest v1 is a fixed 280-byte record (identity, chain, lease, versions, build, zero RNG/history declarations, durability policy, payload length/SHA-256) that PostgreSQL parses and digests itself. Schema v3 adds region_commits with a digest CHECK and a composite head FK, owner-managed retained builds, fenced publish/load functions and owner-only genesis; it drops the bare v2 head kernel and fails closed while v2 heads exist. Linux evo::region_store adds OpenSSL SHA-256, an immutable content-addressed filesystem object store (temp+fsync+link, no overwrite/delete, O_NOFOLLOW exact-length verified reads), and publication (validate -> upload -> read back -> fenced transaction -> receipt check) and recovery (re-digest, allowlist, verify, full restore). Portable evo::region_checkpoint holds the codec and payload validation. Validated: Windows CTest 56/56; WSL Release, clang-tidy and ASan/UBSan private-PostgreSQL suites; four SQL and one host mutation each caught. M7.4 stays open for 7.4b (lineage archive codec and history binding). No Docker/Gitea CI, remote store, process kill or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+84
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
// Rules-2 environmental community used by region checkpoint tests (M7.4).
|
||||
#include "evo/processes/environmental_community.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");
|
||||
}
|
||||
}
|
||||
} // namespace evo::test
|
||||
Reference in New Issue
Block a user