P06-01: Fix review r01 findings for A06 reserve

Settle Mana raised above capacity between boundaries as recorded overflow
instead of rejecting saves or latching a fault, exclude destroyed facilities
from upkeep demand, and keep the depletion drill's outage sustained.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Takeshi
2026-10-19 20:56:57 +09:00
co-authored by Claude Opus 5.5
parent 65534cfd15
commit f247d19325
10 changed files with 104 additions and 21 deletions
+4 -2
View File
@@ -1,4 +1,5 @@
extends SceneTree
const ManaOutage = preload("res://tests/helpers/mana_outage.gd")
var checks := 0
var failures := 0
func _initialize() -> void:
@@ -31,11 +32,12 @@ func _run() -> void:
runtime.free(); clock.free(); state.free(); quit(failures); return
# Only reserve depletion is a diagnostic input; no numeric generation policy
# is asserted by this test. Everything else advances through Runtime ticks.
state.set_resource(&"mana", 0)
ManaOutage.hold(runtime, state)
# Pre-fix saves legitimately contain zero reserve with old powered flags.
var legacy: Dictionary = runtime.create_snapshot()
var legacy_data: Dictionary = legacy[&"systems"][&"runtime"]
legacy_data[&"runtime_schema_version"] = 9
legacy_data.erase(&"mana_reserve")
preload("res://tests/fixtures/pre_upkeep_runtime.gd").strip_empty_upkeep(legacy_data)
var source_copy := legacy.duplicate(true)
var old_reception_id := reception.instance_id
@@ -65,7 +67,7 @@ func _run() -> void:
var room_id := room.instance_id
var reception_id := reception.instance_id
runtime.facility_service.set_operational_status(room_id, {&"suspension_reason": &"DESTROYED"}, clock.absolute_minute)
state.set_resource(&"mana", 1)
ManaOutage.release(runtime, state, 1)
clock.advance_minutes(1)
room = runtime.facility_service.get_instance(room_id)
reception = runtime.facility_service.get_instance(reception_id)
+7 -1
View File
@@ -34,7 +34,13 @@ func _initialize() -> void:
var saved: Dictionary = cycle.create_snapshot()
expect(not cycle.advance_to(370, 57, 63)[&"processed"] and cycle.create_snapshot() == saved, "same boundary never consumed twice")
expect(not cycle.advance_to(360, 57, 63)[&"ok"], "time reversal rejected")
expect(not cycle.advance_to(380, 301, 0)[&"ok"] and cycle.create_snapshot() == saved, "over-capacity reserve rejected without change")
expect(not cycle.advance_to(380, -1, 0)[&"ok"] and cycle.create_snapshot() == saved, "negative reserve rejected without change")
var high = Cycle.new()
high.start_at(360)
flow = high.advance_to(370, 525, 16)[&"flow"]
expect(flow[&"after"] == 300 and flow[&"overflow"] == 229, "amount raised above capacity between boundaries settles with recorded overflow")
var high_restored = Cycle.new()
expect(high_restored.restore_snapshot(high.create_snapshot()), "over-capacity before survives snapshot validation")
var skipped: Dictionary = cycle.advance_to(400, 57, 63)
expect(skipped[&"boundaries"] == 3 and skipped[&"after"] == 0 and skipped[&"flow"][&"shortage"] == 43, "skipped boundaries settle in order")
var restored = Cycle.new()
+42
View File
@@ -18,6 +18,8 @@ func _run() -> void:
_test_generation_and_demand()
_test_save_round_trip_and_migration()
_test_depletion_stops_tower()
_test_between_boundary_increase()
_test_destroyed_facility_demand()
_cleanup()
if _failures == 0:
print("PASS: %d checks" % _checks)
@@ -100,6 +102,46 @@ func _test_depletion_stops_tower() -> void:
_expect(_state.get_resource(&"mana") == maxi(0, 20 - demand), "world tree recovers the reserve at the next boundary")
func _test_between_boundary_increase() -> void:
_clock.advance_minutes(10 - (_clock.absolute_minute % 10) + 3)
_state.add_resource(&"mana", 400)
var high: int = _state.get_resource(&"mana")
_expect(high > Cycle.CAPACITY, "mana can rise above capacity between boundaries (event refund / command)")
var saved: Dictionary = _runtime.create_snapshot()
_expect(_runtime.restore_snapshot(saved.duplicate(true)) and _state.get_resource(&"mana") == high, "over-capacity mid-interval save restores")
_clock.advance_minutes(1)
_expect(not _runtime.get_operations_report()[&"runtime_failure_latched"], "over-capacity amount does not latch a runtime fault")
_clock.advance_minutes(10 - (_clock.absolute_minute % 10))
var flow: Dictionary = _runtime.mana_reserve.get_last_flow()
_expect(_state.get_resource(&"mana") == Cycle.CAPACITY and flow[&"before"] == high, "next boundary settles to capacity")
_expect(flow[&"overflow"] == high + 20 - int(flow[&"consumed"]) - Cycle.CAPACITY, "excess is recorded as overflow")
func _test_destroyed_facility_demand() -> void:
var build = _runtime.submit_command(
&"build_facility",
{&"definition_id": &"cafeteria", &"origin": Vector3i(-5, 0, WorldService.LAYER_FRONT), &"rotation": 0},
&"player", &"", 50, -1, &"a06.build.cafeteria"
)
_expect(build.is_success(), "cafeteria construction starts")
_clock.advance_minutes(180)
var cafeteria: FacilityInstance = null
for facility: FacilityInstance in _runtime.facility_service.get_instances():
if facility.definition_id == &"cafeteria":
cafeteria = facility
_expect(cafeteria != null, "cafeteria completes")
if cafeteria == null:
return
var with_cafeteria: int = _runtime.call("_mana_reserve_demand")
_expect(with_cafeteria == _runtime.mana_network_service.get_total_consumer_demand(), "owned facility demand counts")
_runtime.facility_service.set_operational_status(cafeteria.instance_id, {&"business_open": false}, _clock.absolute_minute)
_expect(_runtime.call("_mana_reserve_demand") == with_cafeteria, "closed facility still pays upkeep demand")
_runtime.facility_service.set_operational_status(cafeteria.instance_id, {&"suspension_reason": &"DESTROYED"}, _clock.absolute_minute)
_expect(_runtime.call("_mana_reserve_demand") == with_cafeteria - 2, "destroyed facility demand is excluded")
_clock.advance_minutes(10 - (_clock.absolute_minute % 10))
_expect(int(_runtime.mana_reserve.get_last_flow()[&"demand"]) == with_cafeteria - 2, "boundary uses demand without destroyed facility")
func _expect(condition: bool, label: String) -> void:
_checks += 1
if condition: