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

82 lines
8.0 KiB
Python

"""Changed mixed Still/Magma inactive-height profile; no alpha or old batch replay."""
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
J=Path('runtime/continuation-20261027/Kalimdor34_45-mixed-liquid-contract');result=J/'focused-mixed-ROOT-result.private.json';assert not result.exists()
classification=json.loads((J/'all29-source-layer-operands.private.json').read_text());native=json.loads((J/'original-native-LVF0-inactive-height-role.private.json').read_text());assert classification['layers']==29 and classification['water_special_vertices']==418 and classification['special_USED_vertices']==0 and native['unused_positive_zero_vertices']==128 and native['same_typed_height_depth_format']is True
raw=Path(classification['input_ROOT']).read_bytes();top=records(raw);authority=any(t=='MH2O'for t,p,z in top)
kwargs=dict(source_legacy_authoritative=authority,source_count0_tail_authoritative=True,normalize_unused_magma_height_sentinels=True,normalize_unused_still_height_sentinels=True)
out,audit=adt_root_magma_candidate(raw,**kwargs);after=records(out);liquid=next(p for t,p,z in after if t=='MH2O');beforecells=[p for t,p,z in top if t=='MCNK'];aftercells=[p for t,p,z in after if t=='MCNK'];assert len(beforecells)==len(aftercells)==256
assert [(t,p,z)for t,p,z in top if t not in ('MHDR','MH2O','MCNK')]==[(t,p,z)for t,p,z in after if t not in ('MHDR','MH2O','MCNK')]
ah=next(p for t,p,z in top if t=='MHDR');bh=next(p for t,p,z in after if t=='MHDR');assert all(ah[n*4:n*4+4]==bh[n*4:n*4+4]for n in range(16)if n not in (9,10,11))
count=water=magma=water_normalized=magma_normalized=0;cellinfo={}
for before,changed in zip(beforecells,aftercells):
a,b=struct.unpack_from('<32I',before),struct.unpack_from('<32I',changed);assert b[0]==a[0]&~0x3c and b[24:26]==(0,0);assert all(a[n]==b[n]for n in range(1,32)if n not in (22,24,25,29))
ca,cb=records(before[128:]),records(changed[128:]);assert[(t,p,z)for t,p,z in ca if t!='MCLQ']==cb
off,n,attrs=struct.unpack_from('<III',liquid,(a[2]*16+a[1])*12);assert n==(a[0]&0x3c).bit_count()
if not n:assert(off,attrs)==(0,0);continue
source=next(p for t,p,z in ca if t=='MCLQ');cellinfo[a[1:3]]=(before,source)
for k in range(n):
block=source[k*804:(k+1)*804];wet=[(i,f)for i,f in enumerate(block[656:720])if f&15!=15];kind=wet[0][1]&15;assert kind in(4,6)and all(f&0x3f==kind for i,f in wet);used=set()
for i,f in wet:y,x=divmod(i,8);used.update((y*9+x,y*9+x+1,(y+1)*9+x,(y+1)*9+x+1))
ty,fmt,lo,hi,x,y,w,h,ex,vd=struct.unpack_from('<HHff4BII',liquid,off+k*24);assert(ty,fmt)=={4:(1,0),6:(7,1)}[kind]and(x,y,w,h)==(0,0,8,8);assert liquid[off+k*24+4:off+k*24+12]==block[:8]
assert struct.unpack_from('<Q',liquid,ex)[0]==sum(1<<i for i,f in wet);assert struct.unpack_from('<QQ',liquid,attrs)==tuple(sum(1<<i for i,f in wet if f&mask)for mask in(0x40,0x80))
for v in range(81):
original=block[12+v*8:16+v*8];actual=liquid[vd+v*4:vd+v*4+4]
if original==b'\xff\xff\x7f\x7f'and v not in used:
assert actual==bytes(4);water_normalized+=kind==4;magma_normalized+=kind==6
else:assert actual==original
tail=bytes(block[8+v*8]for v in range(81))if kind==4 else b''.join(block[8+v*8:12+v*8]for v in range(81));assert liquid[vd+324:vd+324+len(tail)]==tail
count+=1;water+=kind==4;magma+=kind==6
assert(count,water,magma,water_normalized,magma_normalized)==(29,25,4,418,31)
assert audit['normalized_unused_still_vertices']==418 and audit['normalized_unused_magma_vertices']==31 and audit['Source_used_height_bytes_preserved']and audit['Source_water_depth_bytes_preserved']and audit['mixed_Still_Magma_only']
file=J/'kalimdor_34_45.mixed-Still-Magma-count0.root.adt';file.write_bytes(out);file.chmod(0o600)
# New guard changes only: retain mix/attributes/flow and used-height boundaries.
def enc(rr):return b''.join(chunk(t,p)+z for t,p,z in rr)
ci=next(i for i,(t,p,z)in enumerate(top)if t=='MCNK'and(p[4:12]in[struct.pack('<II',*r['cell'])for r in classification['rows']if r['raw_nibbles']==[4]]))
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];wetindex=next(i for i,f in enumerate(block[656:720])if f&15==4);wy,wx=divmod(wetindex,8);used=wy*9+wx
wetset=set()
for i,f in enumerate(block[656:720]):
if f&15!=15:y,x=divmod(i,8);wetset.update((y*9+x,y*9+x+1,(y+1)*9+x,(y+1)*9+x+1))
unused=next(i for i in range(81)if i not in wetset and block[12+i*8:16+i*8]==b'\xff\xff\x7f\x7f')
def mutate(data,header=None):
cc=list(children);cc[mi]=('MCLQ',data,b'');rr=list(top);rr[ci]=('MCNK',header or cell[:128]+b'',b'');rr[ci]=('MCNK',rr[ci][1]+enc(cc),b'');return enc(rr)
refusals=[]
def reject(label,data,kw=kwargs,expected=None):
try:adt_root_magma_candidate(data,**kw)
except ValueError as e:
if expected:assert expected in str(e),(label,str(e))
refusals.append(label)
else:raise AssertionError(label)
reject('old_Still_height_guard_unchanged',raw,dict(kwargs,normalize_unused_still_height_sentinels=False),'sentinel')
reject('Still_policy_requires_literal_count0_authority',raw,dict(kwargs,source_count0_tail_authoritative=False),'count0 mixed')
for n in[1,2]:
b=bytearray(block);struct.pack_into('<I',b,720,n);reject('nonzero_flow_count'+str(n),mutate(bytes(b)),expected='flow')
for label,vertex,bits in [('used_Still_FLT_MAX',used,0x7f7fffff),('unused_Still_NaN',unused,0x7fc00000),('unused_Still_negative_FLT_MAX',unused,0xff7fffff)]:
b=bytearray(block);struct.pack_into('<I',b,12+vertex*8,bits);reject(label,mutate(bytes(b)),expected='sentinel')
# Do not admit an all-Magma root via the mixed-only Still presentation policy.
rr=[]
for tag,data,z in top:
if tag=='MCNK':
cc=[]
for t,p,pad in records(data[128:]):
if t=='MCLQ':
b=bytearray(p)
for start in range(0,(struct.unpack_from('<I',data)[0]&0x3c).bit_count()*804,804):
for i in range(64):
if b[start+656+i]&15==4:b[start+656+i]=(b[start+656+i]&0xf0)|6
p=bytes(b)
cc.append((t,p,pad))
data=data[:128]+enc(cc)
rr.append((tag,data,z))
reject('mixed_policy_requires_Still_and_Magma',enc(rr),expected='Exact Still/Magma mixture')
# A second legitimate class does not allow conflicting per-instance cell attributes.
second=bytearray(block)
for i in range(64):
if second[656+i]&15!=15:second[656+i]=(second[656+i]&0xf0)|6
second[656+wetindex]^=0x40;h=bytearray(cell[:128]);w=struct.unpack_from('<I',h)[0];struct.pack_into('<I',h,0,(w&~0x3c)|0xc);struct.pack_into('<I',h,100,8+1608)
reject('per_layer_Fishable_Deep_conflict',mutate(block+bytes(second),bytes(h)),expected='Per-layer water attributes')
report=dict(status='PASS_CHANGED_COUNT0_MIXED_STILL_MAGMA_INACTIVE_HEIGHT_PROFILE_AND_29_LAYER_ROOT',source_reference=classification['source_reference'],input_ROOT=classification['input_ROOT'],output_ROOT=str(file),bytes=len(out),sha256=hashlib.sha256(out).hexdigest(),instances=29,Still_instances=25,Magma_instances=4,normalized_unused_Still_vertices=418,normalized_unused_Magma_vertices=31,used_heights_depth_UV_bounds_wet_Fishable_Deep_preserved=True,all_other_geometry_children_preserved=True,Source_count0_proof='runtime/continuation-20261027/Source-lava-flow-query-contract/handoff.json',native_LVF0_inactive_control=str(J/'original-native-LVF0-inactive-height-role.private.json'),native_LVF0_control_is_same_typed_role_not_same_Source_tile=True,refusals=refusals,audit=audit,alpha_checks_or_changes=0,native_actions=0,SDK_reads=0,registered=False,runtime_accepted=False)
result.write_text(json.dumps(report,indent=2)+'\n');result.chmod(0o600);(J/'unregistered-ROOT-component.json').write_text(json.dumps(dict(status=report['status'],owner_result=str(result),rows=[dict(source_reference=report['source_reference'],input_ROOT=report['input_ROOT'],output_ROOT=str(file),bytes=report['bytes'],sha256=report['sha256'],audit=audit)],terrain_triplet_qualified=False,TEX_OBJ_and_WDT_linking_deferred=True),indent=2)+'\n');print(report['status']);print('29layers,418Still+31Magma unusedslots normalized;',len(refusals),'refusals; no alpha/native actions.')