Files
TheTree_mock/docs/plans/original-completion-2026-10-02/checkpoints/native-input-copy-r332-r337/096-p23-02-native-input-copy-local-r335.py

81 lines
6.9 KiB
Python

# coding: utf-8
"""One finite cold native guest projection QA against original Runtime golden; no full regression."""
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'
O=A/'p23-02-native-input-copy-local-r335';D=R/'docs/plans/original-completion-2026-10-02'
NAMES=['IMPLEMENTATION_PLAN.md','PROGRESS_INTEGRATION.md','work_packages.json','progress_snapshot.json']
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 unpack(ref):
raw=subprocess.run(['/opt/homebrew/bin/zstd','-d','-q','-c',ref['path']],capture_output=True,check=True,timeout=10).stdout
assert len(raw)==ref['uncompressed_bytes'] and hashlib.sha256(raw).hexdigest()==ref['uncompressed_sha256']
return raw
def main():
r=mod('impact_runner',R/'tools/run_all_tests.py');outer=mod('impact_owned',r.SUPPORT/'owned_outer.py');plan=r.read(O/'input.json')
assert not (O/'execution.json').exists()
fixed=plan['pins'];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']
stage=Path(plan['stage']);parent=Path(plan['parent']);public=(stage/'project.godot').read_bytes()
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
assert r.inventory(parent,stage=True)==plan['expected_stage'] and r.inventory(stage,stage=True)==plan['expected_stage']
assert r.inventory(r.SUPPORT)==plan['support_inventory']
for key,q in fixed.items():
p=Path(q['path']);assert p.stat().st_size==q['bytes'] and r.sha(p)==q['sha256'],key
protect()
review=r.read(Path(fixed['host_review']['path']))
assert not review['blockers'] and review['host_build_accepted']
pre=r.read(A/'p23-02-native-input-copy-local-preexecution-independent-review-r335.json')
assert pre['execution_allowed'] and not pre['blockers']
for group in ('evidence_sha256','canonical_doc4_context_pins'):
for q in pre[group].values():
p=Path(q['path']);assert p.stat().st_size==q['bytes'] and r.sha(p)==q['sha256']
assert r.read(O/'preexecution-root-verification.json')['passed']
phases=[];samples=[];error=None;cleanup=[];cleanup_errors=[]
try:
for spec in plan['specs']:
name=spec['name'];protect()
assert sum(p.stat().st_size for p in O.rglob('*') if p.is_file())<=16*1048576
assert not outer.native.helper['live_engines']() and shutil.disk_usage(A).free >= plan['capacity_floor_bytes']
output=O/(name+'-measurement');output.mkdir();ident=uuid.uuid4().hex
startup='TheTree-PCK-tests-'+ident+'-impact-startup';profile='TheTree-PCK-tests-'+ident+'-impact-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/(name+'-profile.json')),THE_TREE_RUNTIME_MONITOR_OUTPUT=str(output),THE_TREE_REPLAY_SNAPSHOT=fixed['fixture']['path'],THE_TREE_CANDIDATE_ORACLE=fixed['oracle']['path'],THE_TREE_PAIRED_CANDIDATE='r333-library334',THE_TREE_PAIRED_SAMPLE=name)
(stage/'project.godot').write_bytes(r.private_project(public,startup));phase=O/name
argv=[fixed['engine']['path'],'--headless','--path',str(stage),'--script',fixed['starter_'+name]['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(name=name,result=result,capture=capture);phases.append(row);r.write(O/(name+'-phase.json'),row)
report_path=output/'report.json';report=r.read(report_path) if report_path.exists() else None
if report is not None:samples.append(dict(name=name,report=report))
assert result is not None 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['checks']==spec['expected_checks']
assert (phase/'stdout.log').read_text().count(spec['label']+'%d checks, 0 failures'%report['checks'])==1
assert (phase/'stdout.log').read_text().count('NATIVE_ADAPTER_LIBRARY_REGISTERED')==1
r.profile_gate(r.profile_path(profile),O/(name+'-profile.json'),profile)
if name=='runtime':
golden=r.read(Path(fixed['golden_runtime']['path']))
for field in ['candidates','after_evaluation']:assert unpack(report[field])==unpack(golden[field]),field+' full typed golden'
assert report['candidate_count']==150 and report['batch_released']
else:
assert report['case_count']==spec['case_count']
unpack(report['fixtures'])
assert sum(p.stat().st_size for p in O.rglob('*') if p.is_file())<=16*1048576
(stage/'project.godot').write_bytes(public);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):(stage/'project.godot').write_bytes(public)
else:cleanup_errors.append('Project restoration refused while owned child remains live')
guard_errors=[]
try: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)==4 and len(samples)==4
r.write(O/'execution.json',dict(passed=passed,error=error,guard_errors=guard_errors,phases=phases,samples=samples,cleanup=cleanup,cleanup_errors=cleanup_errors,input_source_default_doc4_preserved=not guard_errors,candidate_adopted=False,unit_accepted=False,performance_accepted=False,normal_OS_accepted=False,Windows_accepted=False,limitations=['Four finite local QA engines for r333/library334: six parent shapes,19 nearest paths,4 input-key projection shapes and150 Runtime candidates/full evaluation state. Not invalid-index errors, arbitrary reentry, whole647, performance, full172, OS, Windows or adoption.']))
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())