883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
137 lines
6.5 KiB
Python
137 lines
6.5 KiB
Python
"""Original 70334 Map/Area hotfix-body boundary, without source construction.
|
|
|
|
The explicit field contract is retained independently of the production DBD
|
|
parser. Decode every readable original row and compare every original value;
|
|
never fill absent fields or decrypt the separately inventoried native records.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import spell_passive_compat as producer
|
|
|
|
|
|
def decode_original_body(body, expected_fields, record_id):
|
|
values = {'ID': record_id}
|
|
offset = 0
|
|
for name, kind, bits, unsigned, count in expected_fields:
|
|
decoded = []
|
|
for _ in range(count):
|
|
if kind in ('string', 'locstring'):
|
|
end = body.find(b'\0', offset)
|
|
if end < offset:
|
|
raise AssertionError((name, 'unterminated string'))
|
|
decoded.append(body[offset:end].decode('utf-8'))
|
|
offset = end + 1
|
|
elif kind == 'float':
|
|
decoded.append(struct.unpack_from('<f', body, offset)[0])
|
|
offset += 4
|
|
elif kind == 'int':
|
|
width = bits // 8
|
|
part = body[offset:offset + width]
|
|
if len(part) != width:
|
|
raise AssertionError((name, 'truncated integer'))
|
|
decoded.append(int.from_bytes(part, 'little', signed=not unsigned))
|
|
offset += width
|
|
else:
|
|
raise AssertionError((name, 'unknown explicit native type'))
|
|
values[name] = decoded if count != 1 else decoded[0]
|
|
if offset != len(body):
|
|
raise AssertionError(('unconsumed native body', offset, len(body)))
|
|
return values
|
|
|
|
|
|
def compare_original_row(row, decoded, expected_fields):
|
|
if set(row) != set(decoded):
|
|
raise AssertionError(('complete native field identity', row['ID']))
|
|
for name, kind, _, _, count in expected_fields:
|
|
expected = row[name] if count != 1 else [row[name]]
|
|
actual = decoded[name] if count != 1 else [decoded[name]]
|
|
if kind == 'float':
|
|
expected = [struct.unpack('<f', struct.pack('<f', v))[0] for v in expected]
|
|
if actual != expected:
|
|
raise AssertionError((row['ID'], name, 'original value changed'))
|
|
|
|
|
|
def run(input_directory):
|
|
contracts = json.loads((ROOT / 'tests/fixtures/map-area-native-encoder-schema.json').read_text())
|
|
results = {}
|
|
retained_contexts = {}
|
|
for table, contract in contracts.items():
|
|
explicit_fields = [tuple(f) for f in contract['fields']]
|
|
schema = producer.fields(ROOT.parent / 'tools/WoWDBDefs/definitions' / (table + '.dbd'), table)
|
|
if schema != explicit_fields:
|
|
raise AssertionError((table, 'native declaration sequence changed'))
|
|
th, lh, sequence_pin = producer.SUPPLEMENTAL_TABLES[table]
|
|
if (f'{th:08X}', f'{lh:08X}', sequence_pin) != (
|
|
contract['table_hash'], contract['layout_hash'], contract['field_sequence_sha256']):
|
|
raise AssertionError((table, 'native header/schema registration'))
|
|
rows = json.loads((input_directory / contract['input_basename']).read_text())
|
|
if len(rows) != contract['expected_readable_rows']:
|
|
raise AssertionError((table, 'changed original input scope'))
|
|
retained_contexts[table] = (schema, rows[0])
|
|
seen = set()
|
|
total_bytes = 0
|
|
body_digest = hashlib.sha256()
|
|
for row in rows:
|
|
if row['ID'] in seen:
|
|
raise AssertionError((table, 'duplicate original ID'))
|
|
seen.add(row['ID'])
|
|
body = producer.encode(row, schema, table=table)
|
|
compare_original_row(row, decode_original_body(body, explicit_fields, row['ID']), explicit_fields)
|
|
body_digest.update(row['ID'].to_bytes(4, 'little'))
|
|
body_digest.update(len(body).to_bytes(4, 'little'))
|
|
body_digest.update(body)
|
|
total_bytes += len(body)
|
|
# Fail closed at the new table boundary; no default WDT/map relationship.
|
|
missing = dict(rows[0])
|
|
required = 'WdtFileDataID' if table == 'Map' else 'ContinentID'
|
|
del missing[required]
|
|
try:
|
|
producer.encode(missing, schema, table=table)
|
|
except ValueError as error:
|
|
if 'Complete native row required' not in str(error):
|
|
raise
|
|
else:
|
|
raise AssertionError((table, 'missing field silently defaulted'))
|
|
results[table] = {'readable_original_rows': len(rows), 'complete_values_preserved': True,
|
|
'payload_bytes': total_bytes, 'encoded_original_body_sha256': body_digest.hexdigest(),
|
|
'missing_field_refused': required, 'source_rows_constructed': 0}
|
|
map_schema, original_map_zero = retained_contexts['Map']
|
|
area_schema, original_area = retained_contexts['AreaTable']
|
|
if original_map_zero['ID'] != 0:
|
|
raise AssertionError('original Map0 control missing')
|
|
zero_area = dict(original_area, ID=0)
|
|
refused = []
|
|
for label, callback, expected_error in [
|
|
('default_ID0', lambda: producer.encode(original_map_zero, map_schema), 'Integer bound: ID'),
|
|
('nonMap_ID0', lambda: producer.encode(zero_area, area_schema, table='AreaTable'), 'Integer bound: ID'),
|
|
('wrong_schema_for_Map', lambda: producer.encode(original_area, area_schema, table='Map'), 'Native table/schema identity differs')]:
|
|
try:
|
|
callback()
|
|
except ValueError as error:
|
|
if expected_error not in str(error):
|
|
raise
|
|
refused.append(label)
|
|
else:
|
|
raise AssertionError((label, 'unsafe ID namespace accepted'))
|
|
return {'status': 'PASS_ORIGINAL_MAP_AREA_ENCODING_BOUNDARY', 'tables': results,
|
|
'explicit_Map0_positive': True, 'scope_refusals': refused,
|
|
'encrypted_rows_not_decoded': {'Map': 8, 'AreaTable': 46},
|
|
'source_projection_publication_or_activation_claimed': False}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--inputs', type=Path, default=ROOT / 'runtime/rea-system-jobs-20261022/map-zone-definition-closure-20261024')
|
|
parser.add_argument('--result', type=Path, required=True)
|
|
arguments = parser.parse_args()
|
|
result = run(arguments.inputs)
|
|
arguments.result.write_text(json.dumps(result, indent=2) + '\n')
|
|
print('PASS original Map71/Area1373 row encoding and missing-field refusal')
|