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

138 lines
13 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,_adt_split_records
from map_split_adt_candidate_test import top,children,source_child,expected_holes
def check(job,resume=False,source_only62=False):
job=Path(job);B=Path('runtime/rea-system-jobs-20261022/custom-map-resource-closure-20261024')
source_report=job/('qualified-new62/report.json' if source_only62 else 'qualified-source393/report.json');report=json.loads(source_report.read_text());adts=report['records'];assert len(adts)==(62 if source_only62 else 336) and report['qualified']==(62 if source_only62 else 336)
preflight={r['source_reference']:r for r in json.loads((job/('qualified-new62/preflight-checkpoint.json' if source_only62 else 'qualified-source393/preflight-checkpoint.json')).read_text())}
parent_manifest=source_report
texture_receipt=B/('Source208-selector-safe-stage-inputs/canonical-Source1028-world-texture-bindings.json' if source_only62 else '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']})
new9079=B/'combined8991-to9079-new-resource-bindings.json';extra=json.loads(new9079.read_text());bindings.update({r['source_path']:r['file_data_id'] for r in extra['SourceSwamp_bindings']})
out=job/('private-Source-only62-split' if source_only62 else 'private-new-active336-split')
if resume:
progress=json.loads((job/('Source-only62-progress.json' if source_only62 else 'active336-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/('Source-only62-progress.json' if source_only62 else 'active336-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['source_reference'] in completed:continue
reference=row['source_reference'];match=re.fullmatch(r'world/maps/([^/]+)/\1_(\d+)_(\d+)\.adt',reference);assert match
directory=match[1];tile=(int(match[2]),int(match[3]));path=Path(row['payload']['file']);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=preflight[reference]['dependencies'];roles=['root']
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=reference,directory=directory,reason=str(error),Source_payload=str(path),source_sha256_pin_reused=row['payload']['sha256']));maps[directory].append(dict(source=reference,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=reference.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=reference,directory=directory,tile=list(tile),Source_payload=str(path),source_sha256_pin_reused=row['payload']['sha256'],source_selection_status='QUALIFIED_CURRENT_EXACT393_FIRST_HIT',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=reference,status='structural_components',roles=list(output)));checkpoint()
empty_alpha_refusals=[]
if False and 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)==(62 if source_only62 else 336)
report=dict(status=('PASS_NEW_SOURCE_ONLY62_ADT_SPLIT_BOUNDARY' if source_only62 else 'PASS_NEW_ACTIVE336_SOURCE_ADT_SPLIT_BOUNDARY'),exact_missing_active_requests=(62 if source_only62 else 393),Source_ADTs_assessed=(62 if source_only62 else 336),missing_in_reviewed_builtin_set=(0 if source_only62 else 57),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/('Source-only62-focused-check.json' if source_only62 else 'new-active336-focused-check.json')).write_text(json.dumps(report,indent=2)+'\n');(job/('Source-only62-candidate-manifest.json' if source_only62 else 'new-active336-candidate-manifest.json')).write_text(json.dumps(dict(status=('PRIVATE_SOURCE_ONLY62_COMPONENTS_ALL_HELD' if source_only62 else 'PRIVATE_NEW_ACTIVE336_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/('Source-only62-per-directory-scope.json' if source_only62 else 'new-active336-per-directory-scope.json')).write_text(json.dumps(dict(maps),indent=2)+'\n')
print('PASS newactive336ADT family:written'+str(len(results))+'/held'+str(len(held)))
print('Roles '+str(dict(roles_total))+';geometry cells '+str(geometry))
print('Source capture/hash0;old208and462checks0;allPRIVATE/HELD')
def verify_tex_binding_and_layers(raw, tex0, bindings):
"""The existing TEX-only binding oracle, independent of geometry checks."""
original=top(raw);encoded=top(tex0)
names=next(d for t,p,d in original if t=='MTEX')
paths=[n.decode('ascii').replace('\\','/').lower() for n in names.split(b'\0') if n]
expected=b''.join(struct.pack('<I',bindings[p]) for p in paths)
assert next(d for t,p,d in encoded if t=='MDID')==expected
source_cells=[d for t,p,d in original if t=='MCNK']
target_cells=[d for t,p,d in encoded if t=='MCNK']
assert len(source_cells)==len(target_cells)==256
for source,target in zip(source_cells,target_cells):
words=struct.unpack_from('<32I',source)
for tag,offset,data in top(target):
assert tag in ('MCLY','MCAL','MCSH')
# The Source parent pointer avoids false tag bytes in prior data.
at=words[{'MCLY':7,'MCAL':9,'MCSH':11}[tag]]-8
if at>=128:
assert source[at:at+4]==tag[::-1].encode('ascii')
extent=struct.unpack_from('<I',source,at+4)[0]
if tag=='MCAL' and extent==0xfffff800:
assert words[10]==8
extent=0
old=source[at+8:at+8+extent]
assert len(old)==extent
else:
assert at==-8
records=_adt_split_records(source[128:],legacy_normals=True,
legacy_liquid_extent=(words[24]-136,words[25]),
legacy_alpha_extent=(words[9]-136,words[10]),maximum=128)
old=next(payload+tail for child,payload,tail in records if child==tag)
assert data==old, ('TEX source child mismatch',tag,len(data),len(old),words[10])
return paths
def close_new62_tex_only(job):
"""Only newly available TEX0 roles; preserve completed ROOT/OBJ artifacts."""
job=Path(job)
receipt=Path('runtime/rea-system-jobs-20261022/custom-map-resource-closure-20261024/Source208-selector-safe-stage-inputs/canonical-Source1028-world-texture-bindings.json')
bindings={r['source_path']:r['file_data_id'] for r in json.loads(receipt.read_text())['aliases']}
manifest_path=job/'Source-only62-candidate-manifest.json'
manifest=json.loads(manifest_path.read_text())
selected=[r for r in manifest['results'] if 'tex0' not in r['files']]
assert len(selected)==2
completed=[]
for row in selected:
filename=job/'private-Source-only62-split'/(Path(row['source_reference']).stem+'.tex0.adt')
assert not filename.exists()
raw=Path(row['Source_payload']).read_bytes()
output,audit=adt_split_candidate(raw,tuple(row['tile']),file_data_ids=bindings,roles=('tex0',))
paths=verify_tex_binding_and_layers(raw,output['tex0'],bindings)
filename.write_bytes(output['tex0'])
record=dict(file=str(filename),bytes=len(output['tex0']),sha256=hashlib.sha256(output['tex0']).hexdigest())
row['files']['tex0']=record;row['omitted_roles'].remove('tex0')
completed.append(dict(source_reference=row['source_reference'],MDID_source_paths=paths,output=record))
manifest['new2_TEX0_canonical1028_closure']=dict(bindings=str(receipt),rows=completed)
manifest_path.write_text(json.dumps(manifest,indent=2)+'\n')
result=dict(status='PASS_ONLY_TWO_NEW62_TEX0_BINDING_ROLE_CLOSURES',new_TEX0=2,layer_cells_preserved=512,
rows=completed,canonical_bindings=str(receipt),
Source_asset_capture_or_hash_or_allocation=0,old62_ROOT_OBJ_geometry_rechecks=False,
Source62_final_roles=dict(root=62,tex0=62,obj0=62),native9344_SDK_or_runtime_acceptance=False)
(job/'new2-TEX0-focused-check.json').write_text(json.dumps(result,indent=2)+'\n')
print('PASS only2newTEX0 roles;512layer cells preserved;oldROOT/OBJ unchanged')
if __name__=='__main__':
if '--close-tex-only' in sys.argv[2:]:close_new62_tex_only(sys.argv[1])
else:check(sys.argv[1],resume='--resume' in sys.argv[2:],source_only62='--source-only62' in sys.argv[2:])