Files
TheTree_mock/docs/spec/inputs/p08-02/p03-current1299-EV-retarget-refusal-native-r02-reader.gd

132 lines
11 KiB
GDScript

extends SceneTree
const PAIR_ROOT := "/Users/korizatou114/Projects/とりにく工房ゲーム制作部/artifacts/original-completion-2026-10-02/p03-current1299-EV-retarget-refusal-native-r02/migration-pair"
const MODE := "read"
var checks:=0
var failures:=0
var runtime: Variant
var clock: Variant
var state: Variant
var job_id: StringName
var serial:=0
var journal: Array[Dictionary]=[]
func _initialize() -> void:call_deferred("run")
func expect(ok: bool,label: String) -> void:
checks+=1
print(("PASS " if ok else "FAIL ")+label)
if not ok:failures+=1;push_error("P03_INFLIGHT "+label)
func write_proof(name: String,value: Variant) -> void:
var path:=PAIR_ROOT.path_join(name)
expect(not FileAccess.file_exists(path),"fresh proof "+name)
var file:=FileAccess.open(path,FileAccess.WRITE)
expect(file!=null,"open proof "+name)
if file!=null:file.store_buffer(var_to_bytes(value));file.close()
func read_proof(name: String) -> Variant:
var data:=FileAccess.get_file_as_bytes(PAIR_ROOT.path_join(name))
expect(not data.is_empty(),"read whole proof "+name)
return bytes_to_var(data)
func command(kind: StringName,payload: Dictionary) -> CommandResult:
serial+=1
var result: CommandResult=runtime.submit_command(kind,payload,&"player",&"",0,-1,StringName("p03.inflight.%d"%serial))
expect(result.is_success(),"public paid command "+String(kind)+": "+result.message)
return result
func copy_package(source: String,destination: String) -> void:
expect(DirAccess.make_dir_recursive_absolute(destination)==OK,"package destination "+destination)
for name: String in [SaveService.WORLD_FILE,SaveService.MANIFEST_FILE,SaveService.THUMBNAIL_FILE,SaveService.JOURNAL_FILE]:
var original:=FileAccess.get_file_as_bytes(source.path_join(name))
expect(not original.is_empty() and not FileAccess.file_exists(destination.path_join(name)),"fresh formal member "+name)
var file:=FileAccess.open(destination.path_join(name),FileAccess.WRITE)
expect(file!=null,"open formal member "+name)
if file!=null:file.store_buffer(original);file.close()
expect(original==FileAccess.get_file_as_bytes(destination.path_join(name)),"complete formal member "+name)
func observe(event: SimulationDomainEvent) -> void:journal.append(event.to_dictionary())
func capture(label: String) -> void:
var snapshot: Dictionary=runtime.create_snapshot()
write_proof(MODE+"-"+label+".var",snapshot)
if MODE=="read":expect(var_to_bytes(snapshot)==var_to_bytes(read_proof("write-"+label+".var")),"entire separate-PID snapshot "+label)
var room_id: StringName
const OLD_TARGET:=Vector3i(-7,3,0)
const SLOT: String="user://p03-EV-refusal/manual"
func package_hashes() -> Dictionary:
var values: Dictionary={}
for suffix: String in ["",SaveService.MIGRATION_BACKUP_SUFFIX]:
for name: String in [SaveService.WORLD_FILE,SaveService.MANIFEST_FILE,SaveService.THUMBNAIL_FILE,SaveService.JOURNAL_FILE]:
values[suffix+"/"+name]=FileAccess.get_sha256(ProjectSettings.globalize_path(SLOT+suffix).path_join(name))
return values
func refusal(label: String) -> void:
var before: Dictionary=runtime.create_snapshot()
var packages: Dictionary=package_hashes()
var prepared: Dictionary=runtime.prepare_facility_dimension_snapshot(room_id)
expect(not prepared.get(&"ok",false) and &"TRANSPORT_REPLAN_REQUIRED" in prepared.get(&"retargeting",{}).get(&"errors",[]),"actual occupied trip explicitly refuses retarget")
expect(prepared.get(&"routes",{}).get(&"guest_replans",[]).size()==1,"one actual guest destination requires replan")
var preview: Dictionary=runtime.preview_facility_dimensions_at_path(SLOT)
expect(not preview.get(&"ok",false),"formal migration review rejects occupied retarget")
var result: Dictionary=runtime.migrate_facility_dimensions_at_path(SLOT)
expect(not result.get(&"ok",false) and result.get(&"code",&"")==&"DIMENSION_MIGRATION_REJECTED" and result.get(&"details",{}).get(&"rolled_back",false),"formal batch refuses and rolls back isolated candidate")
expect(var_to_bytes(before)==var_to_bytes(runtime.create_snapshot()),"entire live world unchanged after all three migration paths")
expect(package_hashes()==packages,"all original and real preexisting backup files unchanged")
write_proof(MODE+"-"+label+"-refusal.var",{&"prepared":prepared,&"preview":preview,&"result":result,&"packages":packages})
capture(label)
func run() -> void:
root.get_node("GameClock").set_paused(true);root.get_node("GameClock").set_process(false)
root.get_node("SimulationRuntime").configure_save_policy({&"enabled":false,&"daily_checkpoint_enabled":false})
runtime=load("res://autoload/simulation_runtime.gd").new();clock=load("res://autoload/game_clock.gd").new();state=load("res://autoload/game_state.gd").new()
clock.reset(1,6,0);state.reset();expect(runtime.initialize(clock,state,42588)[&"valid"],"canonical current initialization")
clock.set_paused(true);runtime.configure_save_policy({&"enabled":false,&"daily_checkpoint_enabled":false,&"auto_migrate":false})
var paths: Array[String]=FacilityCatalog.FACILITY_PATHS+FacilityCatalog.INFRASTRUCTURE_FACILITY_PATHS+FacilityCatalog.RESCUE_FACILITY_PATHS
if MODE=="write":
expect(DirAccess.make_dir_recursive_absolute(PAIR_ROOT)==OK,"own fresh evidence directory")
paths.append("res://tests/fixtures/legacy_premium_room.tres")
expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"explicit archived definition")
for row: Array in [[&"guest_elevator",Vector3i(-8,0,0)],[&"reception",Vector3i(-6,0,0)],[&"premium_room",Vector3i(-6,2,0)],[&"guest_stairs",Vector3i(-7,2,0)],[&"guest_stairs",Vector3i(-7,3,0)]]:
if not command(&"build_facility",{&"definition_id":row[0],&"origin":row[1]}).is_success():
runtime.free();clock.free();state.free()
print("EV retarget refusal formal "+MODE+": %d checks, %d failures"%[checks,failures]);quit(failures);return
clock.advance_minutes(runtime.definition_registry.get_facility(row[0]).build_minutes)
for instance: FacilityInstance in runtime.facility_service.get_instances():
if instance.definition_id==&"premium_room":room_id=instance.instance_id
expect(not room_id.is_empty(),"normally paid completed old-size room")
expect(not runtime.path_service.find_path(Vector3i(-8,0,0),OLD_TARGET).is_empty(),"real paid old upper entrance reachable through EV and corridors")
var baseline: Dictionary=runtime.create_snapshot()
expect(SaveService.save_snapshot(SLOT,baseline)[&"ok"],"formal old room baseline before real backup creation")
paths.erase("res://tests/fixtures/legacy_premium_room.tres");paths.append("res://data/facilities/expansion/premium_room.tres")
expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"current approved footprint registry")
var first: Dictionary=runtime.migrate_facility_dimensions_at_path(SLOT)
expect(first.get(&"ok",false) and first.get(&"backup_created",false),"normal unoccupied migration creates actual verified backup")
expect(var_to_bytes(runtime.create_snapshot())==var_to_bytes(baseline),"first migration leaves live original geometry")
expect(var_to_bytes(SaveService.load_snapshot(SLOT+SaveService.MIGRATION_BACKUP_SUFFIX).get(&"snapshot",{}))==var_to_bytes(baseline),"actual backup exactly restores pre-migration baseline")
write_proof("baseline.var",baseline)
command(&"spawn_guest",{&"guest_id":&"p03.retarget.passenger",&"guest_type_id":&"traveler",&"gold":100,&"options":{&"current_cell":Vector3i(-8,0,0),&"state":GuestRuntime.State.MOVING,&"state_entered_at":clock.absolute_minute-1,&"planned_exit_at":clock.absolute_minute+2000,&"target_facility_id":room_id,&"path_handle":{&"target_cell":OLD_TARGET}}})
clock.advance_minutes(2)
var trip: Dictionary=runtime.elevators.get_actor_trip(&"guest:p03.retarget.passenger")
expect(not trip.is_empty() and trip.get(&"state",&"")==&"BOARDED","real passenger owns actual boarded EV trip")
var legacy: Dictionary=runtime.create_snapshot()
expect(SaveService.save_snapshot(SLOT,legacy)[&"ok"],"formal original includes occupied trip and old entrance")
write_proof("legacy.var",legacy);write_proof("identity.var",{&"room_id":room_id,&"serial":serial,&"request_id":trip.get(&"request_id",&"")})
copy_package(ProjectSettings.globalize_path(SLOT),PAIR_ROOT.path_join("original/formal"))
copy_package(ProjectSettings.globalize_path(SLOT+SaveService.MIGRATION_BACKUP_SUFFIX),PAIR_ROOT.path_join("backup/formal"))
else:
paths.append("res://data/facilities/expansion/premium_room.tres")
expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"reader current approved footprint registry")
var identity: Dictionary=read_proof("identity.var");room_id=identity[&"room_id"];serial=identity[&"serial"]
copy_package(PAIR_ROOT.path_join("original/formal"),ProjectSettings.globalize_path(SLOT))
copy_package(PAIR_ROOT.path_join("backup/formal"),ProjectSettings.globalize_path(SLOT+SaveService.MIGRATION_BACKUP_SUFFIX))
expect(runtime.restore_snapshot(SaveService.load_snapshot(SLOT+SaveService.MIGRATION_BACKUP_SUFFIX).get(&"snapshot",{})),"separate PID restores real earlier backup")
expect(var_to_bytes(runtime.create_snapshot())==var_to_bytes(read_proof("baseline.var")),"whole earlier backup state matches")
expect(runtime.restore_snapshot(SaveService.load_snapshot(SLOT).get(&"snapshot",{})),"actual original boarded package restores")
expect(var_to_bytes(runtime.create_snapshot())==var_to_bytes(read_proof("legacy.var")),"whole boarded original restored exactly")
capture("checkpoint");refusal("reject1");refusal("reject2")
if MODE=="write":copy_package(ProjectSettings.globalize_path(SLOT),PAIR_ROOT.path_join("after-refusal/formal"))
expect(runtime.domain_events.subscribe(&"*",&"p03.refusal.uncapped",Callable(self,"observe")),"whole uncapped post-refusal journal")
clock.advance_minutes(1);capture("next1")
clock.advance_minutes(1);capture("next2")
clock.advance_minutes(8);capture("next10")
clock.advance_minutes(10);capture("final20")
expect(runtime.facility_service.get_instance(room_id).occupied_cells.size()==6,"rejected conversion retains original facility shape")
expect(runtime.elevators.get_actor_trip(&"guest:p03.retarget.passenger").is_empty() and runtime.path_service.get_transit_actor_ids().is_empty(),"original EV trip finishes without orphan transit after refusal")
expect(runtime.restore_snapshot(runtime.create_snapshot()),"post-refusal continuation remains canonical")
write_proof(MODE+"-events.var",journal)
if MODE=="read":expect(var_to_bytes(journal)==var_to_bytes(read_proof("write-events.var")),"entire post-refusal journal matches without deletion or replacement")
write_proof(MODE+"-result.var",{&"pid":OS.get_process_id(),&"checks":checks,&"failures":failures,&"events":journal.size()})
runtime.free();clock.free();state.free()
print("EV retarget refusal formal "+MODE+": %d checks, %d failures"%[checks,failures]);quit(failures)