Files
WoW-Hybrid-gateway/tests/map_magma_count0_tail_candidate_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

100 lines
9.7 KiB
Python

"""Changed-only Source count0-tail cohort; strict3/alpha producer proofs reused."""
from pathlib import Path
import hashlib,json,struct,sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from map_asset_preflight import _adt_split_records as records,_adt_split_chunk as chunk,adt_root_magma_candidate,adt_tex0_alpha8_candidate
J=Path('runtime/continuation-20261027/Source-lava-class2-contract/count0-supported-extension');O=J/'private-components';O.mkdir(exist_ok=True)
result=J/'focused-result.private.json';assert not result.exists()
inputs=json.loads((J/'new-three-inputs.private.json').read_text())['rows'];strict=json.loads(Path('runtime/continuation-20261027/Source-lava-class2-contract/magma-strict-three-component.private.json').read_text())
flow=json.loads(Path('runtime/continuation-20261027/Source-lava-flow-query-contract/handoff.json').read_text());assert flow['literal_count0_tail_no_effect_in_proved_consumers'] and flow['nonzero_count_flow_held']
R=J/'completed-new-ROOT-rows.private.jsonl';T=J/'completed-new-TEX-rows.private.jsonl';roots=[json.loads(x) for x in R.read_text().splitlines()] if R.exists() else [];texs=[json.loads(x) for x in T.read_text().splitlines()] if T.exists() else []
def append(p,row):
with p.open('a') as f:f.write(json.dumps(row,separators=(',',':'))+'\n')
def encode(rr):return b''.join(chunk(t,p)+z for t,p,z in rr)
def verify_root(raw,out):
aa,bb=records(raw),records(out);assert [(t,p,z) for t,p,z in aa if t not in ('MCNK','MHDR','MH2O')]==[(t,p,z) for t,p,z in bb if t not in ('MCNK','MHDR','MH2O')]
ha=next(p for t,p,z in aa if t=='MHDR');hb=next(p for t,p,z in bb if t=='MHDR');assert all(ha[n*4:n*4+4]==hb[n*4:n*4+4] for n in range(16) if n not in (9,10,11))
mh=next(p for t,p,z in bb if t=='MH2O');count=vertices=magma=water=0
before=[p for t,p,z in aa if t=='MCNK'];after=[p for t,p,z in bb if t=='MCNK'];assert len(before)==len(after)==256
for p,q in zip(before,after):
w,v=struct.unpack_from('<32I',p),struct.unpack_from('<32I',q);assert v[0]==w[0]&~0x3c and v[24:26]==(0,0);assert all(w[n]==v[n] for n in range(1,32) if n not in (22,24,25,29))
a,b=records(p[128:]),records(q[128:]);assert [(t,d,z) for t,d,z in a if t!='MCLQ']==b
off,n,attrs=struct.unpack_from('<III',mh,(w[2]*16+w[1])*12);assert n==(w[0]&0x3c).bit_count()
if not n:assert(off,attrs)==(0,0);continue
rawblock=next(d for t,d,z in a if t=='MCLQ')
for k in range(n):
block=rawblock[k*804:(k+1)*804];assert struct.unpack_from('<I',block,720)[0]==0
ty,fmt,lo,hi,x,y,width,height,ex,vd=struct.unpack_from('<HHff4BII',mh,off+k*24);wet=[(i,f) for i,f in enumerate(block[656:720]) if f&15!=15];kind=wet[0][1]&15
assert all(f&0x3f==kind for i,f in wet);assert (ty,fmt)=={6:(7,1),4:(1,0),1:(2,0)}[kind] and (x,y,width,height)==(0,0,8,8)
assert mh[off+k*24+4:off+k*24+12]==block[:8];assert struct.unpack_from('<Q',mh,ex)[0]==sum(1<<i for i,f in wet)
assert struct.unpack_from('<QQ',mh,attrs)==tuple(sum(1<<i for i,f in wet if f&mask) for mask in (0x40,0x80))
used=set()
for i,f in wet:
yy,xx=divmod(i,8);used.update((yy*9+xx,yy*9+xx+1,(yy+1)*9+xx,(yy+1)*9+xx+1))
expected=b''.join(bytes(4) if kind==6 and i not in used and block[12+i*8:16+i*8]==b'\xff\xff\x7f\x7f' else block[12+i*8:16+i*8] for i in range(81))
assert mh[vd:vd+324]==expected
tail=b''.join(block[8+i*8:12+i*8] for i in range(81)) if kind==6 else bytes(block[8+i*8] for i in range(81));assert mh[vd+324:vd+324+len(tail)]==tail
count+=1;vertices+=81;magma+=kind==6;water+=kind!=6
return dict(instances=count,height_UV_or_depth_vertices=vertices,Magma_instances=magma,water_instances=water)
held_path=J/'held-new-ROOT-rows.private.json';held_roots=json.loads(held_path.read_text()) if held_path.exists() else []
sample=None
for row in inputs:
if row['source_reference'] in {r['source_reference'] for r in held_roots}:continue
if row['source_reference'] in {r['source_reference'] for r in roots}:continue
raw=Path(row['input_ROOT']).read_bytes();authority=any(t=='MH2O' for t,p,z in records(raw));out,audit=adt_root_magma_candidate(raw,source_legacy_authoritative=authority,source_count0_tail_authoritative=True,normalize_unused_magma_height_sentinels=True);check=verify_root(raw,out);assert check['instances']==audit['instances']
p=O/(Path(row['source_reference']).stem+'.root.adt');p.write_bytes(out);p.chmod(0o600);rr=dict(source_reference=row['source_reference'],input_ROOT=row['input_ROOT'],output_ROOT=str(p),bytes=len(out),sha256=hashlib.sha256(out).hexdigest(),audit=audit,changed_check=check);roots.append(rr);append(R,rr)
if sample is None:sample=(raw,out,authority)
# Reuse only exact input-identity matches from already-owned normalized cohorts.
reused={}
pp=Path('runtime/continuation-20261027/Hyjal-ground-layer-regression/private-current0_1-alpha8-family/component-and-changed-boundary-handoff.json')
for r in json.loads(pp.read_text())['rows']:
if r.get('file') and r.get('original_asset_record'):
for rel in r['relations']:reused[(rel['source_reference'],r['original_asset_record']['sha256'])]=r
pp=Path('runtime/rea-system-jobs-20261022/terrain-alpha-parity-20261025/alpha8-candidate-manifest.json')
for r in json.loads(pp.read_text())['outputs']:reused[(r['source_reference'],r['prior_TEX0']['sha256'])]=dict(file=r['alpha8_file'],bytes=r['bytes'],sha256=r['sha256'],alpha_maps=r['alpha_maps'])
for row in inputs:
ref=row['source_reference']
if ref not in {r['source_reference'] for r in roots}:continue
if ref in {r['source_reference'] for r in texs}:continue
src=row['TEX0'];assert src
if (ref,src['sha256']) in reused:
prior=reused[(ref,src['sha256'])];rr=dict(source_reference=ref,status='REUSED_EXACT_PRIOR_NORMALIZED_TEX',file=prior['file'],bytes=prior['bytes'],sha256=prior['sha256'],alpha_maps=prior['alpha_maps'],MDID_file_data_ids=src['source_available_bindings'])
else:
raw=Path(src['file']).read_bytes()
try:out,audit=adt_tex0_alpha8_candidate(raw)
except ValueError as e:rr=dict(source_reference=ref,status='HELD_EXISTING_ALPHA8_PRODUCER',reason=str(e),input_TEX0=src)
else:
before,after=records(raw),records(out);assert len(before)==len(after)
for (t,a,z),(u,b,zz) in zip(before,after):
assert (t,z)==(u,zz)
if t!='MCNK':assert a==b;continue
aaa,bbb=records(a),records(b);assert len(aaa)==len(bbb)
for (tag,aa,pad),(tag2,bb,pad2) in zip(aaa,bbb):
assert(tag,pad)==(tag2,pad2)
if tag=='MCAL':assert len(bb)==len(aa)*2 and all(bb[2*i]==(v&15)*17 and bb[2*i+1]==(v>>4)*17 for i,v in enumerate(aa))
elif tag=='MCLY':
for i in range(0,len(aa),16):
old=struct.unpack_from('<4I',aa,i);new=struct.unpack_from('<4I',bb,i);assert old[:2]==new[:2] and old[3]==new[3] and new[2]==old[2]*2
else:assert aa==bb
p=O/(Path(ref).stem+'.alpha8.tex0.adt');p.write_bytes(out);p.chmod(0o600);rr=dict(source_reference=ref,status='PASS_NEW_ALPHA8_TEX_CURRENT_3CA_FORMAT',input_TEX0=src['file'],file=str(p),bytes=len(out),sha256=hashlib.sha256(out).hexdigest(),alpha_maps=audit['alpha_maps'],audit=audit,MDID_file_data_ids=src['source_available_bindings'])
texs.append(rr);append(T,rr)
assert len(roots)==2 and len(texs)==2 and len(held_roots)==1
if sample is None:
row=roots[0];raw=Path(row['input_ROOT']).read_bytes();out=Path(row['output_ROOT']).read_bytes();sample=(raw,out,any(t=='MH2O' for t,p,z in records(raw)))
raw,out,authority=sample;top=records(raw);ci=next(i for i,(t,p,z) in enumerate(top) if t=='MCNK' and struct.unpack_from('<I',p)[0]&0x3c);cell=top[ci][1];children=records(cell[128:]);mi=next(i for i,(t,p,z) in enumerate(children) if t=='MCLQ');block=children[mi][1]
def changed_block(count,tail):
b=bytearray(block);struct.pack_into('<I',b,720,count);b[724:804]=tail;cc=list(children);cc[mi]=('MCLQ',bytes(b),b'');tt=list(top);tt[ci]=('MCNK',cell[:128]+encode(cc),b'');return encode(tt)
refusals=[]
for count in [1,2,3]:
try:adt_root_magma_candidate(changed_block(count,bytes(80)),source_legacy_authoritative=authority,source_count0_tail_authoritative=True,normalize_unused_magma_height_sentinels=True)
except ValueError:refusals.append('nonzero_count'+str(count))
else:raise AssertionError(count)
try:adt_root_magma_candidate(raw,source_legacy_authoritative=authority)
except ValueError:refusals.append('prior_strict_profile_tail_guard_unchanged')
else:raise AssertionError('strict profile broadened')
changed=changed_block(0,bytes([0xa5])*80);same,_=adt_root_magma_candidate(changed,source_legacy_authoritative=authority,source_count0_tail_authoritative=True,normalize_unused_magma_height_sentinels=True);assert same==out
report=dict(status='PASS_CHANGED_LITERAL_COUNT0_MAGMA_TAIL_COHORT_AND_EXACT_TEX_ALPHA8_BOUNDARY',new_ROOT_tiles=len(roots),new_ROOT_held=len(held_roots),reused_strict_ROOT_tiles=3,new_instances=sum(r['changed_check']['instances'] for r in roots),new_Magma_instances=sum(r['changed_check']['Magma_instances'] for r in roots),new_water_instances=sum(r['changed_check']['water_instances'] for r in roots),TEX_statuses={s:sum(r['status']==s for r in texs) for s in sorted({r['status'] for r in texs})},refusals=refusals,count0_tail_content_invariance=True,Source_used_heights_all_UV_depth_bounds_masks_and_other_geometry_exact=True,unused_magma_FLT_MAX_to_observed_positive_zero=True,Source_exports=0,SDK_reads=0,native_actions=0,current_B_changes=False,shading_equivalence_verified=False)
result.write_text(json.dumps(report,indent=2)+'\n');result.chmod(0o600)
(J/'changed-three-component.private.json').write_text(json.dumps(dict(status=report['status'],owning_result=str(result),flow_proof='runtime/continuation-20261027/Source-lava-flow-query-contract/handoff.json',ROOT_rows=roots,held_ROOT_rows=held_roots,TEX_rows=texs,reused_strict3_component='runtime/continuation-20261027/Source-lava-class2-contract/magma-strict-three-component.private.json'),indent=2)+'\n')
print(report['status']);print('NewROOT2;',report['new_instances'],'instances; TEX',report['TEX_statuses'])