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

175 lines
12 KiB
Python

"""New actual-family split layout boundary; no old terrain/original tests repeat."""
from pathlib import Path
import collections,hashlib,json,struct,sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from map_asset_preflight import adt_split_candidate
def top(raw):
rows=[];p=0
while p<len(raw):
if raw[p:p+8]==bytes(8):break
t,n=struct.unpack_from('<4sI',raw,p);assert n<=len(raw)-p-8
rows.append((t[::-1].decode(),p,raw[p+8:p+8+n]));p+=8+n
return rows
def children(cell):
rows={}
for t,p,d in top(cell[128:]):rows[t]=d
return rows
def source_child(cell, tag, size=None):
at=cell.find(tag.encode()[::-1],128);assert at>=128
n=struct.unpack_from('<I',cell,at+4)[0]
if size is not None:assert n==size
return at,cell[at+8:at+8+n]
def expected_holes(low):
# Independent4x4 -> doubled-row/doubled-column occupancy matrix.
rows=[]
for y in range(4):
line=0
for x in range(4):
if low&(1<<(4*y+x)):line|=3<<(2*x)
rows.extend([line,line])
return int.from_bytes(bytes(rows),'little')
def parent_span_refusals(raw, tile, source_cells, mode):
candidate_cell=next((p,d) for t,p,d in top(raw) if t=='MCNK' and struct.unpack_from('<I',d,100)[0]>8 and source_child(d,'MCLQ')[1]==b'')
parent_at=candidate_cell[0]+8
spans=[]
if mode in ('all','single'):
spans += [('liquid_parent_offset',96,struct.unpack_from('<I',raw,parent_at+96)[0]+1),('liquid_parent_width',100,813),('liquid_parent_overrun',100,1616)]
if mode in ('all','multiple'):
spans += [('aligned_multi_liquid_parent_overrun',100,((len(candidate_cell[1])//804)+2)*804+8)]
refused=[]
for label,offset,value in spans:
bad=bytearray(raw);struct.pack_into('<I',bad,parent_at+offset,value)
try:adt_split_candidate(bytes(bad),tile,file_data_ids={},roles=('root',))
except ValueError:refused.append(label)
else:raise AssertionError('Invalid parent-owned liquid span admitted: '+label)
return refused
def check(job, resume_liquid=False, resume_multiple=False):
job=Path(job);source_job=Path('runtime/rea-system-jobs-20261022/continent-terrain-Source463-20261025')
source_records=json.loads((source_job/'qualified-source463/report.json').read_text())['records']
preflight=json.loads((source_job/'qualified-source463/preflight-checkpoint.json').read_text())
pby={r['source_reference']:r for r in preflight};binding_path=Path('runtime/rea-system-jobs-20261022/custom-map-resource-closure-20261024/complete-source796-texture-bindings.json')
bindings={r['source_path']:r['file_data_id'] for r in json.loads(binding_path.read_text())['aliases']}
out=job/'private-split-source462'
if resume_liquid:
prior=json.loads((job/'completed-split-family-focused-check.json').read_text())
prior_manifest=json.loads((job/'source462-split-candidate-manifest.json').read_text())
pending={r['source_reference'] for r in prior['held_source_shapes']}
source_records=[r for r in source_records if r['source_reference'] in pending]
results=list(prior_manifest['results']);role_counts=collections.Counter(prior['real_role_counts'])
unknown=collections.Counter(prior['unknown_top_chunks_preserved']);prior_cells=prior['verified_source_geometry_cells']
assert len(source_records)==len(pending) and len(results)+len(pending)==462
else:
assert not out.exists();out.mkdir(mode=0o700)
results=[];role_counts=collections.Counter();unknown=collections.Counter();prior_cells=0
held=[];first=None;first_liquid=None;cell_count=0
for row in source_records:
info=pby[row['source_reference']]
if 'preflight_hold' in info:continue
deps=info['dependencies'];wanted={'root'}
if set(deps['textures'])<=set(bindings):wanted.add('tex0')
objrefs=set(deps['model_placements']['referenced_assets'])|set(deps['wmo_placements']['referenced_assets'])
if objrefs<=set(bindings):wanted.add('obj0')
roles=tuple(r for r in ('root','tex0','obj0') if r in wanted)
raw=Path(row['payload']['file']).read_bytes();tile=tuple(row['scope']['tile'])
try:artifacts,receipt=adt_split_candidate(raw,tile,file_data_ids=bindings,roles=roles)
except ValueError as error:
held.append(dict(source_reference=row['source_reference'],reason=str(error),category=row['scope']['category']));continue
assert set(artifacts)==set(roles) and receipt['publishable'] is False
src=top(raw);srcmap={t:d for t,p,d in src if t!='MCNK'}
source_cells={(struct.unpack_from('<I',d,4)[0],struct.unpack_from('<I',d,8)[0]):d for t,p,d in src if t=='MCNK'}
native=top(artifacts['root']);root_cells=[d for t,p,d in native if t=='MCNK'];assert len(root_cells)==256
native_top={t:d for t,p,d in native if t!='MCNK'};mhdr=native_top['MHDR'];mhdr_start=next(p+8 for t,p,d in native if t=='MHDR')
if 'MH2O' in srcmap:
assert native_top['MH2O']==srcmap['MH2O']
ptr=struct.unpack_from('<I',mhdr,40)[0];assert artifacts['root'][mhdr_start+ptr:mhdr_start+ptr+4]==b'O2HM'
for index,cell in enumerate(root_cells):
ix,iy=struct.unpack_from('<II',cell,4);assert (ix,iy)==(index%16,index//16);s=source_cells[ix,iy];rc=children(cell)
assert rc['MCVT']==source_child(s,'MCVT',580)[1]
nr,normal=source_child(s,'MCNR',435);assert rc['MCNR']==s[nr+8:nr+8+448]
assert cell[104:116]==s[104:116] and cell[52:56]==s[52:56]
assert struct.unpack_from('<Q',cell,20)[0]==expected_holes(struct.unpack_from('<H',s,60)[0])
assert struct.unpack_from('<I',cell)[0]==struct.unpack_from('<I',s)[0]|0x10000
for word in (3,4,7,8,9,10,11,12,14):assert struct.unpack_from('<I',cell,word*4)[0]==0
for word,tag in ((22,b'ESCM'),(29,b'VCCM')):
ptr=struct.unpack_from('<I',cell,word*4)[0]
if ptr:assert cell[ptr-8:ptr-4]==tag
cell_count+=1
for tag in set(srcmap)-{'MVER','MHDR','MCIN','MTEX','MMDX','MMID','MWMO','MWID','MDDF','MODF'}:
assert native_top[tag]==srcmap[tag]
if 'tex0' in artifacts:
tx=top(artifacts['tex0']);txmap={t:d for t,p,d in tx if t!='MCNK'};names=[v.decode().replace('\\','/').lower() for v in srcmap['MTEX'].split(b'\0') if v]
assert txmap['MAMP']==bytes(4) and txmap['MHID']==bytes(len(names)*4)
assert list(struct.unpack('<'+str(len(names))+'I',txmap['MDID']))==[bindings[p] for p in names]
tcells=[d for t,p,d in tx if t=='MCNK'];assert len(tcells)==256
for index,d in enumerate(tcells):
s=source_cells[index%16,index//16];layers=next(v for t,p,v in top(d) if t=='MCLY');assert layers==source_child(s,'MCLY')[1]
files={};prefix=row['source_reference'].rsplit('/',1)[1][:-4]
for role,data in artifacts.items():
path=out/(prefix+'.'+role+'.adt');assert not path.exists();path.write_bytes(data);path.chmod(0o600);files[role]=dict(file=str(path),bytes=len(data),sha256=hashlib.sha256(data).hexdigest());role_counts[role]+=1
unknown.update(receipt['source_unknown_top_roles'])
results.append(dict(source_reference=row['source_reference'],source_sha256_pin_reused=row['payload']['sha256'],category=row['scope']['category'],files=files,omitted_roles=sorted(set(('root','tex0','obj0'))-set(roles)),binding_receipt=str(binding_path),held=receipt['held'],publishable=False))
if first is None:first=(raw,tile,receipt,source_cells)
if first_liquid is None and any(struct.unpack_from('<I',d,100)[0]>8 and source_child(d,'MCLQ')[1]==b'' for d in source_cells.values()):
first_liquid=(raw,tile,receipt,source_cells)
assert len(results)+len(held)==462
if not resume_liquid:
# Distinct external-ID serialization boundary uses one actual source with
# complete deliberately synthetic layout bindings. No native/source asset
# equivalence is claimed or these fixture bytes staged for publication.
raw,tile,receipt,scells=first;required=set(receipt['required_bindings']['tex0'])|set(receipt['required_bindings']['obj0']);synthetic={p:0x70000000+i for i,p in enumerate(sorted(required))}
fixture,fr=adt_split_candidate(raw,tile,file_data_ids=synthetic,roles=('tex0','obj0'))
assert fr['publishable'] is False
obj={t:d for t,p,d in top(fixture['obj0']) if t!='MCNK'};source={t:d for t,p,d in top(raw) if t!='MCNK'}
for tag,width,flag_at,marker in (('MDDF',36,34,0x40),('MODF',64,56,8)):
before=source.get(tag,b'');after=obj[tag];assert len(before)==len(after)
for p in range(0,len(before),width):
assert before[p+4:p+flag_at]==after[p+4:p+flag_at]
assert before[p+flag_at+2:p+width]==after[p+flag_at+2:p+width]
assert struct.unpack_from('<H',after,p+flag_at)[0]==struct.unpack_from('<H',before,p+flag_at)[0]|marker
assert struct.unpack_from('<I',after,p)[0] in synthetic.values()
ocells=[d for t,p,d in top(fixture['obj0']) if t=='MCNK'];assert len(ocells)==256
for index,d in enumerate(ocells):
s=scells[index%16,index//16];n1,n2=struct.unpack_from('<I',s,16)[0],struct.unpack_from('<I',s,56)[0];refs=source_child(s,'MCRF')[1];target={t:v for t,p,v in top(d)}
assert target.get('MCRD',b'')==refs[:n1*4] and target.get('MCRW',b'')==refs[n1*4:] and len(refs)==4*(n1+n2)
refusals=[]
for label,ids in [('missing',{}),('zero',{p:0 for p in required}),('boolean',{p:True for p in required}),('wide',{p:2**32 for p in required})]:
try:adt_split_candidate(raw,tile,file_data_ids=ids)
except ValueError:refusals.append(label)
else:raise AssertionError('Incomplete/invalid binding admitted: '+label)
heldrow=next(r for r in source_records if pby[r['source_reference']].get('preflight_hold'))
try:adt_split_candidate(Path(heldrow['payload']['file']).read_bytes(),tuple(heldrow['scope']['tile']),file_data_ids={},roles=('root',))
except ValueError:refusals.append('actual_Source_MVER19')
else:raise AssertionError('Unreviewed Source version19 admitted')
try:adt_split_candidate(raw,tile,file_data_ids=synthetic,roles=('root','root'))
except ValueError:refusals.append('duplicate_role')
else:raise AssertionError('Duplicate role admitted')
lr,lt,_,lc=first_liquid
refusals += parent_span_refusals(lr,lt,lc,'all')
else:
# Only newly supported span refusals; priorfixture/geometry reused.
lr,lt,_,lc=first_liquid
refusals=prior['negative_cases']+parent_span_refusals(lr,lt,lc,'multiple' if resume_multiple else 'single')
(job/'source462-split-candidate-manifest.json').write_text(json.dumps(dict(status='PRIVATE_PARTIAL_ROLE_CANDIDATES_ALL_HELD',results=results,held_source_shapes=held,real_numeric_binding_input=str(binding_path),synthetic_fixture_not_staged=True),indent=2)+'\n')
report=dict(status='PASS_SOURCE462_NEW_SPLIT_CONSTRUCTOR_BOUNDARY',source_v18_assessed=462,structurally_written=len(results),held_source_shapes=held,real_role_counts=dict(role_counts),verified_source_geometry_cells=prior_cells+cell_count,newly_checked_geometry_cells=cell_count,previous_passed_geometry_cells_reused=prior_cells,source_height_normal_world_area_and_holes_preserved=True,MCSE_MCCV_and_MHDR_MH2O_offsets_checked=True,unknown_top_chunks_preserved=dict(unknown),synthetic_complete_TEX_OBJ_fixture='One actual Source body, uint32 layout only; not staged or asset equivalence evidence',negative_cases=refusals,actual_native_controls='New3strictSDK controls plus retained native2roots/obj33; old checks reused',native_render_or_publication_acceptance=False)
if resume_liquid:
report['affected_resume']='Only22multi-record parent spans; prior440geometry/roles/nine refusals reused' if resume_multiple else 'Only335previous liquid-framing holds; prior127geometry/roles/sixrefusals reused, not rerun'
(job/'completed-split-family-focused-check.json').write_text(json.dumps(report,indent=2)+'\n')
print('PASS new split constructor:Source462 assessed;written'+str(len(results))+'/held'+str(len(held)))
print('Real roles '+str(dict(role_counts))+';geometry cells '+str(cell_count)+';negative cases '+str(len(refusals)))
print('All output PRIVATE/HELD; no source/native asset-equivalence or runtime claim')
if __name__=='__main__':check(sys.argv[1],resume_liquid=any(a in sys.argv[2:] for a in ('--resume-liquid','--resume-multi-liquid')),resume_multiple='--resume-multi-liquid' in sys.argv[2:])