Files
MeltMind/tools/verify_gre24_v4_manual_receive.py
T

67 lines
3.5 KiB
Python

"""Verify Yanqi's completed manual receive; never download or start science."""
import fcntl
import hashlib
import json
import os
from pathlib import Path
import time
ROOT=Path('/home/frank14f/optane/MeltMind/artifacts/gre24-v4-reproduction-2026-11-16')
def save(path,value):
temp=path.with_suffix('.tmp')
temp.write_text(json.dumps(value,indent=2)+'\n')
temp.replace(path)
def main():
root=ROOT/'data'
with (root/'manual-verification.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (root/'manual-verification-started.json').exists():
raise FileExistsError('Inspect prior verification before any repeat')
start=time.monotonic();cpu=time.process_time()
save(root/'manual-verification-started.json',dict(pid=os.getpid(),unix=time.time(),
source='Manual receive by Yanqi',ruling='1794815915.570349'))
source=root/'data.zip.partial';target=root/'data.zip'
try:
if target.exists() or Path(str(source)+'.aria2').exists():
raise ValueError('Unexpected existing target or active aria2 control file')
initial=source.stat()
if initial.st_size!=35925187752:
raise ValueError('Size differs from official archive')
md5=hashlib.md5();sha256=hashlib.sha256();count=0;last=0
with source.open('rb') as stream:
for block in iter(lambda:stream.read(8*2**20),b''):
md5.update(block);sha256.update(block);count+=len(block)
if time.monotonic()-last>=5:
save(root/'manual-verification-progress.json',dict(status='HASHING',bytes_hashed=count,
expected_bytes=initial.st_size,pid=os.getpid(),unix=time.time()))
last=time.monotonic()
final=source.stat()
if (initial.st_size,initial.st_mtime_ns,initial.st_ino)!=(final.st_size,final.st_mtime_ns,final.st_ino):
raise ValueError('Archive changed during verification')
if md5.hexdigest()!='4973f24e12a38c87c31cf129be1a3e3b':
save(root/'manual-hash-mismatch.json',dict(observed_md5=md5.hexdigest(),sha256=sha256.hexdigest()))
raise ValueError('Official MD5 mismatch; manual source retained')
source.rename(target)
stat=target.stat()
receipt=dict(status='VERIFIED',archive=str(target),bytes=stat.st_size,mtime_ns=stat.st_mtime_ns,
inode=stat.st_ino,md5=md5.hexdigest(),sha256=sha256.hexdigest(),unix=time.time(),
elapsed_seconds=time.monotonic()-start,intake_cpu_seconds=time.process_time()-cpu,
source='Manual receive by Yanqi; independently verified by MeltAstra',
original_manual_filename=str(source),user_report_separate_from_independent_hash=True,
authorizing_ruling='1794815915.570349',science_started=False,
original_receiver_remains_user_stopped=True)
save(root/'manual-receive-verification.json',receipt)
save(root/'archive-verification.json',receipt)
return 0
except Exception as error:
save(root/'manual-verification-failure.json',dict(status='FAILED',error_type=type(error).__name__,
message=str(error),unix=time.time(),intake_cpu_seconds=time.process_time()-cpu,science_started=False))
return 1
if __name__=='__main__':raise SystemExit(main())