diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index 98e1259..b7109ac 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -117,6 +117,9 @@ scoped change before starting the next segment. - 11.3a-2: ADR-0103 and the habitat's pure perception projection implement the 5 mm footprint-gap trial radius and exact in-range stock view. Live authenticated server replication and the complete cellular checkpoint remain open. +- 11.3c-2: habitat uptake proposals now require an authoritative in-bounds cell + footprint and refuse a patch outside contact. Atomic patch/life publication, + competing-life resolution and tick ordering remain open. ## Exit boundary diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 409de8b..973e8ad 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -5887,3 +5887,17 @@ dry-run; clang-tidy 19.1.5 using the MSVC `/std:c++latest` argument; and `git diff --check`. Linux GCC, ASan+UBSan, authenticated server visibility and the full CI suite remain pending CI. This projection is not yet wired into live replication or a persistent cellular checkpoint. + +## 2026-10-10 — M11.3c-2 contact-gated patch uptake (CI pending) + +The habitat uptake proposal now validates the cell footprint against the finite +arena and requires footprint contact with the requested stocked patch before it +calculates any transfer. Missing and non-contact patches are distinct refusals; +the helper still only proposes post-transfer balances and does not publish or +mutate either owner. + +Executed locally: warning-as-error MSVC Debug and Release `NDEBUG` compile/run, +focused CTest for motion, uptake and habitat (3/3 passed), clang-format 19.1.5, +clang-tidy 19.1.5 with MSVC `/std:c++latest`, and `git diff --check`. CI +qualification, simultaneous claims and atomic patch/life publication remain +open. diff --git a/include/evo/biology/cellular_habitat.hpp b/include/evo/biology/cellular_habitat.hpp index e7442a5..3410b2c 100644 --- a/include/evo/biology/cellular_habitat.hpp +++ b/include/evo/biology/cellular_habitat.hpp @@ -56,6 +56,7 @@ enum class CellularHabitatError : std::uint8_t { duplicate_patch, overflow, missing_patch, + not_in_contact, uptake, outside_area, format, @@ -86,8 +87,8 @@ class CellularHabitat { [[nodiscard]] std::expected, CellularHabitatError> perceive(CellularPosition position, std::uint32_t extent_um) const; [[nodiscard]] std::expected - propose_uptake(CellularPatchAddress address, accounting::Inventory reserve, - const MetabolicBudget& budget) const noexcept; + propose_uptake(CellularPatchAddress address, CellularPosition position, std::uint32_t extent_um, + accounting::Inventory reserve, const MetabolicBudget& budget) const noexcept; // Canonical little-endian envelope, FNV-1a64 checksum for corruption checks only. [[nodiscard]] std::vector snapshot() const; diff --git a/src/biology/cellular_habitat.cpp b/src/biology/cellular_habitat.cpp index c1dc01b..4327d16 100644 --- a/src/biology/cellular_habitat.cpp +++ b/src/biology/cellular_habitat.cpp @@ -152,12 +152,20 @@ CellularHabitat::perceive(CellularPosition position, std::uint32_t extent_um) co } std::expected -CellularHabitat::propose_uptake(CellularPatchAddress address, accounting::Inventory reserve, +CellularHabitat::propose_uptake(CellularPatchAddress address, CellularPosition position, + std::uint32_t extent_um, accounting::Inventory reserve, const MetabolicBudget& budget) const noexcept { + if (extent_um == 0 || extent_um > config_.width_um || extent_um > config_.height_um || + position.x_um > config_.width_um - extent_um || + position.y_um > config_.height_um - extent_um) + return std::unexpected{CellularHabitatError::outside_area}; const auto index = find(address); if (!index) return std::unexpected{CellularHabitatError::missing_patch}; const auto& patch = config_.patches[*index]; + if (!cellular_footprints_contact(position, extent_um, {patch.address.x_um, patch.address.y_um}, + cellular_patch_pitch_um)) + return std::unexpected{CellularHabitatError::not_in_contact}; const auto uptake = propose_cellular_uptake(patch.stock, reserve, budget); if (!uptake) return std::unexpected{CellularHabitatError::uptake}; diff --git a/tests/cellular_habitat_tests.cpp b/tests/cellular_habitat_tests.cpp index ef5930b..87742dc 100644 --- a/tests/cellular_habitat_tests.cpp +++ b/tests/cellular_habitat_tests.cpp @@ -44,13 +44,15 @@ void create_query_and_propose() { CHECK(!(*made)->find({2'000, 1'000})); CHECK((*made)->totals() == Inventory{{3'000}, {{{50}, {25}, {12}, {5}}}}); - const auto plan = (*made)->propose_uptake({0, 0}, {}, uptake_budget()); + const auto plan = (*made)->propose_uptake({0, 0}, {0, 0}, 20, {}, uptake_budget()); CHECK(plan && plan->patch == CellularPatchAddress{0, 0}); CHECK(plan->transfer.acquired == Inventory{{50}, {{{5}, {2}, {1}, {0}}}}); CHECK(plan->transfer.patch_after == Inventory{{950}, {{{15}, {8}, {4}, {2}}}}); CHECK(plan->transfer.reserve_after == plan->transfer.acquired); CHECK((*made)->patches()[0].stock == Inventory{{1'000}, {{{20}, {10}, {5}, {2}}}}); - CHECK(!(*made)->propose_uptake({2'000, 0}, {}, uptake_budget())); + CHECK(!(*made)->propose_uptake({2'000, 0}, {0, 0}, 20, {}, uptake_budget())); + const auto distant = (*made)->propose_uptake({1'000, 0}, {0, 0}, 20, {}, uptake_budget()); + CHECK(!distant && distant.error() == CellularHabitatError::not_in_contact); } void canonical_snapshot_round_trip() {