883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
132 lines
6.5 KiB
Python
132 lines
6.5 KiB
Python
"""Original 70334 LoadingScreens rows through the existing metadata pipeline.
|
|
|
|
This checks the newly registered wire table and its generated C++ lookup only.
|
|
It constructs no Source rows, defaults or image bindings and invokes no client.
|
|
"""
|
|
import argparse
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
sys.path.insert(0, str(ROOT / 'tests'))
|
|
import spell_passive_compat as encoder
|
|
import item_sparse_compat as composer
|
|
from map_area_native_encoder_test import decode_original_body, compare_original_row
|
|
|
|
|
|
def run(inputs, work):
|
|
work.mkdir(parents=True, exist_ok=True)
|
|
contract = json.loads((ROOT / 'tests/fixtures/loading-screens-native-schema.json').read_text())
|
|
expected_fields = [tuple(field) for field in contract['fields']]
|
|
schema = encoder.fields(ROOT.parent / 'tools/WoWDBDefs/definitions/LoadingScreens.dbd', 'LoadingScreens')
|
|
assert schema == expected_fields
|
|
table, layout, field_pin = encoder.SUPPLEMENTAL_TABLES['LoadingScreens']
|
|
assert (f'{table:08X}', f'{layout:08X}', field_pin) == (
|
|
contract['table_hash'], contract['layout_hash'], contract['field_sequence_sha256'])
|
|
encoder.db2_header(inputs / 'native70334-LoadingScreens.db2', table, layout)
|
|
originals = json.loads((inputs / 'native70334-LoadingScreens-full.json').read_text())
|
|
assert len(originals) == contract['expected_readable_logical_rows']
|
|
assert len({row['ID'] for row in originals}) == len(originals)
|
|
rows, bodies = [], {}
|
|
for original in originals:
|
|
body = encoder.encode(original, schema, table='LoadingScreens')
|
|
compare_original_row(original, decode_original_body(body, expected_fields, original['ID']), expected_fields)
|
|
assert len(body) == 40
|
|
bodies[original['ID']] = body
|
|
rows.append(dict(table_hash=f'0x{table:08x}', table_name='LoadingScreens',
|
|
id=original['ID'], record=original, record_status='valid',
|
|
wire_hex=body.hex(), sha256=hashlib.sha256(body).hexdigest()))
|
|
# The copied original records have independent noninline identities but
|
|
# equal original bodies; preserving both IDs is part of the new boundary.
|
|
assert bodies[194] == bodies[186]
|
|
assert bodies[196] == bodies[187]
|
|
refused = 0
|
|
first = originals[0]
|
|
invalid = []
|
|
row = copy.deepcopy(first); del row['MainImageFileDataID']; invalid.append((row, schema, 'LoadingScreens'))
|
|
row = copy.deepcopy(first); row['HasWideScreen'] = 0; invalid.append((row, schema, 'LoadingScreens'))
|
|
row = copy.deepcopy(first); row['ID'] = 0; invalid.append((row, schema, 'LoadingScreens'))
|
|
row = copy.deepcopy(first); row['Field_8_1_5_28938_006'] = float('nan'); invalid.append((row, schema, 'LoadingScreens'))
|
|
invalid.append((first, schema[:-1], 'LoadingScreens'))
|
|
invalid.append((first, schema, 'Map'))
|
|
for row, fields, table_name in invalid:
|
|
try:
|
|
encoder.encode(row, fields, table=table_name)
|
|
except ValueError:
|
|
refused += 1
|
|
else:
|
|
raise AssertionError('Unsafe new LoadingScreens row/schema admitted')
|
|
assert refused == len(invalid)
|
|
push, header, pages = composer._package_data(rows)
|
|
assert sum(page['count'] for page in pages) == len(rows)
|
|
assert sum(page['wire_bytes'] - 8 for page in pages) == len(rows) * (21 + 40)
|
|
header_path = work / 'original-loading-screens.hpp'
|
|
header_path.write_text(header)
|
|
# Compile and execute the actual generated generic table lookup, rather
|
|
# than parsing header text or simulating its lookup in Python.
|
|
source_path = work / 'original-loading-screens-lookup.cpp'
|
|
source_path.write_text('''#include <cstdio>
|
|
#include "original-loading-screens.hpp"
|
|
int main() {
|
|
using namespace gateway::item_sparse_compat;
|
|
for (const auto& row : Records) {
|
|
const auto actual = find(row.table, row.id);
|
|
const uint32_t prefix[] = {row.table, row.id, static_cast<uint32_t>(actual.size())};
|
|
if (std::fwrite(prefix, sizeof(prefix), 1, stdout) != 1 ||
|
|
std::fwrite(actual.data(), 1, actual.size(), stdout) != actual.size()) return 2;
|
|
}
|
|
if (!find(0xEF9DC6FF, 0).empty() || !find(0xBD84CD62, 23).empty()) return 3;
|
|
return 0;
|
|
}
|
|
''')
|
|
executable = work / 'original-loading-screens-lookup'
|
|
command = ['clang++', '-std=c++20', '-O0', '-Wall', '-Wextra', '-Werror',
|
|
str(source_path), '-o', str(executable)]
|
|
(work / 'compile-command.json').write_text(json.dumps(command, indent=2) + '\n')
|
|
with (work / 'compile.log').open('w') as log:
|
|
subprocess.run(command, stdout=log, stderr=subprocess.STDOUT, check=True)
|
|
binary = subprocess.run([str(executable)], check=True, capture_output=True).stdout
|
|
actual, offset = {}, 0
|
|
while offset < len(binary):
|
|
native_table, ident, size = struct.unpack_from('<III', binary, offset)
|
|
offset += 12
|
|
assert native_table == table and size == 40
|
|
assert ident not in actual
|
|
actual[ident] = binary[offset:offset + size]
|
|
offset += size
|
|
assert offset == len(binary) and actual == bodies
|
|
(work / 'original55-records.json').write_text(json.dumps(rows, indent=2) + '\n')
|
|
(work / 'original55-pages.json').write_text(json.dumps(dict(push_id=push, pages=pages), indent=2) + '\n')
|
|
return dict(status='PASS_ORIGINAL_LOADINGSCREENS_ENCODER_COMPOSER_CPP_LOOKUP',
|
|
original_logical_rows=len(rows), preserved_copy_pairs=2,
|
|
fields_per_row=len(schema), bytes_per_body=40,
|
|
missing_or_unsafe_field_schema_refusals=refused,
|
|
generated_header_compiled=True, actual_cpp_lookup_rows=len(actual),
|
|
zero_and_wrong_table_lookup_refused=True,
|
|
source_constructor_rows=0, native_client_or_runtime_application=False)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--inputs', type=Path, required=True)
|
|
parser.add_argument('--work', type=Path, required=True)
|
|
parser.add_argument('--result', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
try:
|
|
result = run(args.inputs, args.work)
|
|
except Exception as error:
|
|
result = dict(status='FAIL_NEW_LOADINGSCREENS_BOUNDARY',
|
|
error_type=type(error).__name__, error=str(error))
|
|
args.result.write_text(json.dumps(result, indent=2) + '\n')
|
|
raise
|
|
args.result.write_text(json.dumps(result, indent=2) + '\n')
|
|
os.chmod(args.result, 0o600)
|
|
print(result['status'])
|