M11.1: genome schema 2 with per-second rates (ADR-0099, segment 2)
Foundation / checks (deploy) (push) Successful in 3m32s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 12m56s
Foundation / checks (network) (push) Successful in 13m46s
Foundation / checks (tsan) (push) Successful in 7m59s
Foundation / checks (checks) (push) Successful in 33m36s
Foundation / checks (postgres) (push) Successful in 45m30s
Foundation / postgres-tools (push) Successful in 20s
Foundation / server-image (push) Successful in 25s
Foundation / image (push) Successful in 2m36s
Foundation / checks (deploy) (push) Successful in 3m32s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 12m56s
Foundation / checks (network) (push) Successful in 13m46s
Foundation / checks (tsan) (push) Successful in 7m59s
Foundation / checks (checks) (push) Successful in 33m36s
Foundation / checks (postgres) (push) Successful in 45m30s
Foundation / postgres-tools (push) Successful in 20s
Foundation / server-image (push) Successful in 25s
Foundation / image (push) Successful in 2m36s
Movement and ingestion are stored per second in schema 2 (ranges x20). Schema 1 records stay valid, are never rewritten, and read as exactly x20 via Genome::per_second; drafts default to schema 1 so existing literals keep their meaning. Development version 1 converts genome rates at its own 50 ms quantum (round down), so phenotypes are unchanged. Mutation keeps the parent's schema and step; the lineage archive header names exactly the highest schema held (all-schema-1 archives keep their bytes); the development-v1 opening names schema 1. No golden changed; two tests that used 2 as an unknown schema now use the next one. Refresh the dev session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,6 +117,30 @@ void capability_prerequisites() {
|
||||
CHECK(with->maintenance == without->maintenance);
|
||||
}
|
||||
|
||||
// ADR-0099: development version 1 reads genome rates per second at its 50 ms quantum.
|
||||
// A schema 1 genome and its exact schema 2 translation develop identically, and a schema
|
||||
// 2 rate that is not a whole number per tick rounds down (a capacity).
|
||||
void schema_v2_rates_develop_identically() {
|
||||
auto old = draft();
|
||||
old.capabilities.push_back({Capability::movement, 250, 0});
|
||||
old.capabilities.push_back({Capability::ingestion, 120'000, 0});
|
||||
auto now = old;
|
||||
now.schema_version = genome_schema_version;
|
||||
now.capabilities[3].parameter = 5'000; // 250 per tick, per second.
|
||||
now.capabilities[4].parameter = 2'400'000; // 120000 per tick, per second.
|
||||
for (const std::uint32_t realized : {250U, 500U, 1000U}) {
|
||||
const auto a = derive_phenotype(build(old), {realized, 0}, temperate);
|
||||
const auto b = derive_phenotype(build(now), {realized, 0}, temperate);
|
||||
CHECK(a && b && *a == *b);
|
||||
const auto pa = plan_development(build(old), {realized, 0}, temperate);
|
||||
const auto pb = plan_development(build(now), {realized, 0}, temperate);
|
||||
CHECK(pa && pb && *pa == *pb);
|
||||
}
|
||||
now.capabilities[3].parameter = 5'019; // 250.95 per tick.
|
||||
const auto rounded = derive_phenotype(build(now), {1000, 0}, temperate);
|
||||
CHECK(rounded && rounded->movement_speed == 250);
|
||||
}
|
||||
|
||||
void thermal_shortfall_is_reported_not_enforced() {
|
||||
auto source = draft();
|
||||
source.capabilities.push_back({Capability::thermal_tolerance, 5'000, 0});
|
||||
@@ -272,6 +296,7 @@ int main() try {
|
||||
damage_is_not_genome();
|
||||
identical_inputs_give_identical_phenotypes();
|
||||
capability_prerequisites();
|
||||
schema_v2_rates_develop_identically();
|
||||
thermal_shortfall_is_reported_not_enforced();
|
||||
rule_versions_and_invalid_growth();
|
||||
availability_bounds_do_not_wrap();
|
||||
|
||||
+68
-21
@@ -115,30 +115,38 @@ void capability_and_range_rules() {
|
||||
draft = founder();
|
||||
draft.capabilities.push_back({Capability::thermal_tolerance, 1, 1U << capability_count});
|
||||
reject(draft, GenomeError::unknown_capability);
|
||||
// Every boundary of every declared range, from both sides.
|
||||
for (std::size_t index = 0; index < capability_count; ++index) {
|
||||
const auto kind = static_cast<Capability>(index);
|
||||
const auto& limits = capability_schema[index];
|
||||
for (const auto value : {limits.minimum, limits.maximum}) {
|
||||
draft = founder();
|
||||
// Every boundary of every declared range, from both sides, in each schema's own table.
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_version}) {
|
||||
const auto& table = *capability_schema_for(schema);
|
||||
const auto fresh = [&] {
|
||||
auto d = founder();
|
||||
d.schema_version = schema;
|
||||
return d;
|
||||
};
|
||||
for (std::size_t index = 0; index < capability_count; ++index) {
|
||||
const auto kind = static_cast<Capability>(index);
|
||||
const auto& limits = table[index];
|
||||
for (const auto value : {limits.minimum, limits.maximum}) {
|
||||
draft = fresh();
|
||||
std::erase_if(draft.capabilities,
|
||||
[kind](const auto& record) { return record.kind == kind; });
|
||||
draft.capabilities.push_back({kind, value, limits.mandates});
|
||||
const auto accepted = Genome::create(draft);
|
||||
CHECK(accepted && *accepted->parameter(kind) == value);
|
||||
}
|
||||
if (limits.minimum > 0) {
|
||||
draft = fresh();
|
||||
std::erase_if(draft.capabilities,
|
||||
[kind](const auto& record) { return record.kind == kind; });
|
||||
draft.capabilities.push_back({kind, limits.minimum - 1, limits.mandates});
|
||||
reject(draft, GenomeError::parameter_out_of_range);
|
||||
}
|
||||
draft = fresh();
|
||||
std::erase_if(draft.capabilities,
|
||||
[kind](const auto& record) { return record.kind == kind; });
|
||||
draft.capabilities.push_back({kind, value, limits.mandates});
|
||||
const auto accepted = Genome::create(draft);
|
||||
CHECK(accepted && *accepted->parameter(kind) == value);
|
||||
}
|
||||
if (limits.minimum > 0) {
|
||||
draft = founder();
|
||||
std::erase_if(draft.capabilities,
|
||||
[kind](const auto& record) { return record.kind == kind; });
|
||||
draft.capabilities.push_back({kind, limits.minimum - 1, limits.mandates});
|
||||
draft.capabilities.push_back({kind, limits.maximum + 1, limits.mandates});
|
||||
reject(draft, GenomeError::parameter_out_of_range);
|
||||
}
|
||||
draft = founder();
|
||||
std::erase_if(draft.capabilities,
|
||||
[kind](const auto& record) { return record.kind == kind; });
|
||||
draft.capabilities.push_back({kind, limits.maximum + 1, limits.mandates});
|
||||
reject(draft, GenomeError::parameter_out_of_range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +253,7 @@ void encoded_record_rules() {
|
||||
CHECK(!tampered && tampered.error() == GenomeError::digest_mismatch);
|
||||
// An unsupported schema version fails closed before anything else is read.
|
||||
auto future = bytes;
|
||||
future[8] = 2;
|
||||
future[8] = static_cast<std::uint8_t>(genome_schema_version + 1);
|
||||
reseal(future);
|
||||
const auto ahead = Genome::decode(future);
|
||||
CHECK(!ahead && ahead.error() == GenomeError::unsupported_version);
|
||||
@@ -313,6 +321,44 @@ void frozen_record_compatibility() {
|
||||
CHECK(*restored == *genome);
|
||||
}
|
||||
|
||||
// Schema 2 (ADR-0099): rates per second. Schema 1 records stay valid, unrewritten, and
|
||||
// read as exactly twenty times their per-tick values.
|
||||
void schema_v2_rates() {
|
||||
auto v1 = founder();
|
||||
v1.capabilities.push_back({Capability::movement, 5'000, 0});
|
||||
v1.capabilities.push_back({Capability::ingestion, 1'000'000, 0}); // Schema 1 maximum.
|
||||
const auto old = Genome::create(v1);
|
||||
CHECK(old && old->schema_version() == genome_schema_v1);
|
||||
CHECK(old->per_second(Capability::movement) == std::uint64_t{100'000});
|
||||
CHECK(old->per_second(Capability::ingestion) == std::uint64_t{20'000'000});
|
||||
CHECK(old->per_second(Capability::target_size) == std::uint64_t{5'000}); // Not a rate.
|
||||
CHECK(!old->per_second(Capability::thermal_tolerance));
|
||||
auto v2 = v1;
|
||||
v2.schema_version = genome_schema_version;
|
||||
v2.capabilities[3].parameter = 100'000; // Movement, per second.
|
||||
v2.capabilities[4].parameter = 20'000'000;
|
||||
const auto now = Genome::create(v2);
|
||||
CHECK(now && now->schema_version() == 2);
|
||||
CHECK(now->per_second(Capability::movement) == old->per_second(Capability::movement));
|
||||
CHECK(now->per_second(Capability::ingestion) == old->per_second(Capability::ingestion));
|
||||
// The same meaning in another schema is another record.
|
||||
CHECK(now->content_digest() != old->content_digest());
|
||||
const auto restored = Genome::decode(now->encode());
|
||||
CHECK(restored && *restored == *now && restored->schema_version() == 2);
|
||||
// Ranges are per schema: a schema 2 rate may exceed schema 1's per-tick maximum.
|
||||
v2.capabilities[4].parameter = 20'000'001;
|
||||
reject(v2, GenomeError::parameter_out_of_range);
|
||||
v1.capabilities[4].parameter = 1'000'001;
|
||||
reject(v1, GenomeError::parameter_out_of_range);
|
||||
auto unknown = founder();
|
||||
unknown.schema_version = 3;
|
||||
reject(unknown, GenomeError::unsupported_version);
|
||||
auto bytes = Genome::create(founder())->encode();
|
||||
bytes[8] = 3; // Schema field; decode refuses before the checksum matters.
|
||||
CHECK(!Genome::decode(bytes) &&
|
||||
Genome::decode(bytes).error() == GenomeError::unsupported_version);
|
||||
}
|
||||
|
||||
void moves_preserve_validity() {
|
||||
const auto original = Genome::create(founder());
|
||||
const auto other = Genome::create(descendant());
|
||||
@@ -349,6 +395,7 @@ int main() try {
|
||||
canonical_encoding();
|
||||
encoded_record_rules();
|
||||
frozen_record_compatibility();
|
||||
schema_v2_rates();
|
||||
moves_preserve_validity();
|
||||
std::cout << "PASS genome schema, ancestry, development graph and canonical encoding\n";
|
||||
return 0;
|
||||
|
||||
+27
-1
@@ -20,8 +20,10 @@ void check(bool condition, std::source_location location = std::source_location:
|
||||
}
|
||||
}
|
||||
#define CHECK(expression) check(static_cast<bool>(expression))
|
||||
Genome descend(std::uint64_t id, std::uint64_t parent, std::uint32_t conversion = 400) {
|
||||
Genome descend(std::uint64_t id, std::uint64_t parent, std::uint32_t conversion = 400,
|
||||
std::uint32_t schema = genome_schema_v1) {
|
||||
GenomeDraft source;
|
||||
source.schema_version = schema;
|
||||
source.id = id;
|
||||
source.origin_event = id;
|
||||
source.development_version = 1;
|
||||
@@ -380,6 +382,29 @@ void the_archive_decoder_refuses_damage_and_disorder() {
|
||||
CHECK(!LineageArchive::decode(std::span{bytes}.first(39)));
|
||||
}
|
||||
|
||||
// ADR-0099: the header names the highest genome schema held, so an archive of schema 1
|
||||
// records keeps its exact bytes, and a mixed archive round-trips.
|
||||
void schemas_mix_without_rewriting() {
|
||||
const auto old = with_history().encode();
|
||||
CHECK(field(old, 12, 4) == genome_schema_v1);
|
||||
auto archive = branching();
|
||||
CHECK(archive.admit(descend(6, 4, 400, genome_schema_version)));
|
||||
const auto bytes = archive.encode();
|
||||
CHECK(field(bytes, 12, 4) == genome_schema_version);
|
||||
const auto decoded = LineageArchive::decode(bytes);
|
||||
CHECK(decoded && decoded->encode() == bytes);
|
||||
CHECK(decoded->find(6)->schema_version() == 2 && decoded->find(4)->schema_version() == 1);
|
||||
// A header that understates its records is refused.
|
||||
auto understated = bytes;
|
||||
set(understated, 12, genome_schema_v1, 4);
|
||||
reseal(understated);
|
||||
CHECK(!LineageArchive::decode(understated));
|
||||
auto unknown = old;
|
||||
set(unknown, 12, 3, 4);
|
||||
reseal(unknown);
|
||||
CHECK(!LineageArchive::decode(unknown));
|
||||
}
|
||||
|
||||
void a_full_archive_round_trips() {
|
||||
LineageArchive archive;
|
||||
CHECK(archive.admit(descend(1, 0)));
|
||||
@@ -411,6 +436,7 @@ int main() try {
|
||||
the_archive_round_trips_canonically();
|
||||
the_archive_decoder_refuses_damage_and_disorder();
|
||||
a_full_archive_round_trips();
|
||||
schemas_mix_without_rewriting();
|
||||
std::cout << "PASS lineage retention, branching ancestry and provisional absence\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
|
||||
@@ -137,7 +137,8 @@ void only_legitimate_operators_are_offered() {
|
||||
CHECK(offered);
|
||||
for (const auto& candidate : offered->candidates) {
|
||||
// A required capability can never be shed, however it is drawn.
|
||||
const auto& limits = capability_schema[static_cast<std::size_t>(candidate.target)];
|
||||
const auto& limits = (*capability_schema_for(
|
||||
genome.schema_version()))[static_cast<std::size_t>(candidate.target)];
|
||||
CHECK(!(candidate.effect == MutationEffect::shed && limits.required));
|
||||
// Acquiring only ever applies to something the parent lacks, and
|
||||
// adjusting only to something it carries.
|
||||
@@ -320,6 +321,37 @@ void invalid_contexts_are_refused() {
|
||||
CHECK(mutation_catalog().size() == 4 * capability_count);
|
||||
}
|
||||
} // namespace
|
||||
// ADR-0099: a successor keeps its parent's schema and that schema's adjustment step, so
|
||||
// a schema 1 lineage is never migrated by mutating, and a schema 2 one steps per second.
|
||||
void successors_keep_their_parents_schema() {
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_version}) {
|
||||
auto source = draft();
|
||||
source.schema_version = schema;
|
||||
source.capabilities.push_back(
|
||||
{Capability::movement, schema == genome_schema_v1 ? 50'000U : 1'000'000U, 0});
|
||||
const auto parent = build(source);
|
||||
const auto step = schema == genome_schema_v1 ? 1'000U : 20'000U; // 1/100 of the range.
|
||||
bool adjusted = false;
|
||||
// Offers are seeded; search seeds (deterministically) for the movement adjustment.
|
||||
for (std::uint64_t seed = 1; seed <= 200 && !adjusted; ++seed) {
|
||||
const auto offered = mutation_candidates(parent, context(seed, 8));
|
||||
CHECK(offered);
|
||||
for (const auto& candidate : offered->candidates) {
|
||||
const auto successor = select_mutation(parent, context(seed, 8), *offered,
|
||||
candidate.operator_id, 99, 42);
|
||||
CHECK(successor && successor->schema_version() == schema);
|
||||
if (candidate.target == Capability::movement &&
|
||||
candidate.effect == MutationEffect::adjust_up) {
|
||||
CHECK(*successor->parameter(Capability::movement) ==
|
||||
*parent.parameter(Capability::movement) + step);
|
||||
adjusted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK(adjusted);
|
||||
}
|
||||
}
|
||||
|
||||
int main() try {
|
||||
the_same_context_always_offers_the_same_candidates();
|
||||
offers_are_canonical_and_unranked();
|
||||
@@ -330,6 +362,7 @@ int main() try {
|
||||
reported_cost_is_what_the_budget_charges();
|
||||
invalid_contexts_are_refused();
|
||||
every_eligible_operator_is_offered_and_none_is_favoured();
|
||||
successors_keep_their_parents_schema();
|
||||
std::cout << "PASS mutation catalog, uniform seeded offers and guarded selection\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
|
||||
Reference in New Issue
Block a user