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

89 lines
5.0 KiB
Python

"""One changed structural boundary; original resource/render acceptance stays held."""
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 wdt_global_wmo_candidate, wdt_global_wmo_native_template
def check(job):
job = Path(job)
control = json.loads((job/'native34-global-WMO-control-analysis.json').read_text())
native = Path(control['file']).read_bytes()
template = wdt_global_wmo_native_template(native)
rows = json.loads((job/'current-global-WMO-source-constructor-inputs.json').read_text())
completed = []; held = []; sample = None
for index, row in enumerate(rows):
source = Path(row['file']).read_bytes()
directory = row['path'].split('/')[2]
raw_path = row['MWMO'][:-1].replace('\\', '/').lower()
# Deliberately synthetic layout bindings; no asset/path equivalence or
# new allocation is asserted by this test's uint32 field exercise.
binding = 0x70000000 + index
args = dict(directory=directory, source_wmo_path=raw_path,
mapped_root_file_data_id=binding)
try:
candidate, receipt = wdt_global_wmo_candidate(template, source, **args)
except ValueError as error:
assert row['MODF'][0][1] == 0 and str(error) == 'Unreviewed source global MODF identity'
held.append(dict(path=row['path'], reason=str(error)))
continue
assert row['MODF'][0][1] == 0xffffffff
assert receipt['publishable'] is False and receipt['status'].startswith('HELD_')
at = template.modf_payload_offset
# Exact allowed span; MPHD, native empty grids, all opaque refs/tail are
# independently compared against original control, not writer fields.
assert candidate[:at] == native[:at]
assert candidate[at+56:] == native[at+56:]
assert struct.unpack_from('<I', candidate, at)[0] == binding
source_at = source.index(b'FDOM')+8
assert candidate[at+4:at+56] == source[source_at+4:source_at+56]
assert struct.unpack_from('<4H', candidate, at+56) == (8,0,0,1024)
completed.append(dict(path=row['path'], output_sha256=hashlib.sha256(candidate).hexdigest(),
synthetic_layout_binding=binding, runtime_eligible=False))
if sample is None: sample = (source,args,source_at)
assert len(rows) == 20 and len(completed) == 17 and len(held) == 3
source,args,modf_at = sample
def changed(offset, fmt, *values):
body=bytearray(source);struct.pack_into(fmt,body,offset,*values);return bytes(body)
main_at=source.index(b'NIAM')+8
mphd_at=source.index(b'DHPM')+8
negative = [
('source_tile', changed(main_at,'<I',1),args),
('source_extension',changed(mphd_at+4,'<I',1),args),
('source_modf_flag',changed(modf_at+56,'<H',4),args),
('source_modf_set',changed(modf_at+58,'<H',1),args),
('source_nonfinite',changed(modf_at+8,'<f',float('nan')),args),
('source_reversed_bounds',changed(modf_at+32,'<f',struct.unpack_from('<f',source,modf_at+44)[0]+1000.0),args),
('source_second_instance',source+b'FDOM'+struct.pack('<I',64)+source[modf_at:modf_at+64],args),
('source_truncated',source[:-1],args),
('zero_binding',source,dict(args,mapped_root_file_data_id=0)),
('boolean_binding',source,dict(args,mapped_root_file_data_id=True)),
('wrong_path',source,dict(args,source_wmo_path='world/wmo/unrelated.wmo')),
('traversal',source,dict(args,source_wmo_path='world/../unrelated.wmo')),
]
refused=[]
for name,body,kw in negative:
try:wdt_global_wmo_candidate(template,body,**kw)
except ValueError:refused.append(name)
else:raise AssertionError('unsafe structural candidate accepted: '+name)
bad=bytearray(native);bad[-1]^=1
try:wdt_global_wmo_native_template(bytes(bad))
except ValueError:refused.append('wrong_original_template')
else:raise AssertionError('wrong template accepted')
result=dict(status='PASS_WHOLE_RETAINED_GLOBAL_WMO_STRUCTURAL_FAMILY',
source_cohort=20,structurally_prepared=17,held_identity=held,
prepared=completed,refusal_cases=refused,fixture_bindings='Synthetic uint32 layout only; no allocated assets or source-native resource assertion',
native_template_prepared_once=True,source_placement_and_bounds_byte_exact=True,
opaque_companions_and_native_grid_and_tail_unchanged=True,
actual_source_native_resource_or_render_acceptance=False,
prior_terrain_or_SDK_checks_repeated=False)
(job/'global-WMO-structural-family-focused-check.json').write_text(json.dumps(result,indent=2)+'\n')
print('PASS:20cohort/17structural/3identity holds;13negative boundaries refused')
print('Original companions/grid/tail andSource52BMODF span preserved exactly')
print('Synthetic bindings only; allcandidate publication/runtime gates remain held')
if __name__ == '__main__':check(sys.argv[1])