extends SceneTree var checks:=0 var failures:=0 func expect(ok:bool,label:String)->void: checks+=1 if not ok:failures+=1;push_error(label) func _initialize()->void:call_deferred("run") 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();runtime.initialize(clock,state,42608);clock.set_paused(true) expect(runtime.submit_command(&"build_facility",{&"definition_id":&"chapel",&"origin":Vector3i(-6,0,0)}).is_success(),"build normal catalog chapel") clock.advance_minutes(180) var chapel:FacilityInstance for f:FacilityInstance in runtime.facility_service.get_instances(): if f.definition_id==&"chapel":chapel=f if chapel==null:expect(false,"chapel exists");quit(failures);return var facility_id:StringName=chapel.instance_id expect(runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"staff_uma"}).is_success(),"hire real cleric") expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"staff_uma",&"facility_id":facility_id,&"template_id":&"DAY"}).is_success(),"assign cleric") clock.advance_minutes(20) expect(chapel.active_staff_ids==[&"staff_uma"],"actual cleric attendance opens chapel") for index in 9: var guest_id:=StringName("chapel_capacity_%d"%index) expect(runtime.submit_command(&"register_guest_wallet",{&"guest_id":guest_id,&"gold":100}).is_success(),"fund controlled capacity payer") expect(runtime.submit_command(&"create_service_request",{&"request_id":StringName("worship_%d"%index),&"facility_id":facility_id,&"guest_ids":[guest_id],&"service_type":&"worship"}).is_success(),"request capacity worship") if index==7:clock.advance_one_minute() clock.advance_one_minute() expect(runtime.facility_service.get_active_services(facility_id).size()==8 and chapel.queue_entries.size()==1,"eight simultaneous customers and one separate waiting request") var occupied:Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(occupied) and runtime.create_snapshot()==occupied,"full chapel and waiting queue restore exactly") var services:Array=runtime.facility_service.get_active_services(facility_id) var service_id:StringName=services[0].service_id var elapsed:int=services[0].elapsed_minutes expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"staff_uma",&"facility_id":&"",&"template_id":&"DAY"}).is_success(),"normal unassignment removes required cleric") clock.advance_minutes(2) var interrupted:ServiceInstance=runtime.facility_service.get_service(service_id) expect(interrupted.state==ServiceInstance.State.WAITING_FOR_STAFF and interrupted.elapsed_minutes==elapsed,"cleric loss pauses worship without consuming service time") expect(state.get_resource(&"faith")==0 and runtime.economy_service.get_balance(&"GUEST_WALLET:chapel_capacity_0")==100,"interrupted worship grants no faith and takes no donation") var paused:Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(paused) and runtime.create_snapshot()==paused,"interrupted services and grace deadline restore together") clock.advance_minutes(6) expect(runtime.facility_service.get_service(service_id).state==ServiceInstance.State.FAILED,"continued absence fails worship after existing replacement grace") expect(state.get_resource(&"faith")==0 and runtime.economy_service.get_balance(&"GUEST_WALLET:chapel_capacity_0")==100,"failed worship grants no reward or charge") expect(runtime.restore_snapshot(occupied),"restore staffed capacity scenario") var exceeded:=false for minute in 125: clock.advance_one_minute() exceeded=exceeded or runtime.facility_service.get_active_services(facility_id).size()>8 expect(not exceeded,"queue continuation never exceeds eight simultaneous users") expect(state.get_resource(&"faith")==9 and runtime.progression_service.metrics[&"faith_lifetime"]==9,"all nine requests complete with nine faith total") var revenue:=0 for entry:LedgerEntry in runtime.economy_service.get_entries(): if entry.category==&"SERVICE_SALE" and entry.source_entity_id==facility_id:revenue+=entry.amount expect(revenue==180 and runtime.economy_service.validate_ledger()[&"ok"],"nine donations produce180G with balanced ledger") expect(runtime.restore_snapshot(runtime.create_snapshot()),"finished capacity services and Faith remain saveable") # Start a separate normal operating game; enabling midway is invalid by design. clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,42609);clock.set_paused(true) var enabled:Dictionary=runtime.enable_production_operations() expect(enabled[&"ok"],"enable normal arrivals and daily closing from new game") if not enabled[&"ok"]:runtime.free();clock.free();state.free();quit(failures);return expect(runtime.submit_command(&"build_facility",{&"definition_id":&"chapel",&"origin":Vector3i(-6,0,0)}).is_success(),"construct chapel in normal operating game") clock.advance_minutes(180) for f:FacilityInstance in runtime.facility_service.get_instances(): if f.definition_id==&"chapel":facility_id=f.instance_id expect(runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"staff_uma"}).is_success(),"hire cleric in normal operating game") expect(runtime.submit_command(&"set_staff_work_assignment",{&"staff_id":&"staff_uma",&"facility_id":facility_id,&"template_id":&"DAY"}).is_success(),"staff chapel in normal operating game") clock.advance_minutes(1439-clock.absolute_minute) var before_close:Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(before_close),"chapel23:59 operating state restores") clock.advance_one_minute() var first_day:Dictionary=runtime.operations_coordinator.get_day_summary(1) expect(not first_day.is_empty() and first_day[&"category_totals"][&"maintenance"]==3,"first partial ownership day charges prorated chapel upkeep") clock.advance_minutes(1439) var second_close:Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(second_close),"second operating day saves before settlement") clock.advance_one_minute() var second_day:Dictionary=runtime.operations_coordinator.get_day_summary(2) expect(not second_day.is_empty() and second_day[&"category_totals"][&"maintenance"]==6,"full ownership day charges approved6G chapel upkeep") var all_sales:=0 for entry:LedgerEntry in runtime.economy_service.get_entries(): if entry.category==&"SERVICE_SALE" and entry.source_entity_id==facility_id:all_sales+=entry.amount expect(all_sales>0 and all_sales==int(state.get_resource(&"faith"))*20 and runtime.progression_service.metrics[&"faith_lifetime"]==state.get_resource(&"faith"),"two-day natural operations reconcile donations with Faith and lifetime progress") expect(runtime.economy_service.validate_ledger()[&"ok"] and not runtime.get_operations_report()[&"runtime_failure_latched"],"two-day chapel operation closes without ledger or runtime failure") expect(runtime.restore_snapshot(runtime.create_snapshot()),"second chapel close restores without repeating settlement") runtime.free();clock.free();state.free() print("Chapel boundaries: %d checks, %d failures"%[checks,failures]);quit(failures)