883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
105 lines
6.1 KiB
Python
105 lines
6.1 KiB
Python
"""Five original Map/Area controls through package composition and real codec.
|
|
|
|
Consumes already prepared unchanged original bodies; does not construct Source
|
|
rows, re-run the full-table encoder review, or contact a native client.
|
|
"""
|
|
import argparse
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
sys.path.insert(0, str(ROOT / 'tests'))
|
|
import item_sparse_compat as composer
|
|
from native_codec_driver import MODES, load, serialize
|
|
from preworld_creation_hotfix_test import decode_hotfix
|
|
|
|
DEFAULT_INPUTS = ROOT / 'runtime/rea-system-jobs-20261022/map-zone-definition-closure-20261024/original-control-composition'
|
|
OBSERVED = {}
|
|
|
|
|
|
class OriginalMapAreaPackageTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.inputs = Path(os.environ['GW_MAP_AREA_CONTROL_INPUTS'])
|
|
cls.rows = json.loads((cls.inputs / 'original-five-records.json').read_text())
|
|
cls.pages = json.loads((cls.inputs / 'original-five-pages.json').read_text())['pages']
|
|
cls.expected = {(int(r['table_hash'], 16), r['id']): bytes.fromhex(r['wire_hex']) for r in cls.rows}
|
|
if set(cls.expected) != {(0xBD84CD62, 0), (0xBD84CD62, 1), (0xBD84CD62, 33), (0x7253EB43, 1), (0x7253EB43, 77)}:
|
|
raise AssertionError('Changed original control scope')
|
|
cls.library = load()
|
|
|
|
def test_compiled_preworld_advertisement_and_complete_page(self):
|
|
wire = serialize(self.library, MODES.index('--native-client-initialization'), struct.pack('<IIQ', 0x10046, 0, 12345))
|
|
packets, opcode, size = struct.unpack_from('<3I', wire)
|
|
self.assertGreater(packets, 0)
|
|
self.assertEqual(opcode, 0x4B0001)
|
|
_, count = struct.unpack_from('<II', wire, 12)
|
|
advertised = [struct.unpack_from('<II', wire, 20 + 8 * i) for i in range(count)]
|
|
self.assertEqual({push for push, status in advertised if status == 1}, {p['push_id'] for p in self.pages})
|
|
found = {}
|
|
for page in self.pages:
|
|
request = struct.pack('<4I', 70334, 70334, 1, page['push_id'])
|
|
payload = serialize(self.library, MODES.index('--native-hotfix-reply'), request)
|
|
records = decode_hotfix(payload)
|
|
self.assertEqual(len(payload), page['wire_bytes'])
|
|
self.assertEqual(len(records), page['count'])
|
|
for index, record in enumerate(records, page['first'] + 1):
|
|
push, entry, table, identity, status, body = record
|
|
self.assertEqual((push, entry, status), (page['push_id'], index, 32))
|
|
self.assertNotIn((table, identity), found)
|
|
found[table, identity] = body
|
|
self.assertEqual(found, self.expected)
|
|
OBSERVED['page_payloads'] = {'rows': len(found), 'pages': len(self.pages), 'all_original_bodies_exact': True}
|
|
|
|
def test_compiled_table_and_record_lookup_including_Map0(self):
|
|
for (table, identity), expected in self.expected.items():
|
|
with self.subTest(table=hex(table), identity=identity):
|
|
wire = serialize(self.library, MODES.index('--native-db-reply-missing'), struct.pack('<III', table, identity, 12345))
|
|
self.assertEqual(struct.unpack_from('<III', wire), (table, identity, 12345))
|
|
self.assertEqual(wire[12], 32)
|
|
self.assertEqual(wire[17:], expected)
|
|
# Same IDs in two registered tables must never alias; a row present in
|
|
# Area must not appear when requested from the private Map profile.
|
|
absent = serialize(self.library, MODES.index('--native-db-reply-missing'), struct.pack('<III', 0xBD84CD62, 77, 12345))
|
|
self.assertNotEqual(absent[12], 32)
|
|
self.assertEqual(len(absent), 17)
|
|
OBSERVED['compiled_lookup'] = {'positive_records': len(self.expected), 'Map0_valid': True, 'cross_table_alias_refused': True}
|
|
|
|
def test_only_complete_valid_Map0_can_cross_composer(self):
|
|
original = next(r for r in self.rows if r['table_name'] == 'Map' and r['id'] == 0)
|
|
cases = []
|
|
row = copy.deepcopy(original); row['table_name'] = 'AreaTable'; cases.append(('wrong name', row))
|
|
row = copy.deepcopy(original); row['table_hash'] = '0x7253EB43'; cases.append(('nonMap zero', row))
|
|
row = copy.deepcopy(original); row['record_status'] = 'removed'; cases.append(('tombstone zero', row))
|
|
row = copy.deepcopy(original); del row['record']['WdtFileDataID']; cases.append(('incomplete native row', row))
|
|
row = copy.deepcopy(original); row['record']['ID'] = 1; cases.append(('record identity mismatch', row))
|
|
row = copy.deepcopy(original); body = bytes([bytes.fromhex(row['wire_hex'])[0] ^ 1]) + bytes.fromhex(row['wire_hex'])[1:]; row['wire_hex'] = body.hex(); row['sha256'] = hashlib.sha256(body).hexdigest(); cases.append(('wire body mismatch', row))
|
|
row = copy.deepcopy(original); row.pop('record'); cases.append(('untyped raw zero', row))
|
|
for label, row in cases:
|
|
with self.subTest(label=label), self.assertRaises(ValueError):
|
|
composer._package_data([row])
|
|
OBSERVED['composer_refusals'] = len(cases)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--codec', type=Path, required=True)
|
|
parser.add_argument('--inputs', type=Path, default=DEFAULT_INPUTS)
|
|
parser.add_argument('--result', type=Path, required=True)
|
|
arguments = parser.parse_args()
|
|
os.environ['GW_TEST_CODEC_PATH'] = str(arguments.codec.resolve())
|
|
os.environ['GW_MAP_AREA_CONTROL_INPUTS'] = str(arguments.inputs.resolve())
|
|
result = unittest.TextTestRunner(verbosity=2).run(unittest.defaultTestLoader.loadTestsFromTestCase(OriginalMapAreaPackageTest))
|
|
arguments.result.write_text(json.dumps({'status': 'PASS' if result.wasSuccessful() else 'FAIL',
|
|
'tests': result.testsRun, 'failures': len(result.failures), 'errors': len(result.errors),
|
|
'observed': OBSERVED, 'source_constructed_rows': 0, 'native_client_or_auth_action': False,
|
|
'private_codec': str(arguments.codec.resolve())}, indent=2) + '\n')
|
|
sys.exit(0 if result.wasSuccessful() else 1)
|