45 lines
5.4 KiB
Python
45 lines
5.4 KiB
Python
# coding: utf-8
|
|
from pathlib import Path
|
|
import hashlib,importlib.util,json,os,shutil,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-guest-need-normalization-local-r299-r02'
|
|
def mod(name,path):
|
|
s=importlib.util.spec_from_file_location(name,path);m=importlib.util.module_from_spec(s);s.loader.exec_module(m);return m
|
|
def main():
|
|
r=mod('r299',R/'tools/run_all_tests.py');outer=mod('outer299',r.SUPPORT/'owned_outer.py');plan=r.read(O/'input.json');assert not (O/'execution.json').exists()
|
|
prepath=A/'p23-02-guest-need-normalization-local-preexecution-independent-review-r299-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():
|
|
p=Path(q.get('path',key));assert p.stat().st_size==q['bytes'] and r.sha(p)==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']);guest=Path(plan['guest_source']);original=guest.read_bytes();modified=Path(plan['modified_guest']).read_bytes();public=(stage/'project.godot').read_bytes();patched=False
|
|
def protect():
|
|
assert r.source_refs(R)==plan['source_before'] and r.default_player(R)==plan['default_before'];assert {n:r.sha(D/n) for n in plan['doc4_before']}==plan['doc4_before'];assert r.inventory(r.SUPPORT)==plan['support_inventory']
|
|
assert r.inventory(parent,stage=True)==plan['expected_stage'];assert r.inventory(stage,stage=True)==(plan['patched_stage'] if patched else plan['expected_stage'])
|
|
for key,q in plan['pins'].items():
|
|
p=Path(q['path'])
|
|
if p==guest:assert p.read_bytes()==(modified if patched else original)
|
|
else:assert p.stat().st_size==q['bytes'] and r.sha(p)==q['sha256'],key
|
|
protect();assert not outer.native.helper['live_engines']();assert shutil.disk_usage(A).free>=plan['capacity_floor_bytes']+plan['output_budget_bytes']
|
|
error=None;phase=None;report=None;cleanup=[];cleanup_errors=[]
|
|
try:
|
|
guest.write_bytes(modified);patched=True;protect();output=O/'measurement';output.mkdir();ident=uuid.uuid4().hex;startup='TheTree-PCK-tests-'+ident+'-needs-startup';profile='TheTree-PCK-tests-'+ident+'-needs-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/'profile.json'),THE_TREE_RUNTIME_MONITOR_OUTPUT=str(output))
|
|
(stage/'project.godot').write_bytes(r.private_project(public,startup));argv=[plan['engine_path'],'--headless','--path',str(stage),'--script',str(O/'guarded.gd'),'--verbose','--log-file',str(O/'engine/engine-native.log')]
|
|
result,capture=outer.run_phase(argv,O/'engine',plan['timeout_seconds'],env,now_fn=r.now,dump_fn=r.write,sha_fn=r.sha,live_engines_fn=outer.native.helper['live_engines']);phase=dict(result=result,capture=capture);r.write(O/'phase.json',phase)
|
|
rp=output/'report.json';report=r.read(rp) if rp.exists() else None;assert result and result['exit_code']==0 and not result['error_lines'] and not result['timed_out'] and capture['passed'];assert report and report['passed'] and not report['failures'] and report['checks']==plan['expected_checks'] and report['cases']==plan['local_cases'] and report['callback_cases']==2 and report['scalar_state_cases']==plan['scalar_state_cases'] and report['fixture_rows']==plan['fixture_rows'] and report['pid']==result['pid']
|
|
assert [(q['shape'],q['mode'],q['calls']) for q in report['timings']]==[(shape,mode,plan['microbenchmark_calls_each']) for shape in ['single_need','six_needs'] for mode in ['original','candidate']]
|
|
logs=''.join((O/'engine'/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;r.profile_gate(r.profile_path(profile),O/'profile.json',profile)
|
|
assert sum(p.stat().st_size for p in O.rglob('*') if p.is_file())<=plan['output_budget_bytes'];(stage/'project.godot').write_bytes(public);guest.write_bytes(original);patched=False;protect()
|
|
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):guest.write_bytes(original);patched=False;(stage/'project.godot').write_bytes(public)
|
|
else:cleanup_errors.append('Restoration refused while owned child remains live')
|
|
guard_errors=[]
|
|
try:assert guest.read_bytes()==original and not patched;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 phase is not None and report is not None
|
|
r.write(O/'execution.json',dict(passed=passed,error=error,guard_errors=guard_errors,phase=phase,report=report,cleanup=cleanup,cleanup_errors=cleanup_errors,source_default_doc4_support_stage_preserved=not guard_errors,guest_project_restored_byteexact=not patched,compiler_runs=0,unit_accepted=False,performance_accepted=False,candidate_adopted=False));print(json.dumps(dict(passed=passed,error=error,guard_errors=guard_errors,timings=report.get('timings') if report else None)),flush=True);return 0 if passed else 1
|
|
if __name__=='__main__':raise SystemExit(main())
|