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

108 lines
7.1 KiB
Python

"""One140 dual-representation boundary; previous562/115 checks are not replayed."""
import hashlib
import json
from pathlib import Path
import struct
import sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from map_asset_preflight import _adt_split_chunk,_adt_split_records,adt_root_equivalent_ocean_candidate,adt_split_candidate
B=Path('runtime/rea-system-jobs-20261022');J=B/'terrain-MH2O329-role-20261025'
selected=[r for r in json.loads((J/'Source209-MCLQ-MH2O-ocean-correspondence.json').read_text())['rows'] if r.get('whole_tile_equivalent')]
assert len(selected)==140
OUT=J/'private-equivalent140-ROOT';OUT.mkdir(exist_ok=True)
def encode(top):return b''.join(_adt_split_chunk(t,d)+x for t,d,x in top)
def verify(old,new):
before,after=_adt_split_records(old),_adt_split_records(new)
assert [(t,d,x) for t,d,x in before if t!='MCNK']==[(t,d,x) for t,d,x in after if t!='MCNK']
a=[d for t,d,x in before if t=='MCNK'];b=[d for t,d,x in after if t=='MCNK']
assert len(a)==len(b)==256
for original,converted in zip(a,b):
wa,wb=struct.unpack_from('<32I',original),struct.unpack_from('<32I',converted)
assert wb[0]==wa[0]&~0x3c and wb[24:26]==(0,0)
assert all(wa[i]==wb[i] for i in range(1,32) if i not in (22,24,25,29))
ca,cb=_adt_split_records(original[128:]),_adt_split_records(converted[128:])
assert [(t,d,x) for t,d,x in ca if t!='MCLQ']==cb
offsets={};pos=128
for t,d,x in cb:offsets[t]=pos+8;pos+=8+len(d)+len(x)
assert wb[22]==offsets.get('MCSE',0) and wb[29]==offsets.get('MCCV',0)
progress=J/'equivalent140-completed-candidate-rows.jsonl'
rows=[json.loads(l) for l in progress.read_text().splitlines()] if progress.exists() else []
done={r['source_reference'] for r in rows}
for row in selected:
if row['source_reference'] in done:continue
old=Path(row['input_ROOT']).read_bytes();new,audit=adt_root_equivalent_ocean_candidate(old)
verify(old,new)
filename=OUT/(Path(row['source_reference']).stem+'.root.adt');filename.write_bytes(new)
result=dict(source_reference=row['source_reference'],input_ROOT=row['input_ROOT'],output_ROOT=str(filename),
bytes=len(new),sha256=hashlib.sha256(new).hexdigest(),audit=audit)
rows.append(result)
with progress.open('a') as out:out.write(json.dumps(result,separators=(',',':'))+'\n')
sample=selected[0];raw=Path(sample['input_ROOT']).read_bytes();top=_adt_split_records(raw)
hi=next(i for i,r in enumerate(top) if r[0]=='MH2O');liquid=top[hi][1]
x,y=sample['matched_cells'][0]['cell'];cell_index=y*16+x
off,count,attrs=struct.unpack_from('<3I',liquid,cell_index*12)
typ,fmt,lo,h,ox,oy,w,height,bits,vertex=struct.unpack_from('<HHffBBBBII',liquid,off)
def reject(changed):
try:adt_root_equivalent_ocean_candidate(encode(changed))
except ValueError:return
raise AssertionError('Unmatched Source/MH2O field admitted')
def reject_liquid(changed):
records=list(top);records[hi]=('MH2O',bytes(changed),b'');reject(records)
# Type/category and used vertex operands must agree independently of equal IDs.
changed=bytearray(liquid);struct.pack_into('<H',changed,off,1);reject_liquid(changed)
changed=bytearray(liquid);struct.pack_into('<f',changed,off+4,1.);reject_liquid(changed)
local=int.from_bytes(liquid[bits:bits+(w*height+7)//8],'little') if bits else (1<<(w*height))-1
n=next(n for n in range(w*height) if local>>n&1);sy,sx=divmod(n,w)
used_vertex=sy*(w+1)+sx;depth_start=vertex+(w+1)*(height+1)*4 if fmt==0 else vertex
changed=bytearray(liquid);changed[depth_start+used_vertex]^=1;reject_liquid(changed)
changed=bytearray(liquid);bitmap_offset=len(changed);changed.extend((local^(1<<n)).to_bytes(8,'little'));struct.pack_into('<I',changed,off+16,bitmap_offset);reject_liquid(changed)
global_bit=1<<((oy+sy)*8+ox+sx)
fish,deep=struct.unpack_from('<QQ',liquid,attrs) if attrs else ((1<<64)-1,(1<<64)-1)
for newfish,newdeep in [(fish^global_bit,deep),(fish,deep^global_bit)]:
changed=bytearray(liquid);newattrs=len(changed);changed.extend(struct.pack('<QQ',newfish,newdeep));struct.pack_into('<I',changed,cell_index*12+8,newattrs);reject_liquid(changed)
ci=next(i for i,(t,d,z) in enumerate(top) if t=='MCNK' and struct.unpack_from('<2I',d,4)==(x,y));cell=top[ci][1];parts=_adt_split_records(cell[128:]);mi=next(i for i,r in enumerate(parts) if r[0]=='MCLQ');block=parts[mi][1]
wet=next(i for i,f in enumerate(block[656:720]) if f in (65,193))
for offset,value in [(656+wet,b'\x01'),(720,struct.pack('<I',1))]:
changed=bytearray(block);changed[offset:offset+len(value)]=value;p=list(parts);p[mi]=('MCLQ',bytes(changed),b'');records=list(top);records[ci]=('MCNK',cell[:128]+encode(p),b'');reject(records)
changed=bytearray(liquid);struct.pack_into('<I',changed,cell_index*12+4,2);reject_liquid(changed)
records=list(top);hdr=bytearray(records[1][1]);struct.pack_into('<I',hdr,40,struct.unpack_from('<I',hdr,40)[0]+4);records[1]=('MHDR',bytes(hdr),b'');reject(records)
reject([r for r in top if r[0]!='MH2O'])
# Only the new optional integration is checked; previous defaults are compared
# once to this sample's accepted artifact, not a prior family replay.
sourcefiles={}
for filename in [B/'continent-terrain-Source463-20261025/qualified-source463/report.json',B/'new-map-active-Source393-20261025/qualified-source393/report.json',B/'continent-Source-only62-20261025/qualified-new62/report.json']:
for r in json.loads(filename.read_text())['records']:
if r.get('payload'):sourcefiles[r['source_reference']]=r['payload']['file']
if sample['source_reference'] not in sourcefiles:
old208=json.loads((B/'custom-map-retained-ADT-split-20261025/retained208-candidate-manifest.json').read_text())['results'];sourcefiles.update({r['source_reference']:r['Source_payload'] for r in old208})
source=Path(sourcefiles[sample['source_reference']]).read_bytes();tile=tuple(map(int,Path(sample['source_reference']).stem.rsplit('_',2)[1:]))
default,_=adt_split_candidate(source,tile,file_data_ids={},roles=('root',));assert default['root']==raw
new,_=adt_split_candidate(source,tile,file_data_ids={},roles=('root',),preserve_equivalent_ocean_liquid=True);assert new['root']==Path(rows[0]['output_ROOT']).read_bytes()
try:adt_split_candidate(source,tile,file_data_ids={},roles=('root',),preserve_equivalent_ocean_liquid=True,normalize_flat_ocean_liquid=True)
except ValueError:pass
else:raise AssertionError('Conflicting liquid paths accepted')
report=dict(status='PASS140_EQUIVALENT_SOURCE_MH2O_OCEAN_PRESERVATION',Source_MH2O_denominator=329,
typed_flat_Ocean_candidates=209,admitted_whole_tiles=140,
matched_active_cells=sum(r['audit']['active_cells'] for r in rows),
entire_existing_MH2O_and_other_top_payloads_byte_exact=True,
only_redundant_MCLQ_source0x3c_pointers_and_relocations_changed=True,
unsafe_refusals=12,default_byte_exact_cases=1,integrated_cases=1,
old115_562_geometry_alpha_or_SDK_checks_repeated=False,publishable=False)
(J/'equivalent140-focused-check.json').write_text(json.dumps(report,indent=2)+'\n')
(J/'equivalent140-candidate-manifest.json').write_text(json.dumps(dict(status=report['status'],rows=rows),indent=2)+'\n')
print(json.dumps(report))