883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
85 lines
7.0 KiB
Python
85 lines
7.0 KiB
Python
"""Real source/native Hand of Justice conflict; no item-specific converter rules."""
|
|
import copy,json,sys,unittest,hashlib
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops')]
|
|
import spell_item_proc_compat as m,spell_passive_compat as codec,content_package_stage as stage
|
|
from item_sparse_compat import package_payloads
|
|
|
|
class ExistingExtraAttackProcTest(unittest.TestCase):
|
|
def fixture(self):
|
|
inputs=json.loads((ROOT/'tests/fixtures/existing-extra-attack-proc-source.json').read_text())['inputs']
|
|
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('Spell','SpellName','SpellMisc','SpellEffect','SpellLevels','SpellAuraOptions')}
|
|
return inputs,schemas
|
|
def component(self,v):return m.existing_extra_attack_component(**v[0],schemas=v[1])
|
|
def test_genuine_chance_duration_level_and_source_empty_slot_are_corrected(self):
|
|
v=self.fixture();before=copy.deepcopy(v);r=self.component(v);self.assertEqual(v,before);self.assertEqual(len(r['records']),8)
|
|
aura=next(r['record']for r in r['records']if r['table_name']=='SpellAuraOptions')
|
|
self.assertEqual((aura['ProcChance'],aura['ProcCategoryRecovery'],aura['ProcTypeMask']),(2,0,[20,0]))
|
|
extra=next(r['record']for r in r['records']if r['table_name']=='SpellEffect'and r['record']['EffectIndex']==1)
|
|
self.assertEqual((extra['Effect'],extra['EffectAura'],extra['EffectTriggerSpell'],extra['EffectBasePointsF'],extra['ImplicitTarget']),(0,0,0,0,[0,0]))
|
|
self.assertEqual(next(r['record']['DurationIndex']for r in r['records']if r['table_name']=='SpellMisc'),21)
|
|
self.assertEqual(next(r['record']['Description_lang']for r in r['records']if r['table_name']=='Spell'and r['id']==15600),'2% chance on melee hit to gain 1 extra attack.')
|
|
self.assertTrue(all(r.get('record_status','valid')=='valid'for r in r['records']))
|
|
self.assertFalse(r['engine_accepted']);self.assertFalse(r['gameplay_verified'])
|
|
self.assertEqual(r['spells'][0]['source_empty_indices_represented_as_native_none'],[1])
|
|
for row in r['records']:self.assertEqual(bytes.fromhex(row['wire_hex']),codec.encode(row['record'],v[1][row['table_name']]))
|
|
def test_reapplying_to_effective_native_context_is_a_noop(self):
|
|
v=self.fixture();result=self.component(v)
|
|
for row in result['records']:
|
|
table=v[0]['native'][row['table_name']]
|
|
for index,old in enumerate(table):
|
|
if old['ID']==row['id']:table[index]=copy.deepcopy(row['record']);break
|
|
else:self.fail('Existing correction allocated a new record')
|
|
rebuilt=self.component(v)
|
|
self.assertEqual(rebuilt['records'],[])
|
|
self.assertEqual(rebuilt['spells'][0]['source_empty_indices_represented_as_native_none'],[1])
|
|
|
|
def test_default_new_parent_policy_does_not_admit_unreviewed_coefficients(self):
|
|
v=self.fixture();p=next(s for s in v[0]['sources']if s['entry']==15600)
|
|
with self.assertRaises(ValueError):m.validate_source(p,v[0]['proc_proof'],extra_attack_proof=v[0]['extra_attack_proof'])
|
|
def test_trigger_closure_override_and_unknown_native_conditions_reject(self):
|
|
for mutation in('missing-trigger','override','native-icon','radius','scaling','dummy-trigger','dummy-aura','source-duration','proc-mask','proc-ppm','visual'):
|
|
v=self.fixture();i=v[0];n=i['native'];s=next(s for s in i['sources']if s['entry']==15600)
|
|
if mutation=='missing-trigger':i['sources'][:]=[s]
|
|
elif mutation=='override':i['proc_overrides']=[dict(entry=15600,procEx=1)]
|
|
elif mutation=='native-icon':next(r for r in n['SpellMisc']if r['SpellID']==15600)['SpellIconFileDataID']=0
|
|
elif mutation=='radius':next(r for r in n['SpellEffect']if r['SpellID']==15600)['EffectRadiusIndex'][0]=1
|
|
elif mutation=='scaling':next(r for r in n['SpellEffect']if r['SpellID']==15600)['ScalingClass']=1
|
|
elif mutation=='dummy-trigger':next(r for r in n['SpellEffect']if r['ID']==1325832)['EffectTriggerSpell']=99999
|
|
elif mutation=='dummy-aura':next(r for r in n['SpellEffect']if r['ID']==1325832)['EffectAura']=13
|
|
elif mutation=='source-duration':i['duration_reference']['duration_ms']=0
|
|
elif mutation=='proc-mask':n['SpellAuraOptions'][0]['ProcTypeMask'][0]|=256
|
|
elif mutation=='proc-ppm':n['SpellAuraOptions'][0]['SpellProcsPerMinuteID']=12
|
|
else:next(r for r in n['SpellXSpellVisual']if r['SpellID']==15601)['SpellVisualID']=999
|
|
with self.assertRaises(ValueError,msg=mutation):self.component(v)
|
|
def stage_args(self):
|
|
v=self.fixture();r=self.component(v);raw=b'Preserved item\0';row=dict(table_name='SpellName',table_hash=hex(codec.TABLES['SpellName'][0]),id=9911,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
|
|
package=dict(build=codec.BUILD,schema=codec.SCHEMA,id_remapping=False,rows=[row],push_id=package_payloads([row])[0]);return package,r,v[1]
|
|
def test_common_stager_regenerates_semantics_preserves_rows_and_deduplicates(self):
|
|
a=self.stage_args();r=stage.compose_existing_proc_corrections(*a);self.assertEqual(r['added_count'],8);self.assertEqual(r['rows'][:1],a[0]['rows'])
|
|
a[0].update(rows=r['rows'],push_id=r['push_id']);self.assertEqual(stage.compose_existing_proc_corrections(*a)['added_count'],0)
|
|
def test_common_stager_rejects_tampering_and_unrelated_published_changes(self):
|
|
for change in('amount','baseline','status','drop'):
|
|
a=self.stage_args();r=a[1]['records'][0]
|
|
if change=='amount':r['record']['EffectBonusCoefficient']=2
|
|
elif change=='baseline':r['baseline_record']['SpellID']=123
|
|
elif change=='status':r['record_status']='removed'
|
|
else:a[1]['records'].pop()
|
|
with self.assertRaises(ValueError,msg=change):stage.compose_existing_proc_corrections(*a)
|
|
a=self.stage_args();r=copy.deepcopy(a[1]['records'][0]);r['record']['EffectBonusCoefficient']=2;wire=codec.encode(r['record'],a[2]['SpellEffect']);r.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest());a[0]['rows'].append(r);a[0]['push_id']=package_payloads(a[0]['rows'])[0]
|
|
with self.assertRaisesRegex(ValueError,'collision'):stage.compose_existing_proc_corrections(*a)
|
|
def test_source_ids_can_change_without_item_or_spell_allowlists(self):
|
|
v=self.fixture();mapping={15600:600130,15601:600131}
|
|
for s in v[0]['sources']:
|
|
s['entry']=mapping[s['entry']]
|
|
for e in s['effects']:
|
|
if e[10]in mapping:e[10]=mapping[e[10]]
|
|
for table,rows in v[0]['native'].items():
|
|
for r in rows:
|
|
if table in('Spell','SpellName')and r['ID']in mapping:r['ID']=mapping[r['ID']]
|
|
elif r.get('SpellID')in mapping:r['SpellID']=mapping[r['SpellID']]
|
|
if r.get('EffectTriggerSpell')in mapping:r['EffectTriggerSpell']=mapping[r['EffectTriggerSpell']]
|
|
r=self.component(v);self.assertEqual({r['source_spell_id']for r in r['records']},{600130,600131})
|
|
|
|
if __name__=='__main__':unittest.main()
|