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

74 lines
7.8 KiB
Python

"""One new retained custom-map ADT family; no old continent input/check repeats."""
from pathlib import Path
import collections,hashlib,json,re,struct,sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from map_asset_preflight import adt_split_candidate,classic_adt_dependencies
from map_split_adt_candidate_test import top,children,source_child,expected_holes
def check(job,resume=False):
job=Path(job);B=Path('runtime/rea-system-jobs-20261022/custom-map-resource-closure-20261024')
parent_manifest=B/'current-wdt-parent-resource-manifest.json';parents=json.loads(parent_manifest.read_text());adts=[r for r in parents['parents'] if r['path'].endswith('.adt')];assert len(adts)==208
source_dir=Path('runtime/new-area-dependency-batch-20261019/payloads')
texture_receipt=B/'complete-source796-texture-bindings.json';bindings={r['source_path']:r['file_data_id'] for r in json.loads(texture_receipt.read_text())['aliases']}
wmo_receipt=B/'WMO-root26-stage-handoff.json';wmos=json.loads(wmo_receipt.read_text());bindings.update({r['source_member']:r['file_data_id'] for r in wmos['all26_source_paths_to_root_FDIDs']})
out=job/'private-retained208-split'
if resume:
progress=json.loads((job/'retained208-progress.json').read_text());results=list(progress['results']);roles_total=collections.Counter(progress['role_counts']);geometry=progress['geometry_cells'];maps=collections.defaultdict(list,progress['maps']);completed={r['source_reference'] for r in results}
else:
assert not out.exists();out.mkdir(mode=0o700);results=[];roles_total=collections.Counter();geometry=0;maps=collections.defaultdict(list);completed=set()
held=[];refreshed=[];prior_geometry=geometry;underflow_sample=None
def checkpoint():
(job/'retained208-progress.json').write_text(json.dumps(dict(results=results,held=held,role_counts=dict(roles_total),geometry_cells=geometry,maps=dict(maps)),indent=2)+'\n')
for row in adts:
if row['path'] in completed:continue
match=re.fullmatch(r'world/maps/([^/]+)/\1_(\d+)_(\d+)\.adt',row['path']);assert match
directory=match[1];tile=(int(match[2]),int(match[3]));path=source_dir/(row['sha256']+'.adt');assert path.is_file() and not path.is_symlink()
raw=path.read_bytes();
if underflow_sample is None and b'LACM'+struct.pack('<I',0xfffff800) in raw:underflow_sample=(raw,tile)
deps=row['retained_candidate']['dependencies'];roles=['root']
if 'textures' not in deps:
try:deps=classic_adt_dependencies(raw);refreshed.append(dict(source=row['path'],prior=row['retained_candidate']['dependencies'],current=deps))
except ValueError as error:
held.append(dict(source_reference=row['path'],directory=directory,reason=str(error),Source_payload=str(path),source_sha256_pin_reused=row['sha256']));checkpoint();continue
if set(deps['textures'])<=set(bindings):roles.append('tex0')
if set(deps['model_placements']['referenced_assets'])|set(deps['wmo_placements']['referenced_assets'])<=set(bindings):roles.append('obj0')
try:output,audit=adt_split_candidate(raw,tile,file_data_ids=bindings,roles=tuple(roles))
except ValueError as error:
held.append(dict(source_reference=row['path'],directory=directory,reason=str(error),Source_payload=str(path),source_sha256_pin_reused=row['sha256']));maps[directory].append(dict(source=row['path'],status='shape_held',reason=str(error)));checkpoint();continue
assert set(output)==set(roles) and audit['publishable'] is False
original=top(raw);source_cells={(struct.unpack_from('<I',d,4)[0],struct.unpack_from('<I',d,8)[0]):d for t,p,d in original if t=='MCNK'};root=top(output['root']);rcells=[d for t,p,d in root if t=='MCNK'];assert len(rcells)==256
for index,target in enumerate(rcells):
xy=struct.unpack_from('<II',target,4);assert xy==(index%16,index//16);source=source_cells[xy];parts=children(target)
assert parts['MCVT']==source_child(source,'MCVT',580)[1]
at,normal=source_child(source,'MCNR');assert len(normal) in (435,448)
assert parts['MCNR']==source[at+8:at+8+448]
assert target[104:116]==source[104:116] and target[52:56]==source[52:56]
flags=struct.unpack_from('<I',source)[0];holes=int.from_bytes(source[20:28],'little') if flags&0x10000 else expected_holes(struct.unpack_from('<H',source,60)[0]);assert int.from_bytes(target[20:28],'little')==holes
assert struct.unpack_from('<I',target)[0]==flags|0x10000
geometry+=1
st={t:d for t,p,d in original if t!='MCNK'};rt={t:d for t,p,d in root if t!='MCNK'}
for tag in set(st)-{'MVER','MHDR','MCIN','MTEX','MMDX','MMID','MWMO','MWID','MDDF','MODF'}:assert rt[tag]==st[tag]
files={};prefix=row['path'].rsplit('/',1)[1][:-4]
for role,data in output.items():
p=out/(prefix+'.'+role+'.adt');assert not p.exists();p.write_bytes(data);p.chmod(0o600);files[role]=dict(file=str(p),bytes=len(data),sha256=hashlib.sha256(data).hexdigest());roles_total[role]+=1
result=dict(source_reference=row['path'],directory=directory,tile=list(tile),Source_payload=str(path),source_sha256_pin_reused=row['sha256'],source_selection_status=row['selection_status'],files=files,required_bindings=audit['required_bindings'],omitted_roles=sorted(set(('root','tex0','obj0'))-set(output)),holds=audit['held'],WMO_bindings_structural_only=True,publishable=False);results.append(result);maps[directory].append(dict(source=row['path'],status='structural_components',roles=list(output)));checkpoint()
empty_alpha_refusals=[]
if underflow_sample is not None:
raw,tile=underflow_sample
selected=next((p,d) for t,p,d in top(raw) if t=='MCNK' and b'LACM'+struct.pack('<I',0xfffff800) in d)
at,cell=selected;layer_at=cell.find(b'YLCM',128)+8
for label,relative,value in [('alpha_parent_offset',36,struct.unpack_from('<I',cell,36)[0]+1),('alpha_parent_not_header_only',40,4),('alpha_parent_layer_count_mismatch',12,1)]:
bad=bytearray(raw);struct.pack_into('<I',bad,at+8+relative,value)
try:adt_split_candidate(bytes(bad),tile,file_data_ids={},roles=('root',))
except ValueError:empty_alpha_refusals.append(label)
else:raise AssertionError('Unsafe empty-alpha underflow admitted: '+label)
assert len(results)+len(held)==208
report=dict(status='PASS_NEW_RETAINED208_CUSTOM_MAP_SPLIT_BOUNDARY',retained_parent_denominator=209,Source_ADTs_assessed=208,Source_global_WMO_parent_other_owner=1,Source_ADT_components_written=len(results),Source_ADT_shape_holds=held,real_role_counts=dict(roles_total),geometry_cells_verified=geometry,Source_height_normal_world_AreaID_holes_unknown_top_data_preserved=True,Source_parent_reexport_or_hash_sweep=0,previously_blocked_dependency_refresh=refreshed,old_continent462_or_SDK_checks_repeated=False,prior_geometry_cells_reused=prior_geometry,empty_alpha_category_refusals=empty_alpha_refusals,WMO26_numeric_binding_only=True,WMO26_material_fidelity_proven=False,active_publication_or_renderer_acceptance=False)
(job/'retained208-focused-check.json').write_text(json.dumps(report,indent=2)+'\n');(job/'retained208-candidate-manifest.json').write_text(json.dumps(dict(status='PRIVATE_RETAINED208_COMPONENTS_ALL_HELD',parent_manifest=str(parent_manifest),texture_binding_receipt=str(texture_receipt),WMO_binding_receipt=str(wmo_receipt),results=results,held=held),indent=2)+'\n');(job/'per-directory-structural-scope.json').write_text(json.dumps(dict(maps),indent=2)+'\n')
print('PASS retained208newADT family:written'+str(len(results))+'/held'+str(len(held)))
print('Roles '+str(dict(roles_total))+';geometry cells '+str(geometry))
print('Source capture/hash0;old462checks0;allPRIVATE/HELD')
if __name__=='__main__':check(sys.argv[1],resume='--resume' in sys.argv[2:])