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

75 lines
6.8 KiB
Python

"""Only new3 Source-authoritative ROOT components; no accepted861 replay."""
import ast
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_flat_ocean_candidate,adt_root_equivalent_ocean_candidate
J=Path('runtime/continuation-20261026/terrain-remaining3-layer-relationship')
items=json.loads((J/'cached3-MH2O-role-inputs.json').read_text())['rows'];assert len(items)==3
# Reuse only the prior pure cell/header/opaque-payload verifier, not its140 loop.
p=Path('tests/map_equivalent_ocean_candidate_test.py');tree=ast.parse(p.read_text());definition=next(n for n in tree.body if isinstance(n,ast.FunctionDef)and n.name=='verify');ns=dict(_adt_split_records=_adt_split_records,struct=struct);exec(compile(ast.Module(body=[definition],type_ignores=[]),str(p),'exec'),ns);verify_cells=ns['verify']
def encode(parts):return b''.join(_adt_split_chunk(t,d)+z for t,d,z in parts)
def cells_only(parts):return encode([r for r in parts if r[0]=='MCNK'])
def verify(raw,new):
before,after=_adt_split_records(raw),_adt_split_records(new);verify_cells(cells_only(before),cells_only(after))
assert [(t,d,z)for t,d,z in before if t not in('MHDR','MH2O','MCNK')]==[(t,d,z)for t,d,z in after if t not in('MHDR','MH2O','MCNK')]
ha,hb=before[1][1],after[1][1];wa,wb=struct.unpack('<16I',ha),struct.unpack('<16I',hb);assert all(wa[n]==wb[n]for n in range(16)if n not in(9,10,11))
cursor=0;offsets={}
for t,d,z in after:
if t in('MFBO','MH2O','MTXF'):offsets[t]=cursor-20
cursor+=8+len(d)+len(z)
for word,tag in((9,'MFBO'),(10,'MH2O'),(11,'MTXF')):assert wb[word]==offsets.get(tag,0)
liquid=next(d for t,d,z in after if t=='MH2O');active=0;ignored=0
for t,cell,z in before:
if t!='MCNK':continue
w=struct.unpack_from('<32I',cell);x,y=w[1:3];off,count,attrs=struct.unpack_from('<3I',liquid,(y*16+x)*12)
if not(w[0]&0x3c):assert(off,count,attrs)==(0,0,0);continue
assert(w[0]&0x3c).bit_count()==1
source=next(d for t,d,z in _adt_split_records(cell[128:])if t=='MCLQ');first=source[:804];ignored+=len(source)//804-1
flags=first[656:720];exists=sum(1<<n for n,f in enumerate(flags)if f&15!=15);fish=sum(1<<n for n,f in enumerate(flags)if f&15!=15 and f&0x40);deep=sum(1<<n for n,f in enumerate(flags)if f&15!=15 and f&0x80)
assert exists and count==1
typ,fmt,lo,hi,ox,oy,width,height,bits,vertices=struct.unpack_from('<HHffBBBBII',liquid,off)
assert(typ,fmt,lo,hi,ox,oy,width,height)==(2,42,0.,0.,0,0,8,8)
assert struct.unpack_from('<Q',liquid,bits)[0]==exists and struct.unpack_from('<QQ',liquid,attrs)==(fish,deep)
assert liquid[vertices:vertices+81]==bytes(first[8+v*8]for v in range(81));active+=1
return active,ignored
OUT=J/'private-sourceLegacy-authoritative3-ROOT';OUT.mkdir(exist_ok=False)
rows=[];samples=[]
for item in items:
raw=Path(item['input_ROOT']).read_bytes()
# Changed inputs retain strict old default and old preservation refusals.
for fn in(adt_root_flat_ocean_candidate,adt_root_equivalent_ocean_candidate):
try:fn(raw)
except ValueError:pass
else:raise AssertionError('Prior default/preservation unexpectedly admitted changed3 input')
new,audit=adt_root_flat_ocean_candidate(raw,source_legacy_authoritative=True);active,ignored=verify(raw,new)
assert audit['authority_policy']=='source5014-reachable-legacy-Ocean-v1'and audit['existing_MH2O_replaced']and not audit['existing_MH2O_preservation_claim']and not audit['publishable']
assert audit['Source_unreachable_physical_records_ignored']==ignored
dest=OUT/(Path(item['source_reference']).stem+'.root.adt');dest.write_bytes(new)
rows.append(dict(source_reference=item['source_reference'],input_ROOT=item['input_ROOT'],output_ROOT=str(dest),bytes=len(new),sha256=hashlib.sha256(new).hexdigest(),active_Source_cells=active,ignored_unreachable_records=ignored,audit=audit));samples.append((raw,new))
raw,new=samples[0];top=_adt_split_records(raw);ci=next(i for i,(t,d,z)in enumerate(top)if t=='MCNK'and (struct.unpack_from('<I',d)[0]&0x3c)and len(next(p for t,p,z in _adt_split_records(d[128:])if t=='MCLQ'))>804);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(n for n,f in enumerate(block[656:720])if f&15!=15)
def changed_cell(header=None,payload=None):
cp=list(parts)
if payload is not None:cp[mi]=('MCLQ',payload,cp[mi][2])
result=list(top);result[ci]=('MCNK',(cell[:128]if header is None else header)+encode(cp),top[ci][2]);return encode(result)
refusals=[]
def refuse(label,data,**kw):
try:adt_root_flat_ocean_candidate(data,source_legacy_authoritative=True,**kw)
except ValueError:refusals.append(label)
else:raise AssertionError('Unsafe Source authority input accepted: '+label)
for label,offset,value in(('unknown_wet',656+wet,b'\x09'),('nonflat_used_height',12+(wet//8*9+wet%8)*8,struct.pack('<f',1.)),('flow',720,struct.pack('<I',1))):
b=bytearray(block);b[offset:offset+len(value)]=value;refuse(label,changed_cell(payload=bytes(b)))
for label,word,value in(('two_reachable_layers',0,struct.unpack_from('<I',cell)[0]|0x3c),('wrong_parent_extent',25,812)):
h=bytearray(cell[:128]);struct.pack_into('<I',h,word*4,value);refuse(label,changed_cell(header=bytes(h)))
refuse('partial_physical_record',changed_cell(payload=block+b'\0'))
for label,records in(('missing_replaced_MH2O',[r for r in top if r[0]!='MH2O']),('duplicate_replaced_MH2O',top[:2]+[next(r for r in top if r[0]=='MH2O')]+top[2:])):refuse(label,encode(records))
h=bytearray(top[1][1]);struct.pack_into('<I',h,40,struct.unpack_from('<I',h,40)[0]+4);r=list(top);r[1]=('MHDR',bytes(h),top[1][2]);refuse('wrong_old_MH2O_binding',encode(r))
# Actual Source loop proves unreachable data independence even when its flags are wet.
b=bytearray(block);b[804+656]=0xc2;modified=changed_cell(payload=bytes(b));other,otheraudit=adt_root_flat_ocean_candidate(modified,source_legacy_authoritative=True);assert other==new
# One whole private policy check; never old family tests or runtime ingestion.
report=dict(status='PASS_SOURCE_LEGACY_AUTHORITATIVE_CANONICAL_OCEAN3',inputs=3,admitted=3,Source_active_cells=sum(r['active_Source_cells']for r in rows),ignored_unreachable_physical_records=sum(r['ignored_unreachable_records']for r in rows),strict_default_and_preservation_refusals=6,unsafe_refusals=refusals,unreachable_wet_tail_independence=1,geometry_and_other_opaque_bytes_preserved=True,new_MH2O_single_surface_Source_depth_wet_Fishable_Deep_exact=True,old_MH2O_preservation_claim=False,old861_Source_exports_SDK_tests_or_live_actions=False,publishable=False)
(J/'sourceLegacy3-focused-result.json').write_text(json.dumps(report,indent=2)+'\n');(J/'sourceLegacy3-candidate-manifest.json').write_text(json.dumps(dict(status=report['status'],authority_policy='source5014-reachable-legacy-Ocean-v1',rows=rows),indent=2)+'\n');print(report['status'])