Files
TheTree_mock/docs/plans/original-completion-2026-10-02/checkpoints/integer-window-codec-r290/p23-02-native-integer-window-codec-local-r292-r02.py

56 lines
6.8 KiB
Python

# coding: utf-8
from pathlib import Path
import hashlib,importlib.util,json,os,shutil,subprocess,sys,uuid
sys.dont_write_bytecode=True
R=Path(__file__).resolve().parents[2];A=R/'artifacts/original-completion-2026-10-02';D=R/'docs/plans/original-completion-2026-10-02';O=A/'p23-02-native-integer-window-codec-local-r292-r02';NAMES=['IMPLEMENTATION_PLAN.md','PROGRESS_INTEGRATION.md','work_packages.json','progress_snapshot.json']
def mod(name,p):
s=importlib.util.spec_from_file_location(name,p);m=importlib.util.module_from_spec(s);s.loader.exec_module(m);return m
def unpack(q):
raw=subprocess.run(['/opt/homebrew/bin/zstd','-d','-q','-c',q['path']],check=True,capture_output=True,timeout=10).stdout;assert len(raw)==q['uncompressed_bytes'] and hashlib.sha256(raw).hexdigest()==q['uncompressed_sha256'];return raw
def main():
r=mod('local260',R/'tools/run_all_tests.py');outer=mod('owned260',r.SUPPORT/'owned_outer.py');plan=r.read(O/'input.json');fixed=plan['pins'];assert not (O/'execution.json').exists()
source=r.source_refs(R);player=r.default_player(R);docs={n:r.sha(D/n) for n in NAMES};assert source==plan['source_before'] and player==plan['default_before'] and docs==plan['doc4_before']
prepath=A/'p23-02-native-integer-window-codec-local-preexecution-independent-review-r292-r02.json';pre=r.read(prepath);assert pre['execution_allowed'] and not pre['blockers']
for group in ['evidence_sha256','canonical_doc4_context_pins']:
for key,q in pre[group].items():
f=Path(q.get('path',key));assert f.stat().st_size==q['bytes'] and r.sha(f)==q['sha256']
root=r.read(O/'preexecution-root-verification.json');assert root['passed'] and root['review_sha256']==r.sha(prepath)
stage=Path(plan['stage']);parent=Path(plan['parent']);budget=stage/'scripts/core/performance_budget.gd';original=budget.read_bytes();modified=Path(fixed['modified_budget']['path']).read_bytes();public=(stage/'project.godot').read_bytes();patched=False
assert hashlib.sha256(original).hexdigest()==plan['original_budget_sha256']
def protect():
assert r.source_refs(R)==source and r.default_player(R)==player and {n:r.sha(D/n) for n in NAMES}==docs and r.inventory(r.SUPPORT)==plan['support_inventory']
assert r.inventory(parent,stage=True)==plan['expected_stage'] and r.inventory(stage,stage=True)==(plan['patched_stage'] if patched else plan['expected_stage'])
for key,q in fixed.items():
f=Path(q['path']);assert f.stat().st_size==q['bytes'] and r.sha(f)==q['sha256'],key
protect();phases=[];samples=[];error=None;cleanup=[];cleanup_errors=[]
try:
for mode in ['r257-r04']:
protect();assert not outer.native.helper['live_engines']() and shutil.disk_usage(A).free>=plan['capacity_floor_bytes']
if mode=='r257-r04':budget.write_bytes(modified);patched=True
protect();output=O/(mode+'-measurement');output.mkdir();ident=uuid.uuid4().hex;startup='TheTree-PCK-tests-'+ident+'-budget-startup';profile='TheTree-PCK-tests-'+ident+'-budget-runtime';assert not r.profile_path(startup).exists() and not r.profile_path(profile).exists()
env=r.fresh_environment(os.environ);env.update(THE_TREE_PACK_PROFILE_NAME=profile,THE_TREE_PACK_PROFILE_EXPECTED=str(r.profile_path(profile)),THE_TREE_PACK_PROFILE_REPORT=str(O/(mode+'-profile.json')),THE_TREE_RUNTIME_MONITOR_OUTPUT=str(output),THE_TREE_BUDGET_MODE=mode,THE_TREE_EXPECTED_BUDGET_SHA=fixed['modified_budget']['sha256'] if patched else plan['original_budget_sha256'])
(stage/'project.godot').write_bytes(r.private_project(public,startup));phase=O/mode;argv=[fixed['engine']['path'],'--headless','--path',str(stage),'--script',fixed['starter_'+mode]['path'],'--verbose','--log-file',str(phase/'engine-native.log')]
result,capture=outer.run_phase(argv,phase,90,env,now_fn=r.now,dump_fn=r.write,sha_fn=r.sha,live_engines_fn=outer.native.helper['live_engines']);row=dict(mode=mode,result=result,capture=capture);phases.append(row);r.write(O/(mode+'-phase.json'),row)
rp=output/'report.json';report=r.read(rp) if rp.exists() else None
if report is not None:samples.append(report)
assert result and result['exit_code']==0 and not result['error_lines'] and not result['timed_out'] and capture['passed']
logs=''.join((phase/n).read_text() for n in ['stdout.log','stderr.log','engine-native.log']);assert 'Orphan StringName:' not in logs and 'unclaimed string names' not in logs
assert report and report['passed'] and not report['failures'] and report['pid']==result['pid'] and report['mode']==mode and report['checks']==plan['expected_checks'] and report['case_count']==833 and report['codec_cases']==33
assert report['record_calls']==753 and report['guard_calls']==8 and report['getter_calls']==66 and report['clear_calls']==6
assert (phase/'stdout.log').read_text().count('Native Budget record local: %d checks, 0 failures'%plan['expected_checks'])==1 and (phase/'stdout.log').read_text().count('NATIVE_ADAPTER_LIBRARY_REGISTERED')==1
r.profile_gate(r.profile_path(profile),O/(mode+'-profile.json'),profile);unpack(report['fixtures']);unpack(report['codec_fixtures']);assert sum(f.stat().st_size for f in O.rglob('*') if f.is_file())<=16*1048576
(stage/'project.godot').write_bytes(public);budget.write_bytes(original);patched=False;protect()
assert unpack(samples[0]['fixtures'])==unpack(r.read(fixed['baseline_report']['path'])['fixtures']), 'new Budget fixture differs from accepted full original r260-r02 oracle'
except BaseException as caught:error=type(caught).__name__+': '+str(caught)
finally:
cleanup,cleanup_errors=outer.finish_captured(outer.OWNED)
if all(q['engine_ended'] is True for q in cleanup):budget.write_bytes(original);patched=False;(stage/'project.godot').write_bytes(public)
else:cleanup_errors.append('Budget/project restoration refused while owned child remains live')
guard_errors=[]
try:assert not patched and budget.read_bytes()==original;protect()
except BaseException as caught:guard_errors.append(type(caught).__name__+': '+str(caught))
passed=error is None and not guard_errors and not cleanup_errors and len(phases)==1 and len(samples)==1
r.write(O/'execution.json',dict(passed=passed,error=error,guard_errors=guard_errors,phases=phases,samples=samples,cleanup=cleanup,cleanup_errors=cleanup_errors,shared_Budget_restored_byteexact=not patched and budget.read_bytes()==original,input_source_default_doc4_preserved=not guard_errors,candidate_adopted=False,unit_accepted=False,performance_accepted=False,limitations=['Finite accepted original r260-r02 reused versus fresh candidate290/library291 Budget report/state/signal/ownership, and 33 separate engine codec fixtures only. Guard-only malformed/readonly API unsupported/no mutation; original error paths and arbitrary malformed states not accepted. No whole647/final172/impact/performance/OS/Windows/adoption/unit acceptance.']))
print(json.dumps(dict(passed=passed,error=error,guard_errors=guard_errors)),flush=True);return 0 if passed else 1
if __name__=='__main__':raise SystemExit(main())