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

107 lines
7.3 KiB
Python

#!/usr/bin/env python3
"""Only Root's36 newly enabled exact-bound ocean ROOTs; no478 reclassification."""
import ast,hashlib,json,struct,sys
from pathlib import Path
BASE=Path(__file__).resolve().parents[1];sys.path.insert(0,str(BASE/'ops'))
from map_asset_preflight import (_adt_split_records,_adt_split_chunk,
_adt_flat_ocean_source_surface,adt_root_flat_ocean_candidate)
J=BASE/'runtime/continuation-20261026/openworld-zero-surface-FLT_MIN-Ocean36'
J.mkdir(exist_ok=True);OUT=J/'private-ROOT36';OUT.mkdir(exist_ok=True)
operand_path=BASE/'runtime/continuation-20261026/Root-named-openworld-area-status/held-outdoor-liquid-operands.json'
metadata=json.loads(operand_path.read_text())
items=[r for r in metadata['rows'] if r['header_only_nonzero_Ocean_candidate']
and any(b['header_min_max']==[0.,1.1754943508222875e-38] for b in r['blocks'])]
assert len(items)==36
# Existing pure nonliquid geometry/header/opaque verifier, without its old loop.
p=BASE/'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 verify(raw,new):
before,after=_adt_split_records(raw),_adt_split_records(new)
verify_cells(encode([r for r in before if r[0]=='MCNK']),encode([r for r in after if r[0]=='MCNK']))
assert [r for r in before if r[0]not in('MCNK','MHDR','MH2O')]==[r for r in after if r[0]not in('MCNK','MHDR','MH2O')]
oldh,newh=struct.unpack('<16I',before[1][1]),struct.unpack('<16I',after[1][1])
assert all(oldh[i]==newh[i] for i in range(16) if i not in(9,10,11))
cursor=0;offsets={}
for tag,data,tail in after:
if tag in('MFBO','MH2O','MTXF'):offsets[tag]=cursor-20
cursor+=8+len(data)+len(tail)
for word,tag in((9,'MFBO'),(10,'MH2O'),(11,'MTXF')):assert newh[word]==offsets.get(tag,0)
liquid=next(d for t,d,z in after if t=='MH2O');counts={'0/0':0,'0/FLT_MIN':0};sample=None
for tag,cell,tail in before:
if tag!='MCNK':continue
words=struct.unpack_from('<32I',cell);x,y=words[1:3];offset,count,attributes=struct.unpack_from('<3I',liquid,(y*16+x)*12)
if not words[0]&0x3c:assert(offset,count,attributes)==(0,0,0);continue
source=next(d for t,d,z in _adt_split_records(cell[128:]) if t=='MCLQ')[:804]
assert count==1 and liquid[offset:offset+4]==struct.pack('<HH',2,42)
assert liquid[offset+4:offset+12]==source[:8]
counts['0/FLT_MIN' if source[:8]==struct.pack('<2I',0,0x00800000) else '0/0']+=1
if source[:8]==struct.pack('<2I',0,0x00800000):sample=source
ox,oy,w,h,bits,vertices=struct.unpack_from('<4BII',liquid,offset+12)
assert(ox,oy,w,h)==(0,0,8,8)
flags=source[656:720];exists=sum(1<<i for i,f in enumerate(flags) if f&15!=15)
fish=sum(1<<i for i,f in enumerate(flags) if f&15!=15 and f&0x40)
deep=sum(1<<i for i,f in enumerate(flags) if f&15!=15 and f&0x80)
assert struct.unpack_from('<Q',liquid,bits)[0]==exists
assert struct.unpack_from('<QQ',liquid,attributes)==(fish,deep)
assert liquid[vertices:vertices+81]==bytes(source[8+v*8] for v in range(81))
return counts,sample
rows=[];totals={'0/0':0,'0/FLT_MIN':0};sample=None
progress=J/'progress.json'
prior=json.loads(progress.read_text()) if progress.exists() else dict(rows=[],totals=totals)
rows=prior['rows'];totals=prior['totals'];done={r['source_reference'] for r in rows}
for item in items:
if item['source_reference'] in done:continue
raw=Path(item['input_ROOT']).read_bytes()
legacy=any(t=='MH2O' for t,d,z in _adt_split_records(raw))
new,audit=adt_root_flat_ocean_candidate(raw,source_legacy_authoritative=legacy,
allow_zero_surface_flt_min_bounds=True)
counts,current_sample=verify(raw,new);sample=current_sample or sample
assert audit['Source_exact_FLT_MIN_bound_cells']==counts['0/FLT_MIN']
assert audit['Source_raw_bounds_bytes_preserved'] and not audit['original_native_runtime_bounds_consumer_verified']
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'],file=str(dest),
bytes=len(new),sha256=hashlib.sha256(new).hexdigest(),native_group_control=790857,
Source_bounds_counts=counts,audit=audit,role='ROOT',source_geometry_and_nonliquid_bytes_preserved=True))
totals={k:totals[k]+counts[k] for k in totals}
progress.write_text(json.dumps(dict(rows=rows,totals=totals),indent=2)+'\n')
if sample is None:
# A resumed check reuses only the saved relevant804B specimen.
sample=(J/'changed-FLT_MIN-surface-specimen.bin').read_bytes()
else:(J/'changed-FLT_MIN-surface-specimen.bin').write_bytes(sample)
expected_bounds={'0/0':sum(b['header_min_max']==[0.,0.] for r in items for b in r['blocks']),
'0/FLT_MIN':sum(b['header_min_max']==[0.,1.1754943508222875e-38] for r in items for b in r['blocks'])}
assert len(rows)==36 and totals==expected_bounds=={'0/0':3369,'0/FLT_MIN':5624}
refusals=[]
def refuse(label,block,**kw):
try:_adt_flat_ocean_source_surface(block,**kw)
except ValueError:refusals.append(label)
else:raise AssertionError('Unproved Ocean operand admitted: '+label)
refuse('default strict unchanged',sample)
for label,at,value in [('next max bitpattern',4,struct.pack('<I',0x00800001)),
('nonzero min',0,struct.pack('<f',1.)),('negative-zero min',0,struct.pack('<I',0x80000000)),
('nonfinite max',4,struct.pack('<I',0x7f800000)),('NaNmax',4,struct.pack('<I',0x7fc00000)),
('unknown wetflag',656,b'\x09'),('nonzero union',9,b'\x01'),
('flowcount',720,struct.pack('<I',1)),('flowtail',724,b'\x01')]:
block=bytearray(sample);block[at:at+len(value)]=value
refuse(label,bytes(block),allow_zero_surface_flt_min_bounds=True)
wet=next(i for i,f in enumerate(sample[656:720]) if f&15!=15)
block=bytearray(sample);struct.pack_into('<I',block,12+((wet//8)*9+wet%8)*8,1)
refuse('nonzero used height even subnormal',bytes(block),allow_zero_surface_flt_min_bounds=True)
refuse('nonboolean optin',sample,allow_zero_surface_flt_min_bounds=1)
report=dict(status='PASS_PRIVATE_CHANGED36_EXACT_ZERO_SURFACE_FLT_MIN_OCEAN_BOUNDS',
inputs=36,admitted=36,Source_bounds_blocks=totals,refusals=refusals,
exact_raw_bounds_bytes_preserved=True,all_nonliquid_geometry_and_opaque_bytes_preserved=True,
used_surface_height_exact_zero_no_tolerance=True,other14_whole_Ocean_candidates_not_admitted_or_reclassified=True,
original_Source5014_first_reachable_surface_contract_reused=True,
original_native_runtime_bounds_consumer_not_newly_proved=True,native_acceptance=False,publishable=False,
old478_operand_pass_or_Source_exports_SDK_or_old_tests_repeated=False)
(J/'focused-result.json').write_text(json.dumps(report,indent=2)+'\n')
(J/'ROOT36-component-manifest.json').write_text(json.dumps(dict(status=report['status'],rows=rows,
original_operand_receipt=str(operand_path),focused_check=str(J/'focused-result.json'),
native_format_control=790857,new_IDs_allocated=False,stage_or_WDT_association=False),indent=2)+'\n')
print(report['status'])