Preserve production code, regression fixtures, audio assets and provenance, test infrastructure, and the original-completion plan and progress ledger. Final game and Windows acceptance remain pending; excluded local artifacts and native experiments are not part of this snapshot.
103 lines
12 KiB
Python
103 lines
12 KiB
Python
"""Independent guarded-standard protocol reader; raw and Runtime bytes unchanged."""
|
|
from pathlib import Path
|
|
import hashlib, importlib.util, json, re
|
|
HERE=Path(__file__).resolve().parent
|
|
def load(name,path):
|
|
spec=importlib.util.spec_from_file_location(name,path);value=importlib.util.module_from_spec(spec);spec.loader.exec_module(value);return value
|
|
def read(path):return json.loads(Path(path).read_bytes())
|
|
def sha(path):return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
|
def require(ok,reason):
|
|
if not ok:raise AssertionError(reason)
|
|
def review(out,root,expected,contracts,owner_pid):
|
|
out=Path(out);root=Path(root);runner=load('guarded_reader_exact_runner',HERE.parent/'run_all_tests.py')
|
|
marker=load('guarded_reader_marker',HERE.parent/'strict_test_markers.py')
|
|
outer=load('guarded_reader_owned',HERE/'owned_outer.py');diagnostics=load('guarded_reader_diagnostics',HERE/'diagnostic_gate.py')
|
|
owners=load('guarded_reader_ordinary',HERE/'ordinary_proof_gate.py');audio=load('guarded_reader_audio',HERE/'audio_evidence_gate.py')
|
|
initial=read(out/'runner-input.json');ended=read(out/'runner-ended.json');rows=read(out/'all-tests.json') if (out/'all-tests.json').exists() else []
|
|
paths=['tests/run_tests.gd']+sorted(n for n in expected if n.startswith('tests/') and n.endswith('.gd') and Path(n).name.startswith('test') and 'export'not in Path(n).parts and n!='tests/s0/test_kernel_and_save.gd')
|
|
reviewed=[];errors=[];actual_pids=[];policy=read(HERE/'suite-policy.json')
|
|
require(initial['protocol']==ended['protocol']=='guarded-standard-v1' and initial['owner_runner_pid']==ended['owner_runner_pid']==owner_pid,'actual in-process runner owner/protocol')
|
|
require(initial['project_root']==str(root) and initial['roster']==paths and initial['selected_source_map']==expected,'literal logical original suite/source roster')
|
|
require(initial['runner_sha256']==expected['tools/run_all_tests.py'] and initial['marker_module_sha256']==expected['tools/strict_test_markers.py'],'actual runner/marker source')
|
|
require(ended['run_id']==initial['run_id'] and ended['all_tests_sha256']==(sha(out/'all-tests.json') if rows else None),'actual result identity/SHA')
|
|
stage=Path(initial['stage']);require(stage==out/'stage' and stage.is_dir() and not stage.is_symlink(),'one owned private stage')
|
|
phases=ended['phases'];logical=[('import',None),('parse',None)]+[(str(i).zfill(3),n)for i,n in enumerate(paths)]
|
|
require([(p['phase'],p['test'])for p in phases]==logical[:len(phases)] and len(phases)<=len(logical),'prefix-only import/parse/original suite order')
|
|
require([r['test']for r in rows]==[p['test']for p in phases if p['test'] is not None],'all actual suites correspond one phase')
|
|
previous={};expected_stage={n:{'bytes':(stage/n).stat().st_size,'sha256':digest}for n,digest in expected.items()}
|
|
for index,phase in enumerate(phases):
|
|
label=phase['phase'];test=phase['test'];folder=out/label;source=stage/test if test else None
|
|
try:
|
|
raw_stdout=(folder/'stdout.log').read_text();raw_stderr=(folder/'stderr.log').read_text();raw=raw_stdout+raw_stderr
|
|
native=folder/'engine-native.log';result=read(folder/'process.json');start=read(folder/'started.json');end=read(folder/'ended.json')
|
|
pid=result['pid'];require(type(pid)is int and pid>0 and pid not in actual_pids,'actual distinct native PID');actual_pids.append(pid)
|
|
for receipt in [start,end]:require(receipt['actual_pid']==pid and receipt['command']==phase['command'] and receipt['owner_pid']==owner_pid,'actual START/END owner/argv/PID')
|
|
require(start['monotonic_ns']<=end['monotonic_ns'],'actual start/end monotonic order')
|
|
require(result==phase['native_process'] and result['stdout_sha256']==sha(folder/'stdout.log') and result['stderr_sha256']==sha(folder/'stderr.log'),'immutable process receipt/raw streams')
|
|
require(phase['raw_native_log']=={'path':str(native),'bytes':native.stat().st_size,'sha256':sha(native)},'absolute native log size/SHA')
|
|
require(phase['command'][:4]==[initial['engine'],'--headless','--path',str(stage)] and phase['command'][-2:]==['--log-file',str(native)],'actual private resource root/logger binding')
|
|
if label=='import':require(phase['command'][4:-2]==['--editor','--import','--quit','--verbose'],'actual import recipe')
|
|
else:
|
|
script=out/'bootstrap/parse_full_dependencies.gd' if label=='parse' else out/'starters'/(label+'.gd')
|
|
require(phase['command'][4:-2]==['--script',str(script),'--verbose'] and sha(script)==phase['starter_sha256'],'actual external bootstrap argv/bytes')
|
|
if test:
|
|
text='extends '+json.dumps('res://'+test)+'\nconst Guard := preload('+json.dumps(str(out/'bootstrap/profile_guard.gd'))+')\nfunc _initialize() -> void:\n\tif not Guard.activate():\n\t\tquit(97)\n\t\treturn\n\tsuper._initialize()\n'
|
|
require(script.read_text()==text and phase['logical_script']=='res://'+test,'literal logical suite binding; actual argv is never rewritten')
|
|
finite=diagnostics.review_streams(outer.native,{'stdout':raw_stdout,'stderr':raw_stderr,'native_file':native.read_text()},test,source)
|
|
require(finite==phase['finite_original_diagnostic_review'] and diagnostics.diagnostic_result_gate(result,finite)
|
|
and runner.process_gate(result,finite['allowed_e31_error_lines']),'strict actual raw/error/leak/finite321 contract')
|
|
capture=phase['outer_actual_capture'];require(capture['actual_captured_pids']==[pid] and capture['passed'] is True and capture['all_captured_ended'] is True and capture['outer_cleanup_errors']==[],'actual captured native ownership')
|
|
before=read(out/(label+'-startup-profile-before.json'));startup=phase['whole_startup_profile_after']
|
|
require(before=={'path':startup['path'],'existed':False,'files':{},'before_native_spawn':True} and runner.inventory(startup['path'])==startup['files'],'full fresh startup profile including logger/recovery locks')
|
|
require(startup['path']==str(runner.profile_path(phase['profile_startup_name'])),'owned startup name/path')
|
|
if label!='import':
|
|
profile=phase['whole_runtime_profile_after'];require(runner.inventory(profile['path'])==profile['files'],'full actual runtime private profile')
|
|
actual=runner.profile_gate(Path(profile['path']),out/(label+'-profile.json'),phase['controlled_environment']['THE_TREE_PACK_PROFILE_NAME'])
|
|
require(actual==phase['actual_private_profile'],'all five actual Guard conditions and whole runtime profile')
|
|
if label=='parse':
|
|
count=len(read(out/'parse-paths.json'));matches=re.findall(r'(?m)^FULL_DEPENDENCY_PARSE checks=([0-9]+) failures=([0-9]+)\n',raw)
|
|
require(matches==[(str(count),'0')] and phase['actual_parse_checks']==count,'actual all-source parse count')
|
|
if test:
|
|
parsed=marker.parse_raw(test,raw,contracts,expected[test]);require(parsed['passed'] and parsed==phase['completion'],'raw original marker schema/count/phase')
|
|
raw_path=out/(test.replace('/','__')+'.log');require(raw_path.read_text()==raw and sha(raw_path)==phase['log_sha256'],'whole stdout/stderr copied without modification')
|
|
require(phase['source_sha256']==phase['source_sha256_end']==expected[test] and sha(source)==expected[test],'literal suite source SHA')
|
|
p=runner.phase_policy(test,source,policy['suite_policies']);require(p==phase['policy'],'exact proof-policy source')
|
|
route=policy['outside_routes'].get(test)
|
|
if route:require(runner.routed_report(out/(label+'-evidence'),route,test,pid,raw,stage,expected[test])==phase['outside_report'],'fresh report provenance')
|
|
proof=out/(label+'-teardown')
|
|
if p['ordinary_cleanup_prepared']:require(owners.ordinary_gate(proof,pid,out,p['ordinary_control_labels'])==phase['ordinary_owner_pairs'],'whole ordinary owner pairs/control/WeakRef proof')
|
|
if p['old_bounded_teardown']or test=='tests/ui/test_ui_audio_feedback.gd':require(audio.teardown_gate(proof,pid,out)==phase['old_bounded_proof'],'old bounded wholetyped/WeakRef proof')
|
|
if test=='tests/ui/test_ui_audio_feedback.gd':
|
|
audio_dir=out/(label+'-audio-proof')
|
|
require(audio.command_gate(audio_dir/'actual-command-result-buffer-proof.json',audio_dir,pid)==phase['actual_command_evidence'],'whole command DTO15typed pairs')
|
|
require(audio.ogg_gate(audio_dir/'actual-ogg-decode-player-state.json',pid,expected)==phase['actual_ogg_evidence'],'actual Ogg evidence; hearing remains false')
|
|
reviewed.append({'test':test,'actual_checks':parsed['checks'],'passed':True,'source_sha256':expected[test],
|
|
'log':phase['log'],'log_sha256':phase['log_sha256'],'actual_pid':pid,'engine_ended':True,'completion_marker':parsed['marker'],
|
|
'errors':[],'known_unicode_diagnostic_count':parsed['known_unicode_diagnostic_count'],'unrecognized_unicode_diagnostic_count':parsed['unrecognized_unicode_diagnostic_count']})
|
|
requested=policy['fixed_generated_report_routes'].get(test,[]) if test else []
|
|
require(set(phase['generated_reports'])==set(requested),'fixed generated report exact per-suite set')
|
|
for n,pin in phase['generated_reports'].items():
|
|
require(n not in previous and sha(stage/n)==pin['sha256'] and (stage/n).stat().st_size==pin['bytes']
|
|
and pin['actual_engine_pid']==pid and pin['producer_test']==test and pin['producer_source_sha256']==expected[test]
|
|
and pin['payload_modified'] is False,'fresh actual report/PID/source/size/SHA')
|
|
previous[n]={'bytes':pin['bytes'],'sha256':pin['sha256']}
|
|
require(phase['passed'] is True and phase['failed'] is False and phase['default_player_entire_profile_unchanged'] is True,'strict phase accepted')
|
|
except BaseException as caught:
|
|
errors.append(label+': '+type(caught).__name__+': '+str(caught))
|
|
if test:
|
|
if reviewed and reviewed[-1]['test']==test:reviewed.pop()
|
|
reviewed.append({'test':test,'actual_checks':phase.get('reported_checks'),'passed':False,'errors':[errors[-1]]})
|
|
require(runner.inventory(stage,stage=True)==dict(expected_stage,**previous),'complete stage source/UID/declared report inventory')
|
|
context=runner.totals(rows,paths)
|
|
require(all(ended[k]==v for k,v in context.items()),'partial actual counts/NULL metadata derived from real rows')
|
|
require(ended['actual_captured_PIDs']==actual_pids and len(set(actual_pids))==len(actual_pids),'actual all native captured PID set')
|
|
require(len(ended['final_owned_cleanup'])==len(actual_pids) and all(r['pid']in actual_pids and r['engine_ended']is True and not r['outer_cleanup_errors'] and not r['cleanup']['errors']for r in ended['final_owned_cleanup']),'bounded cleanup of exactly actual objects')
|
|
require(ended['engine_ended'] is True and ended['cleanup_errors']==[] and ended['guard_errors']==[],'all actual engine ended/whole guards')
|
|
require(ended['default_player_after']==initial['default_player_before']==runner.default_player(root),'whole default player including logs/lock exact')
|
|
passed=not errors and ended['passed']is True and ended['error']is None and len(phases)==len(logical) and [r['test']for r in reviewed]==paths and all(r['passed']for r in reviewed)
|
|
return {'passed':passed,'rows':reviewed,'collector_errors':errors,'actual_captured_PIDs':actual_pids,
|
|
'actual_native_phases':len(phases),'actual_parse_checks':next((p.get('actual_parse_checks')for p in phases if p['phase']=='parse'),None),
|
|
'actual_all_roster_checks':context['actual_all_roster_checks'],'available_marker_checks':context['available_marker_checks'],
|
|
'strict_accepted_checks':context['strict_accepted_checks'],'remaining_unexecuted_tests':context['remaining_unexecuted_tests'],
|
|
'missing_marker_paths':context['missing_marker_paths'],'Runtime_typed_normalizations':0,'native_Windows':'pending','formal_acceptance':False}
|