55 lines
6.3 KiB
Python
55 lines
6.3 KiB
Python
# coding: utf-8
|
|
from pathlib import Path
|
|
import importlib.util,json,hashlib,os,uuid,shutil,subprocess,traceback,sys
|
|
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-current-phase-diagnostic-r338'
|
|
def mod(n,p):
|
|
s=importlib.util.spec_from_file_location(n,p);m=importlib.util.module_from_spec(s);s.loader.exec_module(m);return m
|
|
def unpack(p):return subprocess.run(['/opt/homebrew/bin/zstd','-d','-q','-c',str(p)],check=True,capture_output=True,timeout=10).stdout
|
|
def main():
|
|
r=mod('r338',R/'tools/run_all_tests.py');outer=mod('o338',r.SUPPORT/'owned_outer.py');p=r.read(O/'input.json');assert not (O/'execution.json').exists()
|
|
prepath=A/'p23-02-current-phase-diagnostic-preexecution-independent-review-r338.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(p['stage']);public=(stage/'project.godot').read_bytes();budget=stage/'scripts/core/performance_budget.gd';budget_before=budget.read_bytes();patched=False
|
|
fixed=p['pins'];source=r.source_refs(R);default=r.default_player(R);docs={n:r.sha(D/n) for n in p['doc4_before']};assert source==p['source_before'] and default==p['default_before'] and docs==p['doc4_before']
|
|
def protect():
|
|
assert r.source_refs(R)==source and r.default_player(R)==default and {n:r.sha(D/n) for n in docs}==docs and r.inventory(r.SUPPORT)==p['support_inventory']
|
|
assert r.inventory(stage,stage=True)==(p['patched_stage'] if patched else p['expected_stage'])
|
|
for q in fixed.values():
|
|
f=Path(q['path']);assert f.stat().st_size==q['bytes'] and r.sha(f)==q['sha256']
|
|
for row in p['manifest'].values():
|
|
for key in ['before','after']:
|
|
q=row[key];f=Path(q['path']);assert f.stat().st_size==q['bytes'] and r.sha(f)==q['sha256']
|
|
protect();error=None;guard_errors=[];cleanup=[];cleanup_errors=[];result=None;capture=None;report=None
|
|
try:
|
|
assert not outer.native.helper['live_engines']() and shutil.disk_usage(A).free>=p['capacity_floor_bytes']
|
|
for rel,row in p['manifest'].items():(stage/rel).write_bytes(Path(row['after']['path']).read_bytes())
|
|
budget.write_bytes(Path(fixed['modified_budget']['path']).read_bytes());patched=True;protect()
|
|
output=O/'measurement';output.mkdir();ident=uuid.uuid4().hex;startup='TheTree-PCK-tests-'+ident+'-diagnostic-startup';profile='TheTree-PCK-tests-'+ident+'-diagnostic-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),THE_TREE_REPLAY_SNAPSHOT=fixed['fixture']['path'],THE_TREE_CANDIDATE_ORACLE=fixed['oracle']['path'],THE_TREE_PAIRED_CANDIDATE='r333-diagnostic',THE_TREE_PAIRED_SAMPLE='r338',THE_TREE_EXPECTED_PATH_SHA=fixed['original_path']['sha256'],THE_TREE_EXPECTED_BUDGET_SHA=fixed['modified_budget']['sha256'])
|
|
(stage/'project.godot').write_bytes(r.private_project(public,startup));phase=O/'engine';argv=[fixed['engine']['path'],'--headless','--path',str(stage),'--script',fixed['starter']['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']);r.write(O/'phase.json',dict(result=result,capture=capture))
|
|
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 and (phase/'stdout.log').read_text().count('NATIVE_ADAPTER_LIBRARY_REGISTERED')==1
|
|
report=r.read(output/'report.json');assert report['passed'] and not report['failures'] and report['pid']==result['pid'] and report['checks']==16 and report['candidate']=='r333-diagnostic' and report['sample']=='r338'
|
|
assert (phase/'stdout.log').read_text().count('Phase diagnostic whole647: 16 checks, 0 failures')==1
|
|
after=unpack(report['after647']['path']);oracle=unpack(fixed['oracle']['path']);assert after==oracle and len(after)==11487732 and hashlib.sha256(after).hexdigest()==report['after647']['uncompressed_sha256']
|
|
raw=unpack(report['metrics']['path']);assert len(raw)==report['metrics']['uncompressed_bytes'] and hashlib.sha256(raw).hexdigest()==report['metrics']['uncompressed_sha256']
|
|
r.profile_gate(r.profile_path(profile),O/'profile.json',profile);assert sum(f.stat().st_size for f in O.rglob('*') if f.is_file())<=p['measurement_cap_bytes']
|
|
except BaseException:error=traceback.format_exc()
|
|
finally:
|
|
cleanup,cleanup_errors=outer.finish_captured(outer.OWNED)
|
|
if all(q['engine_ended'] is True for q in cleanup):
|
|
for rel,row in p['manifest'].items():(stage/rel).write_bytes(Path(row['before']['path']).read_bytes())
|
|
budget.write_bytes(budget_before);(stage/'project.godot').write_bytes(public);patched=False
|
|
else:cleanup_errors.append('Restoration refused while captured owned child remains live')
|
|
try:assert not patched;protect()
|
|
except BaseException:guard_errors.append(traceback.format_exc())
|
|
passed=error is None and not guard_errors and not cleanup_errors
|
|
r.write(O/'execution.json',dict(passed=passed,error=error,guard_errors=guard_errors,result=result,capture=capture,report=report,cleanup=cleanup,cleanup_errors=cleanup_errors,source_default_doc4_support_stage_preserved=not guard_errors,unit_accepted=False,performance_accepted=False,candidate_adopted=False,limits=['One instrumented current r333/library334 cold646 tick. Nested inclusive measurements overlap and include instrumentation. No CPU sums/subtraction, uninstrumented comparisons, stable gain/P95/budget/final regression/Main/x3/OS/Windows 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())
|