Files

102 lines
7.0 KiB
GDScript

extends "/Users/korizatou114/Projects/とりにく工房ゲーム制作部/artifacts/original-completion-2026-10-02/p23-02-native-ready-route-fallback-r307-r02.gd"
const INDEX_CASES := ["missing_index", "negative_index", "beyond_cost_index"]
const SHAPE_CASES := ["parents_array", "cells_packed_vector3"]
var boundary_records: Array = []
var reentry_input: Dictionary={}
var nested_result: Dictionary={}
func boundary_setup(label: String) -> Dictionary:
var input: Dictionary=route_setup("ordinary")
if input.is_empty(): return input
var tree: Dictionary=input["tree"]
if label=="missing_index": tree[&"indices"].erase(input["goal"])
elif label=="negative_index": tree[&"indices"][input["goal"]]=-1
elif label=="beyond_cost_index": tree[&"indices"][input["goal"]]=tree[&"cost_values"].size()
elif label=="parents_array":
var converted: Array[int]=[]
for value: int in tree[&"parent_indices"]: converted.append(value)
tree[&"parent_indices"]=converted
elif label=="cells_packed_vector3":
var converted := PackedVector3Array()
for cell: Vector3i in tree[&"cells"]: converted.append(Vector3(cell))
tree[&"cells"]=converted
return input
func selected(input: Dictionary, ticks: Callable) -> Dictionary:
return core.nearest_guest_access(input["path"],Vector3i.ZERO,input["goals"],input["goal"],input["layers"],input["access"],ticks)
func index_case(label: String) -> void:
var input: Dictionary=boundary_setup(label)
if input.is_empty(): return
var before: PackedByteArray=var_to_bytes(state())
var result: Dictionary=selected(input,Callable(Time,"get_ticks_usec"))
check(not bool(result.get(&"supported",true)),label+" rejected before compact parent walk")
check(var_to_bytes(state())==before,label+" rejection preserves full Runtime cache counters errors and query batch")
boundary_records.append({"case":label,"result":result,"before":bytes_to_var(before),"after":state()})
func shape_case(label: String) -> void:
var input: Dictionary=boundary_setup(label)
if input.is_empty(): return
var p: PathService=input["path"]
var before_tree: PackedByteArray=var_to_bytes(input["tree"])
var result: Dictionary=selected(input,Callable(Time,"get_ticks_usec"))
check(bool(result.get(&"supported",false)),label+" original conversion shape remains supported")
var result_bytes: PackedByteArray=var_to_bytes(result)
var after: PackedByteArray=var_to_bytes(state())
var route: Array=result[&"path"]
var key: String=p._cache_key(Vector3i.ZERO,input["goal"],input["layers"],input["access"])
var cached: Array=p._path_cache[key]
check(route.is_typed() and route.get_typed_builtin()==TYPE_VECTOR3I and not route.is_read_only() and cached.is_typed() and cached.get_typed_builtin()==TYPE_VECTOR3I and not cached.is_read_only() and not is_same(route,cached),label+" typed writable independent cache owner")
check(var_to_bytes(input["tree"])==before_tree,label+" original tree shape and all bytes preserved")
var cache_before: PackedByteArray=var_to_bytes(p._path_cache)
route[0]=Vector3i(99,99,0)
check(var_to_bytes(p._path_cache)==cache_before,label+" result mutation leaves cache unchanged")
var route_before: PackedByteArray=var_to_bytes(route)
cached[0]=Vector3i(77,77,0)
check(var_to_bytes(route)==route_before,label+" cache mutation leaves result unchanged")
boundary_records.append({"case":label,"result":bytes_to_var(result_bytes),"tree_before":bytes_to_var(before_tree),"after":bytes_to_var(after)})
func reentry_ticks() -> int:
tick_calls+=1
if tick_calls==1: nested_result=selected(reentry_input,Callable(Time,"get_ticks_usec"))
return Time.get_ticks_usec()
func reentry_case() -> void:
reentry_input=boundary_setup("ordinary")
if reentry_input.is_empty(): return
var p: PathService=reentry_input["path"]
p.path_query_measured.connect(observed)
tick_calls=0;nested_result={}
var result: Dictionary=selected(reentry_input,Callable(self,"reentry_ticks"))
check(bool(result.get(&"supported",false)),"outer call supported after actual nested nearest query")
check(tick_calls==2 and bool(nested_result.get(&"supported",false)),"actual nested call runs at first outer tick and both complete")
check(p.cache_hits==1 and p.cache_misses==1 and calls==2,"nested miss followed by outer hit and exactly two query signals")
check(var_to_bytes(result)==var_to_bytes(nested_result),"outer cached route equals nested route ordered typed bytes")
var result_bytes: PackedByteArray=var_to_bytes(result)
var nested_bytes: PackedByteArray=var_to_bytes(nested_result)
var after: PackedByteArray=var_to_bytes(state())
var route: Array=result[&"path"]
var key: String=p._cache_key(Vector3i.ZERO,reentry_input["goal"],reentry_input["layers"],reentry_input["access"])
var cached: Array=p._path_cache[key]
check(route.is_typed() and route.get_typed_builtin()==TYPE_VECTOR3I and not route.is_read_only() and cached.is_typed() and cached.get_typed_builtin()==TYPE_VECTOR3I and not cached.is_read_only() and not is_same(route,cached),"outer reentry route/cache typed writable separate owners")
var cache_before: PackedByteArray=var_to_bytes(p._path_cache)
route[0]=Vector3i(55,55,0)
check(var_to_bytes(p._path_cache)==cache_before,"reentry outer result mutation leaves cache unchanged")
var route_before: PackedByteArray=var_to_bytes(route)
cached[0]=Vector3i(44,44,0)
check(var_to_bytes(route)==route_before,"reentry cache mutation leaves outer result unchanged")
boundary_records.append({"case":"nested_same_goal","result":bytes_to_var(result_bytes),"nested":bytes_to_var(nested_bytes),"after":bytes_to_var(after),"outer_ticks":tick_calls,"query_signals":calls})
reentry_input={};nested_result={}
func run() -> void:
output=OS.get_environment("THE_TREE_RUNTIME_MONITOR_OUTPUT")
runtime=root.get_node("SimulationRuntime");clock=root.get_node("GameClock")
var raw := FileAccess.get_file_as_bytes(OS.get_environment("THE_TREE_REPLAY_SNAPSHOT")).decompress(11411840,FileAccess.COMPRESSION_ZSTD)
var initial: Dictionary=bytes_to_var(raw)
runtime.initialize(clock,root.get_node("GameState"),int(initial[&"systems"][&"runtime"][&"world_seed"]))
check(runtime.restore_snapshot(initial),"fixed646 seed/context restore")
core=ClassDB.instantiate(&"TheTreeNumericCore")
for label: String in INDEX_CASES: index_case(label)
for label: String in SHAPE_CASES: shape_case(label)
reentry_case()
var fixtures: Dictionary=typed("fixtures",boundary_records)
core=null
var report := {"passed":failures.is_empty(),"checks":checks,"failures":failures,"pid":OS.get_process_id(),"case_count":boundary_records.size(),"fixtures":fixtures,"candidate":OS.get_environment("THE_TREE_PAIRED_CANDIDATE"),"unit_accepted":false,"performance_accepted":false,"Windows_accepted":false,"scope":"parent275 vs candidate303 finite index3/convertible shape2/nested same-goal1 only; deliberate errors from invalid parent/cell arrays and arbitrary reentry/script mutations not covered"}
var file := FileAccess.open(output.path_join("report.json"),FileAccess.WRITE)
if file==null:quit(98);return
file.store_string(JSON.stringify(report,"\t"));file.close()
print("Ready route boundary: %d checks, %d failures"%[checks,failures.size()]);quit(0 if failures.is_empty() else 1)