883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
124 lines
7.7 KiB
Python
124 lines
7.7 KiB
Python
from pathlib import Path
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import item_model_assets as assets
|
|
|
|
|
|
def run(alias_only=False):
|
|
with tempfile.TemporaryDirectory(prefix='native-base-variant-', dir=ROOT / 'runtime') as tmp:
|
|
folder = Path(tmp)
|
|
body = bytearray(280)
|
|
body[:8] = struct.pack('<4sI', b'MD20', 272)
|
|
struct.pack_into('<II', body, 80, 1, 264)
|
|
raw = struct.pack('<4sI', b'MD21', len(body)) + body
|
|
raw += struct.pack('<4sII', b'SFID', 4, 22)
|
|
txid_offset = len(raw) + 8
|
|
raw += struct.pack('<4sII', b'TXID', 4, 33)
|
|
old_native = bytearray(raw)
|
|
struct.pack_into('<I', old_native, txid_offset, 32)
|
|
native_key = hashlib.md5(old_native).hexdigest()
|
|
sha = hashlib.sha256(raw).hexdigest()
|
|
output = folder / 'variant.m2'
|
|
output.write_bytes(raw)
|
|
texture = dict(kind='texture', file_data_id=33, content_key='b' * 32)
|
|
parents = [dict(kind='model', file_data_id=i, path=f'fixture/{i}.m2', source_paths=[f'world/generic/fixture{i}.m2']) for i in (11, 12, 13)]
|
|
baseline = dict(assets=parents + [texture])
|
|
records = []
|
|
for parent in parents:
|
|
native_id = parent['file_data_id'] + 100
|
|
native_file = str(folder / f'{native_id}-original.m2')
|
|
audit = dict(kind='owned-explicit-TXID-rebind-v1', all_non_TXID_bytes_preserved=True,
|
|
non_TXID_sha256=hashlib.sha256(raw[:txid_offset] + bytes(4) + raw[txid_offset+4:]).hexdigest(),
|
|
old_texture_ids=[32], new_texture_ids=[33], changed_slots=[0],
|
|
skin_file_ids=[22], animation_files=[], native_base_file_data_id=native_id,
|
|
native_base_content_key=native_key, native_base_file=native_file,
|
|
Source_geometry_and_all4draws_exact=True, Source_bone_native_Stand_sampling_operands_exact=True,
|
|
Source_collision_triangle_multisets_exact=True, Stand_original_metadata_preserved=True,
|
|
all_native_non_TXID_bytes_preserved=True, Stand_index=2)
|
|
records.append(dict(parent_model_file_data_id=parent['file_data_id'], parent_asset=copy.deepcopy(parent),
|
|
Source_paths=parent['source_paths'], file=str(output), bytes=len(raw), sha256=sha,
|
|
content_key=hashlib.md5(raw).hexdigest(),
|
|
path='wowhybrid/source-equipment/material-variants/' + sha + '.m2',
|
|
native_base_file_data_id=native_id, native_base_content_key=native_key,
|
|
native_base_typed_record=dict(kind='model', native_FDI=native_id,
|
|
content_key=native_key, file=native_file, bytes=len(raw)),
|
|
native_skin_first_read=dict(file_data_id=22, content_key='c' * 32), audit=audit,
|
|
texture_replacements=[dict(old_file_data_id=32, new_file_data_id=33,
|
|
new_content_key=texture['content_key'], Source_texture_asset=texture)]))
|
|
family = dict(kind='validated-native-base-Source-texture-Stand-crate-model-variant-family-v1',
|
|
status='PASS_THREE_QUALIFIED_CRATE_NATIVE_AUTHORED_STAND_SOURCE_TEXTURE_VARIANTS',
|
|
parent_manifest_sha256='a' * 64, all_non_TXID_bytes_preserved=True, SKIN_imports=0,
|
|
qualified=3, whole_family=6, Source_geometry_SKIN_reconversion=0,
|
|
Native_Stand_alias_or_flag_edits=0, Source_weight_animation_equivalence_not_claimed=True,
|
|
records=records)
|
|
cases = []
|
|
for name, mutate, allowed in [
|
|
('valid-native-base-source-material', None, True),
|
|
('unqualified-geometry', lambda f: f['records'][0]['audit'].update(Source_geometry_and_all4draws_exact=False), False),
|
|
('unqualified-Stand-pose', lambda f: f['records'][0]['audit'].update(Source_bone_native_Stand_sampling_operands_exact=False), False),
|
|
('changed-native-base', lambda f: f['records'][0].update(native_base_content_key='d' * 32), False),
|
|
('changed-original-Stand', lambda f: f['records'][0]['audit'].update(Stand_original_metadata_preserved=False), False),
|
|
('wrong-skin-proof', lambda f: f['records'][0]['native_skin_first_read'].update(file_data_id=23), False),
|
|
('changed-Source-material-asset', lambda f: f['records'][0]['texture_replacements'][0]['Source_texture_asset'].update(kind='model'), False),
|
|
('changed-original-body-mask', lambda f: f['records'][0]['audit'].update(non_TXID_sha256='0' * 64), False),
|
|
('Source-nonTXID-equivalence-overclaim', lambda f: f.update(Source_weight_animation_equivalence_not_claimed=False), False),
|
|
('partial-cohort', lambda f: f.update(records=f['records'][:2]), False),
|
|
('stale-parent', lambda f: f.update(parent_manifest_sha256='e' * 64), False),
|
|
]:
|
|
if alias_only:
|
|
continue
|
|
value = copy.deepcopy(family)
|
|
if mutate:
|
|
mutate(value)
|
|
proof = folder / (name + '.json')
|
|
proof.write_text(json.dumps(value))
|
|
try:
|
|
selected, audit = assets._validated_owned_model_variants(
|
|
proof, hashlib.sha256(proof.read_bytes()).hexdigest(), baseline, 'a' * 64)
|
|
except ValueError as error:
|
|
assert not allowed, (name, str(error))
|
|
cases.append(dict(case=name, result='REFUSED', reason=str(error)))
|
|
else:
|
|
assert allowed and len(selected) == 3 and audit['native_base_Stand_models']
|
|
assert not audit['Source_parent_non_TXID_equivalence_claimed']
|
|
cases.append(dict(case=name, result='ADMITTED'))
|
|
alias_baseline = copy.deepcopy(baseline)
|
|
alias_baseline['models'] = []
|
|
for parent in alias_baseline['assets'][:3]:
|
|
members = parent.pop('source_paths')
|
|
alias_baseline['models'].append(dict(path=parent['path'], source_candidates=[dict(member=x) for x in members]))
|
|
for name, wrong, allowed in [('registered-model-candidate-alias', False, True), ('unrelated-model-alias', True, False)]:
|
|
current = copy.deepcopy(alias_baseline)
|
|
value = copy.deepcopy(family)
|
|
for record, parent in zip(value['records'], current['assets'][:3]):
|
|
record['parent_asset'] = copy.deepcopy(parent)
|
|
if wrong:
|
|
current['models'][0]['path'] = 'fixture/unrelated.m2'
|
|
proof = folder / (name + '.json')
|
|
proof.write_text(json.dumps(value))
|
|
try:
|
|
selected, audit = assets._validated_owned_model_variants(
|
|
proof, hashlib.sha256(proof.read_bytes()).hexdigest(), current, 'a' * 64)
|
|
except ValueError as error:
|
|
assert not allowed, (name, str(error))
|
|
cases.append(dict(case=name, result='REFUSED', reason=str(error)))
|
|
else:
|
|
assert allowed and len(selected) == 3
|
|
cases.append(dict(case=name, result='ADMITTED'))
|
|
return dict(status='PASS_QUALIFIED_NATIVE_BASE_SOURCE_MATERIAL_ADMISSION_AND_REFUSALS', cases=cases,
|
|
actual_old_Source_or_native_body_reads=0, synthetic_only=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
result = run(alias_only='--alias-only' in sys.argv)
|
|
if len(sys.argv) >= 2:
|
|
Path(sys.argv[1]).write_text(json.dumps(result, indent=2) + '\n')
|
|
print('Native-base Source-material admission PASS:', len(result['cases']), 'affected cases')
|