import base64,hashlib,json,os,stat
from pathlib import Path
HERE=Path(__file__).resolve().parent
assert not (HERE/'manifest-blocked4.json').exists(),'No reseal'
verification={'HTTP':0,'DML':0,'DDL':0,'business_reached':False,'lanes':{}}
for lane in ['B','C']:
    root=HERE/'private-original'/lane;attempts=json.loads((root/'http-attempts-original.json').read_text());assert len(attempts)==2
    for a in attempts:
        w=json.loads((root/('wire-'+a['label']+'.json')).read_text());assert a['complete'] and base64.b64decode(a['body_base64']).decode()==w['body'];assert w['status']==404 and w['own_source_unchanged'];assert json.loads(w['body'])=={'code':'2','message':'Original lists readonly gate' if lane=='B' else 'Exact metadata CALL binds','data':[]}
        for e in w['native']:assert not e['queryString'].upper().startswith(('INSERT','UPDATE','DELETE','CREATE','ALTER','DROP'))
    r=json.loads((root/'resource-check.json').read_text());assert all(r[k] for k in ['own_worker_absent','own_port_closed','original_parent_present','request_absent','cache_absent']) and r['AppleDouble']==[]
    verification['HTTP']+=2;verification['lanes'][lane]={'actual_HTTP':2,'status':404,'cause':'harness omitted exact bootstrap config table; no business list execution'}
(HERE/'verification-blocked4.json').write_text(json.dumps(verification,ensure_ascii=False,indent=2)+'\n')
files=[p for p in HERE.iterdir() if p.is_file() and ('original' in p.name or p.name in ['seal-blocked4.py','verification-blocked4.json'])]+list((HERE/'private-original').rglob('*'));rows=[]
for p in sorted(set(files)):
    assert not p.is_symlink();rel=p.relative_to(HERE)
    if 'private-original' in rel.parts:os.chmod(p,0o700 if p.is_dir() else 0o600)
    if p.is_file():b=p.read_bytes();rows.append({'path':str(rel),'bytes':len(b),'sha256':hashlib.sha256(b).hexdigest(),'mode':oct(stat.S_IMODE(p.stat().st_mode))})
out={'scope':'original failed4 only; retry and candidates separate','files':rows};out['seal_sha256']=hashlib.sha256(json.dumps(out,ensure_ascii=False,sort_keys=True,separators=(',',':')).encode()).hexdigest();target=HERE/'manifest-blocked4.json';target.write_text(json.dumps(out,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'files':len(rows),'file_sha256':hashlib.sha256(target.read_bytes()).hexdigest(),'canonical_sha256':out['seal_sha256'],'HTTP':4,'business_reached':False}))
