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

140 lines
6.3 KiB
Python

"""One affected liquid-absence boundary on accepted ROOT artifacts, not geometry replay."""
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_dry_liquid_candidate, adt_split_candidate
B = Path('runtime/rea-system-jobs-20261022')
J = B / 'terrain-liquid-closure-20261025'
OUTPUT = J / 'private-dry562-ROOT'
OUTPUT.mkdir(exist_ok=True)
def encode(records):
return b''.join(_adt_split_chunk(tag, data) + tail for tag, data, tail in records)
def reject(raw):
try:
adt_root_dry_liquid_candidate(raw)
except ValueError:
return
raise AssertionError('Unproved liquid/ROOT input was accepted')
def verify(old, new):
before, after = _adt_split_records(old), _adt_split_records(new)
assert [(t, d, x) for t, d, x in after if t == 'MH2O'] == [('MH2O', bytes(3072), b'')]
assert [(t, d, x) for t, d, x in before if t not in ('MHDR', 'MCNK')] == [
(t, d, x) for t, d, x in after if t not in ('MHDR', 'MCNK', '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)
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 a, b in zip(old_cells, new_cells):
wa, wb = struct.unpack_from('<32I', a), struct.unpack_from('<32I', b)
assert all(wa[i] == wb[i] for i in range(32) if i not in (22, 24, 25, 29))
assert wb[24:26] == (0, 0)
ca = _adt_split_records(a[128:], maximum=128)
cb = _adt_split_records(b[128:], maximum=128)
assert [(t, d, x) for t, d, x in ca if t != 'MCLQ'] == cb
pos = 128
offsets = {}
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)
inputs = {}
for filename in [
B / 'continent-native-split-ADT-20261025/source462-split-candidate-manifest.json',
B / 'custom-map-retained-ADT-split-20261025/retained208-candidate-manifest.json',
B / 'new-map-active-Source393-20261025/new-active336-candidate-manifest.json',
]:
for row in json.loads(filename.read_text())['results']:
inputs[row['source_reference']] = row['files']['root']['file']
selected = []
with (J / 'completed-liquid-leaves.jsonl').open() as stream:
for line in stream:
row = json.loads(line)
if row['all_256_Source_header_or_cell_dry']:
selected.append({k: row[k] for k in ('source_reference', 'payload', 'cohort')})
assert len(selected) == 562
progress = J / 'dry562-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(inputs[row['source_reference']]).read_bytes()
candidate, audit = adt_root_dry_liquid_candidate(raw)
verify(raw, candidate)
filename = OUTPUT / (Path(row['source_reference']).stem + '.root.adt')
filename.write_bytes(candidate)
result = dict(row, input_ROOT=inputs[row['source_reference']], output_ROOT=str(filename),
bytes=len(candidate), sha256=hashlib.sha256(candidate).hexdigest(), audit=audit)
results.append(result)
with progress.open('a') as stream:
stream.write(json.dumps(result, separators=(',', ':')) + '\n')
# These cases target the new gate only; completed geometry/alpha checks are reused.
sample = selected[0]
raw = Path(inputs[sample['source_reference']]).read_bytes()
top = _adt_split_records(raw)
index = next(i for i, r in enumerate(top) if r[0] == 'MCNK')
cell = top[index][1]
for word, value in [(0, struct.unpack_from('<I', cell)[0] | 4), (25, 812), (0, 0)]:
changed = bytearray(cell)
struct.pack_into('<I', changed, word * 4, value)
mutated = list(top)
mutated[index] = ('MCNK', bytes(changed), b'')
reject(encode(mutated))
changed = list(top)
changed.insert(index, ('MH2O', bytes(3072), b''))
reject(encode(changed))
children = [r for r in _adt_split_records(cell[128:]) if r[0] != 'MCLQ']
children.append(('MCLQ', bytes(804), b''))
changed = list(top)
changed[index] = ('MCNK', cell[:128] + encode(children), b'')
reject(encode(changed))
reject(encode(top[:index] + top[index + 1:]))
changed = list(top)
header = bytearray(changed[1][1])
struct.pack_into('<I', header, 40, 64)
changed[1] = ('MHDR', bytes(header), b'')
reject(encode(changed))
# The unchanged default is checked once against its accepted artifact; opt-in
# integration must equal this completed post-conversion boundary exactly.
tile = tuple(map(int, Path(sample['source_reference']).stem.rsplit('_', 2)[1:]))
source = Path(sample['payload']).read_bytes()
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_dry_liquid_absence=True)
assert integrated['root'] == adt_root_dry_liquid_candidate(raw)[0]
report = dict(status='PASS_DRY562_CHANGED_LIQUID_ABSENCE_BOUNDARY', Source_tiles=1006,
admitted_dry_tiles=562, retained_other_liquid_tiles=444,
native_MH2O_zero_instance_rows=562 * 256,
old_geometry_alpha_or_SDK_checks_repeated=False,
only_liquid_headers_pointers_and_empty_MCLQ_removed=True,
all_other_ROOT_child_payloads_header_words_and_top_payloads_byte_exact=True,
refusals=7, default_path_byte_exact_cases=1, integrated_opt_in_cases=1,
cohort_counts=dict(collections.Counter(r['cohort'] for r in selected)),
active_liquid_or_material_or_runtime_acceptance=False)
(J / 'dry562-focused-check.json').write_text(json.dumps(report, indent=2) + '\n')
(J / 'dry562-candidate-manifest.json').write_text(json.dumps(dict(status=report['status'], rows=results), indent=2) + '\n')
print(json.dumps(report))