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

132 lines
6.9 KiB
Python

"""Changed20-tile Ocean role boundary; prior geometry/alpha/SDK evidence reused."""
import collections
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_split_candidate
B = Path('runtime/rea-system-jobs-20261022')
J = B / 'terrain-liquid-closure-20261025'
OUTPUT = J / 'private-flat-Ocean20-ROOT'
OUTPUT.mkdir(exist_ok=True)
all139 = json.loads((J/'legacy139-water-operand-leaves.json').read_text())['rows']
flat89 = [r for r in all139 if r['all_blocks_original_ocean_depth_profile_candidate']]
selected = [r for r in flat89 if all(set(map(int,b['Source_cell_flag_values'])) <= {15,65} for b in r['blocks'])]
assert len(selected) == 20
def encode(top):
return b''.join(_adt_split_chunk(t,d)+tail for t,d,tail in top)
def verify(old, new, expected):
before, after = _adt_split_records(old), _adt_split_records(new)
h2o = next(d for t,d,tail in after if t=='MH2O')
assert [(t,d,x) for t,d,x in before if t not in ('MCNK','MHDR')] == [
(t,d,x) for t,d,x in after if t not in ('MCNK','MHDR','MH2O')]
a = next(d for t,d,x in before if t=='MHDR')
b = next(d for t,d,x in after if t=='MHDR')
assert a[:40]+a[44:] == b[:40]+b[44:]
pos = 0
for t,d,x in after:
if t=='MH2O':assert struct.unpack_from('<I',b,40)[0] == pos-20
pos += 8+len(d)+len(x)
blocks = {tuple(r['cell']):r for r in expected['blocks']}
old_cells = [d for t,d,x in before if t=='MCNK']
new_cells = [d for t,d,x in after if t=='MCNK']
assert len(old_cells) == len(new_cells) == 256
for oldcell,newcell in zip(old_cells,new_cells):
wa,wb = struct.unpack_from('<32I',oldcell),struct.unpack_from('<32I',newcell)
assert wb[0] == wa[0]&~0x3c and wb[24:26]==(0,0)
assert all(wa[i]==wb[i] for i in range(1,32) if i not in (22,24,25,29))
ca,cb = _adt_split_records(oldcell[128:]),_adt_split_records(newcell[128:])
assert [(t,d,x) for t,d,x in ca if t!='MCLQ'] == cb
offsets = {};pos=128
for t,d,x in cb:offsets[t]=pos+8;pos+=8+len(d)+len(x)
assert wb[22]==offsets.get('MCSE',0) and wb[29]==offsets.get('MCCV',0)
x,y=wa[1:3]
instance,count,attrs = struct.unpack_from('<3I',h2o,(y*16+x)*12)
source = blocks.get((x,y))
if source is None:
assert (instance,count,attrs)==(0,0,0)
continue
assert count==1 and instance>=3072 and attrs>=3072
typ,lvf,lo,hi,ox,oy,w,h,bits,vertices=struct.unpack_from('<HHffBBBBII',h2o,instance)
assert (typ,lvf,lo,hi,ox,oy,w,h)==(2,42,0.,0.,0,0,8,8)
fish,deep=struct.unpack_from('<QQ',h2o,attrs)
bitmap=int.from_bytes(bytes.fromhex(source['wet_bitmap_hex']),'little')
assert struct.unpack_from('<Q',h2o,bits)[0]==bitmap==fish and deep==0
assert h2o[vertices:vertices+81]==bytes.fromhex(source['depth_bytes_hex'])
progress=J/'Ocean20-completed-candidate-rows.jsonl'
results=[json.loads(l) for l in progress.read_text().splitlines()] if progress.exists() else []
done={r['source_reference'] for r in results}
for row in selected:
if row['source_reference'] in done:continue
raw=Path(row['input_ROOT']).read_bytes()
output,audit=adt_root_flat_ocean_candidate(raw)
verify(raw,output,row)
filename=OUTPUT/(Path(row['source_reference']).stem+'.root.adt')
filename.write_bytes(output)
result=dict(source_reference=row['source_reference'],input_ROOT=row['input_ROOT'],output_ROOT=str(filename),
bytes=len(output),sha256=hashlib.sha256(output).hexdigest(),audit=audit)
results.append(result)
with progress.open('a') as out:out.write(json.dumps(result,separators=(',',':'))+'\n')
# Mutate only newly admitted liquid fields on one accepted input.
sample=selected[0];raw=Path(sample['input_ROOT']).read_bytes();top=_adt_split_records(raw)
cell_index=next(i for i,(t,d,x) in enumerate(top) if t=='MCNK' and struct.unpack_from('<I',d)[0]&0x3c)
cell=top[cell_index][1];children=_adt_split_records(cell[128:]);bi=next(i for i,r in enumerate(children) if r[0]=='MCLQ')
body=children[bi][1];wet=next(i for i,v in enumerate(body[656:720]) if v==65)
def reject(changed):
try:adt_root_flat_ocean_candidate(encode(changed))
except ValueError:return
raise AssertionError('Unproved Ocean operand or attribute accepted')
def reject_block(offset,value):
block=bytearray(body);block[offset:offset+len(value)]=value
changed_children=list(children);changed_children[bi]=('MCLQ',bytes(block),b'')
changed=list(top);changed[cell_index]=('MCNK',cell[:128]+encode(changed_children),b'')
reject(changed)
for flag in (33,161):reject_block(656+wet,bytes([flag]))
y,x=divmod(wet,8);reject_block(12+(y*9+x)*8,struct.pack('<f',1.))
reject_block(0,struct.pack('<f',1.))
reject_block(720,struct.pack('<I',1))
reject_block(724,b'\1')
reject_block(9,b'\1')
reject_block(656+wet,b'\x44')
changed=list(top);changed.insert(cell_index,('MH2O',bytes(3072),b''));reject(changed)
header=bytearray(cell[:128]);struct.pack_into('<I',header,100,1616)
changed=list(top);changed[cell_index]=('MCNK',bytes(header)+cell[128:],b'');reject(changed)
dry=json.loads((J/'dry562-candidate-manifest.json').read_text())['rows'][0]
reject(_adt_split_records(Path(dry['input_ROOT']).read_bytes()))
# New producer opt-in once; its unchanged default must match the prior artifact.
capture=json.loads((B/'continent-terrain-Source463-20261025/qualified-source463/report.json').read_text())
source_row=next(r for r in capture['records'] if r['source_reference']==sample['source_reference'])
source=Path(source_row['payload']['file']).read_bytes()
tile=tuple(map(int,Path(sample['source_reference']).stem.rsplit('_',2)[1:]))
default,_=adt_split_candidate(source,tile,file_data_ids={},roles=('root',))
assert default['root']==raw
integrated,_=adt_split_candidate(source,tile,file_data_ids={},roles=('root',),normalize_flat_ocean_liquid=True)
assert integrated['root']==Path(results[0]['output_ROOT']).read_bytes()
report=dict(status='PASS_EXACT20_FLAT_OCEAN_ATTRIBUTE_MATCHING_BOUNDARY',Source_denominator=1006,
legacy_only_tiles=139,flat_Ocean_tiles_assessed=89,admitted_whole_tiles=20,
flat_Ocean_attribute_held_tiles=69,other_legacy_held_tiles=50,existing_MH2O_held_tiles=305,
Source_wet_flag=65,native_LiquidType=2,native_LVF_field=42,Fishable='Source wet bitmap',Deep=0,
native_instances=sum(len(r['blocks']) for r in selected),refusals=11,
other_ROOT_header_words_and_payloads_byte_exact=True,default_byte_exact_cases=1,integrated_cases=1,
old_geometry_alpha_SDK_checks_repeated=False,publishable=False)
(J/'Ocean20-focused-check.json').write_text(json.dumps(report,indent=2)+'\n')
(J/'Ocean20-candidate-manifest.json').write_text(json.dumps(dict(status=report['status'],rows=results),indent=2)+'\n')
print(json.dumps(report))