883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
117 lines
6.5 KiB
Python
117 lines
6.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Genuine source52732; data loading is distinct from server execution."""
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
from types import SimpleNamespace
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path[:0] = [str(ROOT / 'ops'), str(ROOT / 'tests')]
|
|
import spell_extra_attack_compat as m
|
|
import spell_passive_compat as codec
|
|
import spell_restore_compat_test as restore
|
|
from spell_visual_compat import new_visual_candidate
|
|
import spell_visual_compat_test as visual_tests
|
|
from turtle_data import spell_layout
|
|
|
|
|
|
class ExtraAttackTest(unittest.TestCase):
|
|
def source(self):
|
|
f = json.loads((ROOT / 'tests/fixtures/extra-attack-source.json').read_text())
|
|
dbc = SimpleNamespace(by_id={52732: f['disk_row']},
|
|
string={int(k): v for k, v in f['strings'].items()}.__getitem__)
|
|
src = m.source_spell(dbc, f['server_row'], spell_layout(),
|
|
family_namespace=f['family_namespace'], semantics=f['semantics'])
|
|
return f, dbc, src
|
|
|
|
def fixture(self):
|
|
f, dbc, src = self.source(); v = list(restore.RestorationCompatibilityTest().new_fixture())
|
|
v[0] = [src]
|
|
visual = new_visual_candidate(*visual_tests.VisualConversionTest().fixture())
|
|
for t in ('SpellVisual', 'SpellVisualEvent', 'SpellXSpellVisual'):
|
|
v[1].setdefault(t, [])
|
|
v[2][t] = codec.fields(ROOT.parent / 'tools/WoWDBDefs/definitions' / (t + '.dbd'), t)
|
|
v[3][t] = 1500000
|
|
raw = b'BLP2' + bytes(20); path = 'interface/icons/inv_jewelry_talisman_01.blp'
|
|
v[5].update(new_icon_ids={'52732': 133434}, target_icon_names={133434: [path]},
|
|
icon_assets=[dict(path=path, bytes=len(raw), sha256=hashlib.sha256(raw).hexdigest(), magic_hex=raw[:4].hex())],
|
|
read_icon=lambda path: raw, visual_candidates={6624: visual})
|
|
v[5]['source_tables']['SpellIcon'] = SimpleNamespace(by_id={315: f['source_icon_row']}, string=lambda n: f['source_icon_string'])
|
|
return v
|
|
|
|
def convert(self, v): return m.new_component(*v[:5], **v[5])
|
|
|
|
def test_genuine_source_level_effect_count_and_separate_visual(self):
|
|
v = self.fixture(); before = copy.deepcopy(v[:5]); result = self.convert(v)
|
|
self.assertEqual(v[:5], before); self.assertEqual(len(result['records']), 10)
|
|
rows = {r['table_name']: r['record'] for r in result['records']}
|
|
self.assertEqual((rows['SpellEffect']['Effect'], rows['SpellEffect']['EffectAura'],
|
|
rows['SpellEffect']['EffectBasePointsF']), (19, 0, 1))
|
|
self.assertEqual(rows['SpellEffect']['ImplicitTarget'], [1, 0])
|
|
self.assertEqual((rows['SpellLevels']['SpellLevel'], rows['SpellLevels']['BaseLevel']), (60, 60))
|
|
self.assertEqual(rows['SpellXSpellVisual']['SpellID'], 52732)
|
|
self.assertEqual(rows['SpellXSpellVisual']['SpellVisualID'], 194634)
|
|
self.assertEqual(rows['SpellMisc']['DurationIndex'], 0)
|
|
self.assertFalse(result['installable']); self.assertFalse(result['gameplay_verified'])
|
|
self.assertFalse(result['spells'][0]['known_spells_modified'])
|
|
self.assertNotIn('SkillLineAbility', rows)
|
|
for row in result['records']:
|
|
self.assertEqual(bytes.fromhex(row['wire_hex']), codec.encode(row['record'], v[2][row['table_name']]))
|
|
|
|
def test_registry_reuse_and_shared_visual_deduplication(self):
|
|
v = self.fixture(); r = self.convert(v); v[4].update(r['child_id_registry'])
|
|
self.assertEqual(self.convert(v), r)
|
|
second = copy.deepcopy(v[0][0]); second['entry'] = 600151; v[0].append(second)
|
|
v[5]['new_icon_ids']['600151'] = 133434
|
|
r = self.convert(v)
|
|
self.assertEqual(len(r['records']), 17)
|
|
self.assertEqual(sum(r['table_name'] == 'SpellVisual' for r in r['records']), 1)
|
|
self.assertEqual({r['record']['SpellID'] for r in r['records'] if r['table_name'] == 'SpellXSpellVisual'}, {52732, 600151})
|
|
|
|
def test_source_and_capture_mismatch_rejected(self):
|
|
for mutation in ('level', 'visual', 'count', 'attribute'):
|
|
f, dbc, src = self.source()
|
|
key, value = {'level': ('baseLevel', 0), 'visual': ('spellVisual1', 0),
|
|
'count': ('effectBasePoints1', 1), 'attribute': ('attributes', 64)}[mutation]
|
|
f['server_row'][key] = value
|
|
with self.assertRaises(ValueError, msg=mutation):
|
|
m.source_spell(dbc, f['server_row'], spell_layout(), family_namespace=f['family_namespace'], semantics=f['semantics'])
|
|
|
|
def test_missing_or_tampered_visual_dependency_rejects(self):
|
|
for mutation in ('missing', 'bytes', 'source', 'registry', 'role', 'installed'):
|
|
v = self.fixture(); c = v[5]['visual_candidates'][6624]
|
|
if mutation == 'missing': v[5]['visual_candidates'] = {}
|
|
elif mutation == 'bytes': c['records'][0]['wire_hex'] = '00'
|
|
elif mutation == 'source': c['source_visual_row'][2] = 999
|
|
elif mutation == 'registry': c['child_id_registry']['SpellVisual']['6624'] = 194635
|
|
elif mutation == 'role': c['records'][1]['record']['TargetType'] = 2
|
|
else: c['installed'] = True
|
|
with self.assertRaises(ValueError, msg=mutation): self.convert(v)
|
|
|
|
def test_unreviewed_effect_conditions_and_namespace_reject(self):
|
|
for mutation in ('target', 'variance', 'count', 'proc', 'cost', 'secondary', 'level', 'bool', 'proof'):
|
|
v = self.fixture(); s = v[0][0]
|
|
if mutation == 'target': s['effects'][0][8] = 6
|
|
elif mutation == 'variance': s['effects'][0][4] = 2
|
|
elif mutation == 'count': s['effects'][0][2] = 5
|
|
elif mutation == 'proc': s['conditions']['procFlags'] = 16
|
|
elif mutation == 'cost': s['power'][1] = 1
|
|
elif mutation == 'secondary': s['visuals'][1] = 718
|
|
elif mutation == 'level': s['levels']['baseLevel'] = 65536
|
|
elif mutation == 'bool': s['effects'][0][2] = True
|
|
else: s['extra_attack_semantics']['target_effect'] = 30
|
|
with self.assertRaises(ValueError, msg=mutation): self.convert(v)
|
|
|
|
def test_positive_native_context_and_link_collision_reject(self):
|
|
for table in m.REQUIRED_REFERENCE_TABLES:
|
|
v = self.fixture(); v[1][table].append(dict(ID=52732, SpellID=52732))
|
|
with self.assertRaises(ValueError, msg=table): self.convert(v)
|
|
v = self.fixture(); v[1]['SpellXSpellVisual'].append(dict(ID=1500001, SpellID=99))
|
|
with self.assertRaisesRegex(ValueError, 'collision'): self.convert(v)
|
|
|
|
|
|
if __name__ == '__main__': unittest.main()
|