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

107 lines
6.3 KiB
Python

#!/usr/bin/env python3
"""Real source3091 conversion; audio payload and renderer parity not inferred."""
import copy
import json
from pathlib import Path
import struct
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'ops'))
from spell_sound_compat import new_sound_candidate, sound_inventory, source_sound
from spell_passive_compat import BUILD, fields
class SoundConversionTest(unittest.TestCase):
def test_inventory_retains_unused_weights_without_relaxing_converter(self):
source=json.loads((ROOT/'tests/fixtures/source-spell-sound.json').read_text())['source']
raw=list(source['source_row']);raw[3+9]=0;raw[13+9]=1
class Disk:
fields=29;rows=[raw];by_id={raw[0]:raw}
def string(self,offset):return source['source_strings'][str(offset)]
def digest(self):return 'a'*64
with self.assertRaisesRegex(ValueError,'weight without file'):source_sound(Disk(),raw[0])
r=sound_inventory(Disk(),{})
self.assertEqual(r['records'][0]['unused_file_weights'],[dict(slot=9,frequency=1)])
self.assertFalse(r['records'][0]['reviewed_simple_spell_family'])
def test_full_inventory_retains_all_files_and_unreviewed_families(self):
f=json.loads((ROOT/'tests/fixtures/source-spell-sound.json').read_text())
source=f['source'];raw=source['source_row'];other=list(raw);other[0]=999;other[25]=0x200
class Disk:
fields=29;rows=[raw,other];by_id={raw[0]:raw,999:other}
def string(self,offset):return source['source_strings'][str(offset)]
def digest(self):return 'a'*64
paths=[v['path']for v in source['files']]
native={paths[0]:[1],paths[1].rsplit('.',1)[0]+'.ogg':[2],paths[2]:[3,4]}
r=sound_inventory(Disk(),native)
self.assertEqual(r['source_records'],2);self.assertEqual(r['parsed_records'],2)
self.assertEqual(r['file_status_counts'],{'ambiguous':2,'encoding-variant-candidate':2,'exact-path-candidate':2,'missing-native-path':4})
by_id={row['id']:row for row in r['records']}
self.assertTrue(by_id[source['id']]['reviewed_simple_spell_family'])
self.assertFalse(by_id[999]['reviewed_simple_spell_family'])
self.assertFalse(r['asset_bytes_verified']);self.assertFalse(r['converted'])
self.assertEqual(r,sound_inventory(Disk(),native))
def fixture(self):
f = json.loads((ROOT / 'tests/fixtures/source-spell-sound.json').read_text())
schemas = {t: fields(ROOT.parent / 'tools/WoWDBDefs/definitions' / (t + '.dbd'), t) for t in ('SoundKit', 'SoundKitEntry')}
return [f['source'], f['native_kit'], f['native_entries'], {int(k): v for k, v in f['native_names'].items()},
schemas, dict(SoundKit=374813, SoundKitEntry=1734088),
dict(schema_version=1, build=BUILD, SoundKit={}, SoundKitEntry={}),
dict(SoundKit={3091}, SoundKitEntry={293466, 293467, 293468, 293469, 293470})]
def test_source_settings_and_variants_retained_under_new_id(self):
v = self.fixture(); before = copy.deepcopy(v); result = new_sound_candidate(*v)
self.assertEqual(v, before); self.assertEqual(result['native_sound_id'], 374814)
self.assertEqual(len(result['records']), 6); kit = result['records'][0]['record']
self.assertEqual((kit['VolumeFloat'], kit['MinDistance'], kit['DistanceCutoff'], kit['Flags']), (1, 8, 45, 0))
self.assertEqual(kit['SoundKitAdvancedID'], 0)
self.assertEqual([r['record']['FileDataID'] for r in result['records'][1:]], [569828, 569827, 569830, 569829, 569831])
self.assertTrue(all(r['record']['SoundKitID'] == 374814 for r in result['records'][1:]))
self.assertTrue(all(r['source_path'].endswith('.wav') and r['native_path'].endswith('.ogg') for r in result['file_mappings']))
self.assertFalse(result['existing_records_modified']); self.assertFalse(result['installable'])
self.assertFalse(result['audio_payload_equivalence_verified'])
def test_independent_53_and_17_byte_wire_vectors(self):
result = new_sound_candidate(*self.fixture())
expected = struct.pack('<ififfBI4fbfHBI', 1, 1, 0, 8, 45, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self.assertEqual(len(expected), 53)
self.assertEqual(bytes.fromhex(result['records'][0]['wire_hex']), expected)
for row in result['records'][1:]:
expected = struct.pack('<IiBfi', 374814, row['record']['FileDataID'], 1, 1, 0)
self.assertEqual(len(expected), 17); self.assertEqual(bytes.fromhex(row['wire_hex']), expected)
def test_stable_registry_and_collision_guards(self):
v = self.fixture(); r = new_sound_candidate(*v); v[6] = r['child_id_registry']
self.assertEqual(new_sound_candidate(*v), r)
for mode in ('new-collision', 'collision', 'floor', 'key'):
v = self.fixture()
if mode == 'new-collision': v[7]['SoundKit'].add(374814)
elif mode == 'collision': v[6]['SoundKit']['3091'] = 374814; v[7]['SoundKit'].add(374814)
elif mode == 'floor': v[6]['SoundKit']['3091'] = 374813
else: v[6]['SoundKitEntry']['3091:10'] = 1734089
with self.assertRaises(ValueError): new_sound_candidate(*v)
def test_reject_normalized_source_mismatch_and_unsupported_flags(self):
for key, value in (('volume', .5), ('flags', 0x200), ('sound_type', 2), ('eax_def', True)):
v = self.fixture(); v[0][key] = value
with self.assertRaises(ValueError): new_sound_candidate(*v)
v = self.fixture(); v[0]['source_row'][25] = 0x200; v[0]['flags'] = 0x200
with self.assertRaisesRegex(ValueError, 'flag-free'): new_sound_candidate(*v)
def test_missing_renamed_conditional_duplicate_or_reweighted_assets_reject(self):
for mode in ('missing', 'name', 'weight', 'condition', 'duplicate', 'variation-volume'):
v = self.fixture()
if mode == 'missing': v[2].pop()
elif mode == 'name': v[3][569828] = ['sound/spells/unrelated.ogg']
elif mode == 'weight': v[2][0]['Frequency'] = 2
elif mode == 'condition': v[2][0]['PlayerConditionID'] = 99
elif mode == 'duplicate': v[2][1] = copy.deepcopy(v[2][0])
else: v[2][0]['Volume'] = .5
with self.assertRaises(ValueError, msg=mode): new_sound_candidate(*v)
if __name__ == '__main__': unittest.main()