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

99 lines
5.8 KiB
Python

#!/usr/bin/env python3
"""Compose real cloak proc52731 with its complete source52732 dependency."""
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_item_proc_compat as m
import spell_extra_attack_compat_test as extra
import spell_passive_compat as codec
from turtle_data import spell_layout
class ExtraAttackProcTest(unittest.TestCase):
def fixture(self):
v = extra.ExtraAttackTest().fixture(); trigger = extra.ExtraAttackTest().convert(v)
f = json.loads((ROOT / 'tests/fixtures/extra-attack-proc-source.json').read_text())
dbc = SimpleNamespace(by_id={52731: f['disk_row']}, string={int(k): v for k, v in f['strings'].items()}.__getitem__)
source = m.source_spell(dbc, f['server_row'], spell_layout(), family_namespace=f['family_namespace'], proc_proof=f['proc_namespace'])
proof = v[0][0]['extra_attack_semantics']
link = next(r for r in trigger['records'] if r['table_name'] == 'SpellXSpellVisual')
visual = v[5].pop('visual_candidates')[6624]
v[5].update(extra_attack_proof=proof, proc_proof=f['proc_namespace'],
proc_overrides=f['proc_overrides'], trigger_sources={52732: v[0][0]},
trigger_records=trigger['records'], trigger_visual_links={52732: dict(
kind='source-owned-extra-attack-visual-dependency', record=link, visual_candidate=visual)})
v[0] = [source]
v[2]['SpellAuraOptions'] = codec.fields(ROOT.parent / 'tools/WoWDBDefs/definitions/SpellAuraOptions.dbd', 'SpellAuraOptions')
v[3]['SpellAuraOptions'] = 1500000
for row in trigger['records']:
if row['table_name'] in v[3]: v[3][row['table_name']] = max(v[3][row['table_name']], row['id'])
raw = b'BLP2' + bytes(20); path = 'interface/icons/spell_lightning_lightningbolt01.blp'
v[5].update(new_icon_ids={'52731': 135990}, target_icon_names={135990: [path]},
icon_assets=[dict(path=path, bytes=len(raw), sha256=hashlib.sha256(raw).hexdigest(), magic_hex=raw[:4].hex())], read_icon=lambda path: raw)
v[5]['source_tables']['SpellIcon'] = SimpleNamespace(by_id={320: 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_real_source_flags_levels_chance_melee_mask_and_dependency(self):
v = self.fixture(); before = copy.deepcopy(v[:5]); r = self.convert(v)
self.assertEqual(v[:5], before); self.assertEqual(r['definition_policy'], m.EXTRA_ATTACK_POLICY)
self.assertEqual(len(r['records']), 7)
rows = {r['table_name']: r['record'] for r in r['records']}
self.assertEqual(rows['SpellMisc']['Attributes'], [64] + [0] * 16)
self.assertEqual((rows['SpellLevels']['SpellLevel'], rows['SpellLevels']['BaseLevel']), (60, 60))
self.assertEqual((rows['SpellAuraOptions']['ProcChance'], rows['SpellAuraOptions']['ProcTypeMask']), (1, [20, 0]))
self.assertEqual(rows['SpellEffect']['EffectTriggerSpell'], 52732)
dep = r['spells'][0]['trigger_dependencies'][0]
self.assertEqual(dep['definition_family'], 'constant-self-extra-attack')
self.assertEqual(len(dep['record_sha256']), 10)
self.assertFalse(r['installable']); self.assertFalse(r['gameplay_verified'])
def test_old_policy_remains_closed(self):
v = self.fixture(); del v[5]['extra_attack_proof']
with self.assertRaises(ValueError): self.convert(v)
v = self.fixture(); s = v[0][0]
with self.assertRaises(ValueError): m.validate_source(s, v[5]['proc_proof'])
def test_missing_visual_and_reencoded_trigger_mutations_reject(self):
for mutation in ('missing-visual', 'missing-event', 'level', 'count', 'link'):
v = self.fixture(); rows = v[5]['trigger_records']
if mutation == 'missing-visual': v[5]['trigger_visual_links'] = {}
elif mutation == 'missing-event': v[5]['trigger_records'] = [r for r in rows if r['table_name'] != 'SpellVisualEvent']
else:
table, field, value = {'level': ('SpellLevels', 'BaseLevel', 0),
'count': ('SpellEffect', 'EffectBasePointsF', 2),
'link': ('SpellXSpellVisual', 'SpellVisualID', 6624)}[mutation]
row = next(r for r in rows if r['table_name'] == table)
row['record'][field] = value; raw = codec.encode(row['record'], v[2][table])
row.update(wire_hex=raw.hex(), sha256=hashlib.sha256(raw).hexdigest())
with self.assertRaises(ValueError, msg=mutation): self.convert(v)
def test_nonmelee_or_missing_override_or_wrong_proof_rejects(self):
for mutation in ('event', 'proof', 'family', 'overrides', 'level'):
v = self.fixture()
if mutation == 'event': v[0][0]['conditions']['procFlags'] = 64
elif mutation == 'proof': v[5]['extra_attack_proof']['target_effect'] = 30
elif mutation == 'family': v[0][0]['class_family']['target_id'] = 4
elif mutation == 'overrides': v[5]['proc_overrides']['rows'] = [[52731]]
else: v[0][0]['levels']['baseLevel'] = True
with self.assertRaises(ValueError, msg=mutation): self.convert(v)
def test_stable_allocations_and_source_id_is_not_allowlist(self):
v = self.fixture(); r = self.convert(v); v[4].update(r['child_id_registry'])
self.assertEqual(self.convert(v), r)
v[0][0]['entry'] = 600152; v[5]['new_icon_ids'] = {'600152': 135990}
v[5]['proc_overrides']['source_spell_ids'].append(600152)
r = self.convert(v)
self.assertTrue(all(row['source_spell_id'] == 600152 for row in r['records']))
if __name__ == '__main__': unittest.main()