Files
TheTree_mock/tests/mvp/test_runtime_mana_depletion.gd
Takeshi 5dde0c5ec2 Record original-alignment implementation and traceability checkpoint
Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
2026-09-30 23:52:24 +09:00

82 lines
5.2 KiB
GDScript

extends SceneTree
var checks := 0
var failures := 0
func _initialize() -> void:
call_deferred("_run")
func expect(ok: bool, message: String) -> void:
checks += 1
if not ok:
failures += 1
push_error(message)
func _run() -> void:
var runtime: Variant = load("res://autoload/simulation_runtime.gd").new()
var clock: Variant = load("res://autoload/game_clock.gd").new()
var state: Variant = load("res://autoload/game_state.gd").new()
clock.reset(1, 6, 0)
state.reset()
expect(runtime.initialize(clock, state, 424242)[&"valid"], "initialize")
clock.set_paused(true)
expect(runtime.enable_production_operations()[&"ok"], "enable natural operations")
expect(runtime.submit_command(&"build_facility", {&"definition_id": &"reception", &"origin": Vector3i(-6, 0, 0)}).is_success(), "build reception")
clock.advance_minutes(120)
expect(runtime.submit_command(&"build_facility", {&"definition_id": &"standard_room", &"origin": Vector3i(-6, 2, 0)}).is_success(), "build zero-demand room on supported floor")
clock.advance_minutes(60)
var reception: FacilityInstance
var room: FacilityInstance
for facility: FacilityInstance in runtime.facility_service.get_instances():
if facility.definition_id == &"reception": reception = facility
if facility.definition_id == &"standard_room": room = facility
expect(room != null and reception != null, "both facilities complete normally")
if room == null or reception == null:
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)
# 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
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
var old_room_id := room.instance_id
expect(runtime.restore_snapshot(legacy), "pre-upkeep zero-reserve save migrates with old facility flags")
expect(legacy == source_copy, "migration does not mutate its source save")
expect(state.get_resource(&"mana") == 0 and clock.absolute_minute == 540 and clock.paused, "legacy migration preserves empty reserve saved time and pause")
expect(runtime.economy_service.get_balance(FacilityUpkeepSettlement.EXPENSE) == 0, "migration does not charge pre-save ownership or mana consumption")
var no_admission: Dictionary = runtime.call("_operations_arrival_boundary", {}, OperationsCoordinator.PHASE_CAPTURE, null)
expect(no_admission[&"capacity_remaining"] == 0, "legacy empty reserve rejects admission even before first resumed tick")
var migrated: Dictionary = runtime.create_snapshot()
var invalid: Dictionary = migrated.duplicate(true)
invalid[&"game_state"][&"resources"][&"mana"] = -1
expect(not runtime.restore_snapshot(invalid) and runtime.create_snapshot() == migrated, "invalid negative-reserve save rejects without changing active state")
clock.advance_minutes(1)
reception = runtime.facility_service.get_instance(old_reception_id)
room = runtime.facility_service.get_instance(old_room_id)
expect(clock.absolute_minute == 541 and not reception.power_available, "depletion gates powered facilities outside ten-minute evaluation")
expect(not room.power_available and room.operation_state == FacilityInstance.OperationState.INACTIVE, "zero-demand room also stops")
var capture: Dictionary = runtime.call("_operations_arrival_boundary", {}, OperationsCoordinator.PHASE_CAPTURE, null)
expect(capture[&"ok"] and capture[&"capacity_remaining"] == 0, "arrival transaction exposes no admission capacity during outage")
var stopped: Dictionary = runtime.create_snapshot()
expect(runtime.restore_snapshot(stopped), "outage restores through full runtime")
expect(runtime.create_snapshot() == stopped, "outage snapshot is exact")
clock.advance_minutes(9)
expect(not runtime.facility_service.get_instance(room.instance_id).power_available, "scheduled positive network output cannot bypass empty reserve")
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)
clock.advance_minutes(1)
room = runtime.facility_service.get_instance(room_id)
reception = runtime.facility_service.get_instance(reception_id)
expect(reception.power_available, "reserve restoration restores actual network supply next minute")
expect(room.power_available and room.operation_state == FacilityInstance.OperationState.SUSPENDED and room.suspension_reason == &"DESTROYED", "power recovery does not reverse destruction suspension")
var recovered: Dictionary = runtime.create_snapshot()
expect(runtime.restore_snapshot(recovered), "recovered runtime and persistent suspension restore")
expect(not runtime.get_operations_report()[&"runtime_failure_latched"], "depletion and recovery do not latch a runtime fault")
runtime.free()
clock.free()
state.free()
print("%s: %d checks" % ["PASS" if failures == 0 else "FAIL", checks])
quit(failures)