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

224 lines
11 KiB
Python

#!/usr/bin/env python3
"""One affected Map169 cohort; reuse the existing liquid operand validator."""
from pathlib import Path
import ast
import hashlib
import json
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_still_river_candidate,
)
J = Path('runtime/continuation-20261107/map169-count0-still-family-private')
J.mkdir(exist_ok=True)
O = J / 'converted-ROOTs-private'
O.mkdir(exist_ok=True)
RESULT = J / 'focused-result.private.json'
assert not RESULT.exists(), 'Reuse the owning focused result; do not replay this cohort'
# The original test has a top-level historical batch. Compile only its existing
# operand/relocation verifier, so none of that batch is imported or rerun.
helper = Path('tests/map_still_river_liquid_candidate_test.py')
tree = ast.parse(helper.read_text(), filename=str(helper))
function = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == 'verify')
exec(compile(ast.Module(body=[function], type_ignores=[]), str(helper), 'exec'), globals())
P = Path('runtime/continuation-20261107/map169-next-cached-batch-private')
rows = json.loads((P / 'map169-nine-retained-liquid-ROOT-summary.private.json').read_text())
identities = {r['source_reference']: r for r in json.loads((P / 'map169-nine-prior-incomplete-role-records.private.json').read_text())}
assert len(rows) == len(identities) == 9
completed = []
held = []
refusals = []
sample = None
prior_progress = J / 'tail-only-progress.private.json'
reused_defaults = json.loads(prior_progress.read_text()) if prior_progress.exists() else None
if reused_defaults:
assert reused_defaults['unchanged_default_refusals'] == len(rows)
assert {r['source_reference'] for r in reused_defaults['rows']} == set(identities)
def convert(raw, authority, **kwargs):
kwargs.setdefault('normalize_unused_still_height_sentinels', True)
return adt_root_still_river_candidate(
raw, source_legacy_authoritative=authority, **kwargs)
def expected_unused_height_projection(raw):
"""Supply the old byte-exact validator only the admitted inactive changes."""
top = _adt_split_records(raw)
normalized = 0
for i, (tag, payload, pad) in enumerate(top):
if tag != 'MCNK':
continue
count = (struct.unpack_from('<I', payload)[0] & 0x3c).bit_count()
children = _adt_split_records(payload[128:])
for k, (child, blocks, child_pad) in enumerate(children):
if child != 'MCLQ':
continue
blocks = bytearray(blocks)
for layer in range(count):
base = layer * 804
used = set()
for n, flag in enumerate(blocks[base + 656:base + 720]):
if flag & 15 != 15:
y, x = divmod(n, 8)
used.update((9 * y + x, 9 * y + x + 1, 9 * (y + 1) + x, 9 * (y + 1) + x + 1))
for vertex in range(81):
at = base + 12 + 8 * vertex
if blocks[at:at + 4] == b'\xff\xff\x7f\x7f':
assert vertex not in used
blocks[at:at + 4] = bytes(4)
normalized += 1
children[k] = child, bytes(blocks), child_pad
top[i] = tag, payload[:128] + b''.join(_adt_split_chunk(t, b) + z for t, b, z in children), pad
return b''.join(_adt_split_chunk(t, b) + z for t, b, z in top), normalized
for row in rows:
raw = Path(row['input_ROOT']).read_bytes()
authority = any(tag == 'MH2O' for tag, payload, pad in _adt_split_records(raw))
if not reused_defaults:
try:
convert(raw, authority, normalize_unused_still_height_sentinels=False)
except ValueError as error:
assert 'bounds or flow records' in str(error)
refusals.append(dict(case='unchanged_default', source_reference=row['source_reference'], reason=str(error)))
else:
raise AssertionError('Default must still refuse nonzero physical flow tails')
try:
output, audit = convert(raw, authority, source_count0_tail_authoritative=True)
except ValueError as error:
held.append(dict(**row, remaining_hold=str(error)))
continue
comparison, normalized = expected_unused_height_projection(raw)
instances, still = verify(comparison, output)
assert instances == still == row['wet_blocks'] == audit['instances']
assert normalized == audit['normalized_unused_still_vertices']
assert audit['Source_literal_flow_count_zero_required']
assert audit['Source_nonzero_flow_count_admitted'] is False
assert audit['native_depth_shading_equivalence_verified'] is False
path = O / (Path(row['source_reference']).stem + '.root.adt')
path.write_bytes(output)
completed.append(dict(
source_reference=row['source_reference'],
source_sha256=identities[row['source_reference']]['source_sha256'],
input_ROOT=row['input_ROOT'], output_ROOT=str(path),
bytes=len(output), sha256=hashlib.sha256(output).hexdigest(),
instances=instances, normalized_unused_still_vertices=normalized, audit=audit,
historical_saved_bindings=identities[row['source_reference']]['saved_bindings']))
if sample is None:
sample = raw, output, authority
(J / 'completed-ROOT-rows.private.json').write_text(json.dumps(completed, indent=2) + '\n')
(J / 'held-ROOT-rows.private.json').write_text(json.dumps(held, indent=2) + '\n')
assert sample is not None, 'No positive real input; preserve remaining holds before expanding scope'
raw, output, authority = sample
def changed_first_block(*, count=None, tail=None, ocean=False, height=None, used_height=True):
top = _adt_split_records(raw)
changed = False
for i, (tag, payload, pad) in enumerate(top):
if tag != 'MCNK' or not (struct.unpack_from('<I', payload)[0] & 0x3c):
continue
children = _adt_split_records(payload[128:])
for k, (child, block, child_pad) in enumerate(children):
if child != 'MCLQ':
continue
block = bytearray(block)
if count is not None:
struct.pack_into('<I', block, 720, count)
if tail is not None:
block[724:804] = tail
if ocean:
for n in range(656, 720):
if block[n] & 15 != 15:
block[n] = (block[n] & 0xf0) | 1
if height is not None:
used = set()
for n, flag in enumerate(block[656:720]):
if flag & 15 != 15:
y, x = divmod(n, 8)
used.update((9 * y + x, 9 * y + x + 1, 9 * (y + 1) + x, 9 * (y + 1) + x + 1))
vertex = min(used if used_height else set(range(81)) - used)
block[12 + vertex * 8:16 + vertex * 8] = height
children[k] = child, bytes(block), child_pad
changed = True
break
top[i] = tag, payload[:128] + b''.join(_adt_split_chunk(t, b) + z for t, b, z in children), pad
break
assert changed
return b''.join(_adt_split_chunk(t, b) + z for t, b, z in top)
for count in (1, 2, 3):
try:
convert(changed_first_block(count=count, tail=bytes(80)), authority,
source_count0_tail_authoritative=True)
except ValueError as error:
assert 'bounds or flow records' in str(error)
refusals.append(dict(case='nonzero_count', count=count, reason=str(error)))
else:
raise AssertionError('Count0 authority must not admit an active flow slot')
try:
convert(changed_first_block(ocean=True, tail=bytes([0xa5]) * 80), authority,
source_count0_tail_authoritative=True)
except ValueError as error:
assert 'qualified for Still water only' in str(error)
refusals.append(dict(case='Ocean_tail_not_generalized', reason=str(error)))
else:
raise AssertionError('Still render authority must not generalize to Ocean tails')
for value in (0, 1):
try:
convert(raw, authority, source_count0_tail_authoritative=value)
except ValueError as error:
assert 'Explicit count0 tail authority' in str(error)
refusals.append(dict(case='non_boolean_authority', value=value, reason=str(error)))
else:
raise AssertionError('Explicit boolean authority required')
for value, used in ((b'\xff\xff\x7f\x7f', True), (b'\x00\x00\xc0\x7f', True), (b'\x00\x00\xc0\x7f', False)):
try:
convert(changed_first_block(height=value, used_height=used), authority,
source_count0_tail_authoritative=True)
except ValueError as error:
assert 'Nonfinite or sentinel water vertices' in str(error)
refusals.append(dict(case='unqualified_height', bits=value.hex(), used=used, reason=str(error)))
else:
raise AssertionError('Only exact positive FLT_MAX outside occupied corners may normalize')
try:
convert(raw, authority)
except ValueError as error:
assert 'requires explicit count0 authority' in str(error)
refusals.append(dict(case='Still_height_without_count0_authority', reason=str(error)))
else:
raise AssertionError('Still height opt-in requires the count0 authority')
for tail in (bytes(80), bytes([0xa5]) * 80):
same, _ = convert(changed_first_block(count=0, tail=tail), authority,
source_count0_tail_authoritative=True)
assert same == output
report = dict(
status='PASS_CHANGED_STILL_LITERAL_COUNT0_TAIL_BOUNDARY',
input_ROOT_tiles=len(rows), converted_ROOT_tiles=len(completed),
held_ROOT_tiles=len(held), instances=sum(r['instances'] for r in completed),
refusal_cases=len(refusals), refusals=refusals,
count0_tail_content_invariance_cases=2,
reused_default_refusals=9 if reused_defaults else 0,
normalized_unused_still_vertices=sum(r['normalized_unused_still_vertices'] for r in completed),
existing_operand_validator=str(helper) + '::verify',
used_heights_depth_bounds_wet_Fishable_Deep_and_nonliquid_bytes_preserved=True,
only_exact_unused_Still_FLT_MAX_normalized_to_positive_zero=True,
input_ROOT_reads=len(rows), Source_exports=0, SDK_reads=0,
raw_Source_ADT_reads=0, formerly_failed_conversions_retried=len(rows) if reused_defaults else 0,
old_batches_repeated=0, allocated_resources=0, publication=False,
installed=False, native_accepted=False,
completed_rows=str(J / 'completed-ROOT-rows.private.json'),
held_rows=str(J / 'held-ROOT-rows.private.json'))
RESULT.write_text(json.dumps(report, indent=2) + '\n')
print(report['status'])
print(f"ROOTs {len(completed)}/9; held {len(held)}; instances {report['instances']}; refusals {len(refusals)}.")