From 94edeba474c873d6d3504f574805a74778f779a1 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 10 Oct 2026 16:28:27 -0400 Subject: [PATCH] Fix optional access in reservation tests --- docs/engineering/VALIDATION.md | 8 ++++++++ tests/life_reservation_store_tests.cpp | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 400ff0f..34da71d 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -5706,3 +5706,11 @@ explicitly checked before access. clang-format 19.1.5 dry-run, clang-tidy 19.1.5 with warnings-as-errors, GCC 13.2 Release/NDEBUG compilation with warnings-as- errors, and `git diff --check` pass locally. PostgreSQL integration remains unavailable in this Windows environment; awaiting CI rerun. + +The next CI analysis build reached the PostgreSQL tests and reported four +`bugprone-unchecked-optional-access` errors in the life-reservation test's nested +`expected>` checks. Reworked those assertions to extract safe +fallback values while still checking both success/presence states. clang-format +19.1.5, clang-tidy 19.1.5 with warnings-as-errors, GCC 13.2 Release/NDEBUG +compilation with warnings-as-errors, and `git diff --check` pass locally. The +PostgreSQL test binary remains unrun locally; awaiting CI rerun. diff --git a/tests/life_reservation_store_tests.cpp b/tests/life_reservation_store_tests.cpp index 0af6430..d43c203 100644 --- a/tests/life_reservation_store_tests.cpp +++ b/tests/life_reservation_store_tests.cpp @@ -80,9 +80,11 @@ void run_life_reservation_store_tests() { CHECK(reserve(2) == *conflict); auto conflict_result = query_primitive_life(*db, a, *lease_a, alice, control->generation, 2, 5s); - CHECK(conflict_result && *conflict_result && - (**conflict_result).reservation.refusal == LifeRefusal::existing_life && - !(**conflict_result).published); + const auto conflict_outcome = conflict_result.value_or(std::nullopt); + const auto conflict_value = conflict_outcome.value_or(PrimitiveLifeOutcome{}); + CHECK(conflict_result.has_value() && conflict_outcome.has_value() && + conflict_value.reservation.refusal == LifeRefusal::existing_life && + !conflict_value.published); CHECK(failed(reserve_primitive_life(*db, a, *lease_a, alice, 2, request, 1, 5s), LifeReservationError::fenced)); CHECK(failed(reject_primitive_life(*db, a, *lease_a, alice, 1, request, LifeRefusal::none, 5s), @@ -118,8 +120,11 @@ void run_life_reservation_store_tests() { const auto moved = claim_account_control(*db, b, *lease_b, alice, 2, 2, 20000ms, 5s); CHECK(moved); auto moved_result = query_primitive_life(*db, b, *lease_b, alice, moved->generation, 4, 5s); - CHECK(moved_result && *moved_result && (**moved_result).reservation.region == 1 && - (**moved_result).reservation.refusal == LifeRefusal::cancelled); + const auto moved_outcome = moved_result.value_or(std::nullopt); + const auto moved_value = moved_outcome.value_or(PrimitiveLifeOutcome{}); + CHECK(moved_result.has_value() && moved_outcome.has_value() && + moved_value.reservation.region == 1 && + moved_value.reservation.refusal == LifeRefusal::cancelled); const auto cancelled_retry = reserve_primitive_life(*db, b, *lease_b, alice, moved->generation, 4, 1, 5s); CHECK(cancelled_retry && cancelled_retry->refusal == LifeRefusal::cancelled);