Files
WoW-Hybrid-gateway/tests/map_source_alpha_edge_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

58 lines
6.3 KiB
Python

"""One newly qualified Source63x63 edge profile and its exact34_46 TEX."""
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_edge_invariant_alpha8_layers as layers,adt_tex0_alpha8_candidate,adt_root_magma_candidate
J=Path('runtime/continuation-20261027/Source-alpha-edge-original-contract');result=J/'focused-new-edge-and-34_46-TEX.private.json';assert not result.exists()
flags=json.loads((J/'Source-mask-scalars-and-34_46-edge-flags.private.json').read_text());assert flags['Source_fix_clear_cells']==256
byxy={(r['x'],r['y']):r['flags'] for r in flags['flags']};sourceflags=tuple(byxy[x,y]for y in range(16)for x in range(16))
cohort=json.loads(Path('runtime/continuation-20261027/Source-lava-class2-contract/count0-supported-extension/new-three-inputs.private.json').read_text())['rows'];row=next(r for r in cohort if r['source_reference']==flags['Source_reference']);prior=row['TEX0'];prefix_path=J/"completed-actual34_46-TEX-prefix.private.json"
raw=(J/'34_46-cached-input-TEX.bin').read_bytes()
if prefix_path.exists():
prefix=json.loads(prefix_path.read_text());audit=prefix["audit"];maps=prefix["alpha_maps"];samples=prefix["Source_effective_alpha_samples_compared"];changed_border_samples=prefix["raw_unused_border_samples_replaced"];p=Path(prefix["file"])
else:
out,audit=adt_tex0_alpha8_candidate(raw,source_mcnk_flags=sourceflags)
before,after=records(raw),records(out);assert len(before)==len(after);cell=maps=samples=changed_border_samples=0
for (tag,a,z),(tag2,b,z2)in zip(before,after):
assert(tag,z)==(tag2,z2)
if tag!='MCNK':assert a==b;continue
aa,bb=records(a),records(b);assert len(aa)==len(bb);old={t:p for t,p,z in aa};new={t:p for t,p,z in bb}
for (t,p,pad),(u,q,pad2) in zip(aa,bb):
assert(t,pad)==(u,pad2)
if t not in ('MCLY','MCAL'):assert p==q
ll=list(struct.iter_unpack('<4I',old['MCLY']));nn=list(struct.iter_unpack('<4I',new['MCLY']));assert len(ll)==len(nn)
for index,(l,n) in enumerate(zip(ll,nn)):
assert l[:2]==n[:2] and l[3]==n[3] and n[2]==l[2]*2
if index==0:continue
packed=old['MCAL'][l[2]:l[2]+2048];actual=new['MCAL'][n[2]:n[2]+4096];assert len(packed)==2048 and len(actual)==4096
# Original6B0BF0 emits63 columns/rows into ARGB4444, repeating col62
# and then row62. Compare its effective 4bit alpha to target8bit alpha.
for y in range(64):
for x in range(64):
ey,ex=(min(y,62),min(x,62)) if not sourceflags[cell]&0x8000 else (y,x);i=ey*64+ex;v=packed[i//2];nib=(v>>(4*(i&1)))&15;source_argb4444=(nib<<12)|0xfff;assert actual[y*64+x]==((source_argb4444>>12)&15)*17
orig=(packed[(y*64+x)//2]>>(4*(x&1)))&15;changed_border_samples+=nib!=orig
assert actual[63*64:]==actual[62*64:63*64] and all(actual[y*64+63]==actual[y*64+62]for y in range(64));maps+=1;samples+=4096
cell+=1
assert cell==256 and maps==audit['alpha_maps'] and changed_border_samples>0
p=J/'azeroth_34_46.Source63.alpha8.tex0.adt';p.write_bytes(out);p.chmod(0o600)
prefix=dict(file=str(p),bytes=len(out),sha256=hashlib.sha256(out).hexdigest(),content_key=hashlib.md5(out).hexdigest(),alpha_maps=maps,Source_effective_alpha_samples_compared=samples,raw_unused_border_samples_replaced=changed_border_samples,audit=audit)
prefix_path.write_text(json.dumps(prefix,indent=2)+"\n")
# New policy boundaries on one bounded noninvariant Source map, no old cohort replay.
mcly=struct.pack('<8I',0,0,0,0,1,0x100,0,0);mcal=bytes([0x12])*2048
_,expanded,_=layers(mcly,mcal,source_edge_repair=True);assert expanded[62]==34 and expanded[63]==34
refusals=[]
for label,fn in [('Source_no_fix_requires_invariant_edges',lambda:layers(mcly,mcal)),('Source_compressed_layer_refused',lambda:layers(struct.pack('<8I',0,0,0,0,1,0x300,0,0),mcal,source_edge_repair=True,source_alpha_presence_only=True)),('Source_unknown_high_layer_refused',lambda:layers(struct.pack('<8I',0,0,0,0,1,0x500,0,0),mcal,source_edge_repair=True,source_alpha_presence_only=True)),('Source_flag_count255',lambda:adt_tex0_alpha8_candidate(raw,source_mcnk_flags=sourceflags[:-1])),('Source_bool_not_flagword',lambda:adt_tex0_alpha8_candidate(raw,source_mcnk_flags=(False,)+sourceflags[1:]))]:
try:fn()
except ValueError:refusals.append(label)
else:raise AssertionError(label)
# The additional height profile admits only unused exactpositiveFLT_MAX.
root=Path(row['input_ROOT']).read_bytes();top=records(root);ci=next(i for i,(t,p,z)in enumerate(top)if t=='MCNK' and struct.unpack_from('<I',p)[0]&0x3c);c=top[ci][1];children=records(c[128:]);mi=next(i for i,(t,p,z)in enumerate(children)if t=='MCLQ');block=children[mi][1];wet=next(i for i,f in enumerate(block[656:720])if f&15==6);wy,wx=divmod(wet,8);usedvertex=wy*9+wx
for label,bits in [('used_FLT_MAX',0x7f7fffff),('used_NaN',0x7fc00000),('used_infinity',0x7f800000)]:
changed=bytearray(block);struct.pack_into('<I',changed,12+usedvertex*8,bits);cc=list(children);cc[mi]=('MCLQ',bytes(changed),b'');tt=list(top);tt[ci]=('MCNK',c[:128]+b''.join(struct.pack('<4sI',t[::-1].encode(),len(d))+d+z for t,d,z in cc),b'');changedroot=b''.join(struct.pack('<4sI',t[::-1].encode(),len(d))+d+z for t,d,z in tt)
try:adt_root_magma_candidate(changedroot,source_legacy_authoritative=any(t=='MH2O'for t,p,z in top),source_count0_tail_authoritative=True,normalize_unused_magma_height_sentinels=True)
except ValueError:refusals.append(label)
else:raise AssertionError(label)
report=dict(status='PASS_ORIGINAL_SOURCE63_ALPHA_EDGE_TO_3CA_COMPATIBLE_ALPHA8_TEX_AND_USED_HEIGHT_REFUSALS',source_reference=row['source_reference'],Source_ROOT=flags['Source_ROOT'],Source_flags_receipt=str(J/'Source-mask-scalars-and-34_46-edge-flags.private.json'),input_TEX=prior,file=str(p),bytes=prefix['bytes'],sha256=prefix['sha256'],content_key=prefix['content_key'],audit=audit,cells=256,alpha_maps=maps,Source_effective_alpha_samples_compared=samples,raw_unused_border_samples_replaced=changed_border_samples,MDID_file_data_ids=prior['source_available_bindings'],all_nonalpha_bytes_and_all_layer_flags_unchanged=True,all_target_alpha_edges_invariant=True,refusals=refusals,native_actions=0,SDK_reads=0,registered=False,runtime_accepted=False,Source_shading_equivalence_verified=False)
result.write_text(json.dumps(report,indent=2)+'\n');result.chmod(0o600);print(report['status']);print('TEX34_46:',maps,'maps,',samples,'Source-effective samples;',len(refusals),'refusals.')