Files

89 lines
5.8 KiB
Python

# coding: utf-8
from pathlib import Path
import json,re
R=Path('/Users/korizatou114/Projects/とりにく工房ゲーム制作部');A=R/'artifacts/original-completion-2026-10-02';O=A/'p23-02-native-hot-loop-local-r329';assert not O.exists();O.mkdir()
def write(p,s):
with p.open('x') as f:f.write(s)
old=A/'p23-02-native-lazy-edge-cache-protocol-r143.gd';s=old.read_text();s=s.replace('extends SceneTree','extends RefCounted',1)
s=re.sub(r'func _initialize\(\) -> void:\n.*?(?=\nfunc )','',s,count=1,flags=re.S)
s=s[:s.index('func _run() -> void:')]
s+='''class ReentrantProvider extends RefCounted:
var core: Object
var cells: Array[Vector3i]
var indices: Dictionary
var goals: Dictionary
var entered := false
var inner_result: Dictionary
func edges(cell: Vector3i) -> Array:
if cell.x != 0: return []
if not entered:
entered = true
core.call("clear_edge_cache")
var inner := EdgeProvider.new()
inner.rows = [[[cells[1],9]], []]
inner_result = core.call("search_cached",cells,indices,0,goals,Callable(inner,"edges"))
return [[cells[1],7]]
func _reentrant_collision(core) -> Dictionary:
core.call("clear_edge_cache")
var cells: Array[Vector3i] = [Vector3i.ZERO,Vector3i(1,0,0)]
var indices: Dictionary = {cells[0]:0,cells[1]:1}
var goals: Dictionary = {cells[1]:true}
var provider := ReentrantProvider.new()
provider.core=core;provider.cells=cells;provider.indices=indices;provider.goals=goals
var outer: Dictionary = core.call("search_cached",cells,indices,0,goals,Callable(provider,"edges"))
_check(outer[&"status"] == "usable" and outer[&"cost_values"][1] == 7, "reentrant collision returns original converted outer row")
_check(provider.inner_result[&"status"] == "usable" and provider.inner_result[&"cost_values"][1] == 9, "inner populated same cache key before outer insertion")
var warm: Dictionary = core.call("search_cached",cells,indices,0,goals,Callable(provider,"edges"))
_check(warm[&"status"] == "usable" and warm[&"cost_values"][1] == 9, "warm preserves inner first cache publication")
var result := {"outer":outer,"inner":provider.inner_result,"warm":warm}
var ref: WeakRef = weakref(provider)
provider = null
_check(ref.get_ref() == null, "borrowed native cache retains no reentrant provider")
core.call("clear_edge_cache")
return result
func run_frozen(core, manifest_path: String) -> Dictionary:
var manifest: Dictionary = JSON.parse_string(FileAccess.get_file_as_string(manifest_path))
_check(manifest["cases"].size() == 50, "same frozen fifty-input scope")
for row: Dictionary in manifest["cases"]: _case(core,row)
_prefix_wrap(core,true)
_prefix_wrap(core,[Vector3i(2,0,0),false])
_shrink_transfer(core)
_cached_goals_and_reset(core)
_cached_prefix_wrap(core,true)
_cached_prefix_wrap(core,[Vector3i(2,0,0),false])
var collision := _reentrant_collision(core)
_warm_for_teardown(core)
return {"passed":failures.is_empty(),"checks":checks,"failures":failures,"cases":cases,"cached_cases":cached_cases,"reentrant_collision":collision,"unit_accepted":false,"performance_accepted":false}
'''
write(O/'protocol_helper.gd',s)
qa=(A/'p23-02-native-guest-bulk-local-r315.gd').read_text()
qa=qa.replace('var _bulk_records: Array = []','const ProtocolHelper = preload('+json.dumps(str(O/'protocol_helper.gd'))+')\n\nvar _bulk_records: Array = []',1)
a='\t_test_bulk_candidates()\n\tvar output := OS.get_environment("THE_TREE_RUNTIME_MONITOR_OUTPUT")';b='''\t_test_bulk_candidates()
var output := OS.get_environment("THE_TREE_RUNTIME_MONITOR_OUTPUT")
var protocol = ProtocolHelper.new()
var protocol_core: Object = ClassDB.instantiate(&"TheTreeNumericCore")
var protocol_report: Dictionary = protocol.run_frozen(protocol_core,'''+json.dumps(str(A/'p23-02-native-bridge-Godot-protocol-preparation-r73/pinned-inputs.json'))+''')
var core_ref: WeakRef = weakref(protocol_core)
protocol_core = null
_expect(core_ref.get_ref() == null, "combined protocol core with populated cache releases")
_checks += int(protocol_report["checks"])
_failures += protocol_report["failures"].size()
var protocol_file := FileAccess.open(output.path_join("protocol-report.json"),FileAccess.WRITE)
if protocol_file == null: quit(98); return
protocol_file.store_string(JSON.stringify(protocol_report,"\\t")+"\\n");protocol_file.close()
protocol = null''';assert a in qa;qa=qa.replace(a,b,1)
qa=qa.replace('"original_s3_invocations": 18,','"original_s3_invocations": 18, "protocol_cases": 50, "protocol_checks": int(protocol_report["checks"]),')
write(O/'local.gd',qa)
guard=(A/'p23-02-native-guest-bulk-local-r315/candidate-guarded.gd').read_text()
guard=guard.replace('p23-02-native-guest-bulk-local-r315.gd','p23-02-native-hot-loop-local-r329/local.gd').replace('p23-02-native-guest-bulk-local-r315/candidate.gdextension','p23-02-native-hot-loop-local-r329/candidate.gdextension')
write(O/'candidate-guarded.gd',guard)
runner=(A/'p23-02-native-guest-bulk-local-r315.py').read_text().replace('p23-02-native-guest-bulk-local-r315','p23-02-native-hot-loop-local-r329')
a=" fixture=output/'fixtures.varbytes';assert fixture.stat().st_size==report['fixture_bytes'] and r.sha(fixture)==report['fixture_sha256']"
b=a+"\n protocol=r.read(output/'protocol-report.json');assert protocol['passed'] and not protocol['failures'] and len(protocol['cases'])==50 and len(protocol['cached_cases'])==50 and protocol['checks']==report['protocol_checks']\n assert fixture.read_bytes()==Path(plan['original_Guest_fixture']['path']).read_bytes(), 'Unchanged full Guest53 original fixture bytes'"
assert a in runner;runner=runner.replace(a,b,1)
runner=runner.replace('Finite standalone Guest candidate ABI/local and18 affected original S3 methods only.','Finite Guest53 and18 affected original S3 methods plus frozen50 protocols/shrink/ownership/reentrant collision on same new bridge.')
write(A/'p23-02-native-hot-loop-local-r329.py',runner)
print('Prepared single-engine combined local/protocol QA. Engine0.')