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

117 lines
6.3 KiB
Python

#!/usr/bin/env python3
"""One two-tile batch for the additional retained native ROOT layout class."""
import copy
import hashlib
import json
import os
from pathlib import Path
import struct
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import map_conversion_batch as batch
from map_conversion_batch_test import adt_fixture, chunk
def no_color_fixture():
parts = []
for tag, body, _ in batch.terrain._adt_split_records(adt_fixture(native=True)):
if tag == 'MCNK':
body = struct.pack('<I', 0x18000) + body[4:]
parts.append(chunk(tag, body))
return b''.join(parts)
class NoMCCVBoundary(unittest.TestCase):
def test_one_two_tile_batch_and_new_class_boundary(self):
profile = batch.terrain.NATIVE_NEAR_TERRAIN_NO_MCCV_PROFILE_V1
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
def ref(name, raw):
path = root / name
path.write_bytes(raw)
return dict(path=str(path), sha256=hashlib.sha256(raw).hexdigest(), bytes=len(raw))
owner_manifest = os.environ.get('GW_NEAR_TERRAIN_NO_MCCV_MANIFEST')
if owner_manifest:
request = json.loads(Path(owner_manifest).read_text())
else:
receipt = ref('profile.json', batch.encoded(profile))
provenance = ref('fixture-contract.json', batch.encoded({
'kind': 'fixture-only-original-contract-pin'}))
request = dict(kind='map-conversion-batch-v1', payloads={
'native': ref('native.adt', no_color_fixture()),
'source': ref('source.adt', adt_fixture()),
'holes': ref('holes.adt', adt_fixture(bad_holes=True))}, contracts={
'profile': dict(operation='native-patch', admission='private-candidate',
api='adt_near_terrain_profile_candidate', receipt=receipt,
accepted_kind=profile['kind'], provenance=[provenance])}, jobs=[
dict(id=ident, kind='adt', source=source, native='native',
map_id=1, tile=[44,20], native_file_data_id=787430,
contracts={'native-patch':'profile'})
for ident, source in [('geometry', 'source'), ('holes', 'holes')]])
self.assertEqual(len(request['jobs']), 2)
output = Path(os.environ.get('GW_NEAR_TERRAIN_NO_MCCV_OUTPUT', str(root / 'candidates')))
report = batch.convert_batch(request, output)
self.assertEqual((report['resolved'], report['held']), (1, 1))
self.assertFalse(report['candidate_content_complete'])
held = next(r for r in report['rows'] if r['status'] == 'HELD')
self.assertIn('hole change', held['reason'])
row = next(r for r in report['rows'] if r['status'] == 'CONVERTED')
job = next(j for j in request['jobs'] if j['id'] == row['id'])
native = Path(request['payloads'][job['native']]['path']).read_bytes()
source = Path(request['payloads'][job['source']]['path']).read_bytes()
candidate = (output / row['outputs'][0]['file']).read_bytes()
audit = json.loads((output / row['audit']['file']).read_text())
self.assertEqual(len(candidate), len(native))
self.assertEqual(audit['cells'], 256)
self.assertFalse(audit['installable'])
spans = sorted(audit['allowed_spans'], key=lambda s: s['native_offset'])
self.assertEqual(len(spans), 768)
previous = 0
for span in spans:
n, s, size = (span[k] for k in ('native_offset', 'source_offset', 'bytes'))
self.assertLessEqual(previous, n)
self.assertEqual(candidate[previous:n], native[previous:n])
self.assertEqual(candidate[n:n+size], source[s:s+size])
previous = n + size
if span['kind'] == 'existing_MCNR':
self.assertEqual(candidate[n+435:n+448], native[n+435:n+448])
self.assertEqual(candidate[previous:], native[previous:])
self.assertEqual(batch.terrain.adt_height_profile(candidate, tuple(job['tile']))['V9'],
batch.terrain.adt_height_profile(source, tuple(job['tile']))['V9'])
# Only the new class's admission is probed: arbitrary descriptors,
# a color child, or a nonzero retained color offset remain refused.
bad_profile = dict(profile, native_MCNK_flags=0x18001)
with self.assertRaisesRegex(ValueError, 'Unqualified'):
batch.terrain.adt_near_terrain_profile_candidate(b'', b'', job['tile'],
map_id=job['map_id'], native_file_data_id=job['native_file_data_id'],
native_profile=bad_profile)
parts = batch.terrain._adt_split_records(native)
for mode in ('child', 'offset'):
changed = []; first = True
for tag, body, _ in parts:
if tag == 'MCNK' and first:
first = False
if mode == 'child':
body += chunk('MCCV', bytes(580))
else:
body = body[:116] + struct.pack('<I', 1) + body[120:]
changed.append(chunk(tag, body))
with self.assertRaisesRegex(ValueError, 'color relationship'):
batch.terrain.adt_near_terrain_profile_candidate(b''.join(changed), source,
job['tile'], map_id=job['map_id'],
native_file_data_id=job['native_file_data_id'], native_profile=profile)
receipt = dict(status='PASS_NEW_NO_MCCV_CLASS_TWO_TILE_BOUNDARY',
report=str(output / 'report.json'), requested=2, converted=1, held=1,
cells=256, spans=768, native_normal_tails_preserved=256,
unchanged_outside_spans=True, new_class_color_relationship_refusals=2,
arbitrary_profile_refused=True, old_tests_repeated=False,
installed=False, runtime_verified=False)
(output.parent / 'focused-check.private.json').write_bytes(batch.encoded(receipt))
if __name__ == '__main__':
unittest.main()