883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
50 lines
3.9 KiB
Python
50 lines
3.9 KiB
Python
"""Same-ID scalar overlay, package precedence and fail-closed arithmetic boundaries."""
|
|
import copy,hashlib,json,sys,unittest
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import aura_definition_profile as m
|
|
from spell_passive_compat import fields,encode,SUPPLEMENTAL_TABLES
|
|
F=json.loads((ROOT/'tests/fixtures/attack-power-scalar.json').read_text())
|
|
DBD=ROOT.parent/'tools/WoWDBDefs/definitions'
|
|
SCHEMA=fields(DBD/'SpellEffect.dbd','SpellEffect');LEVELS=fields(DBD/'SpellLevels.dbd','SpellLevels')
|
|
PROOF=dict(policy=m.SCALAR_POLICY,header_sha256=m.SCALAR_HEADER_PINS)
|
|
class Tests(unittest.TestCase):
|
|
def run_batch(self,f=None,published=()):
|
|
f=copy.deepcopy(f or F)
|
|
return m.attack_power_scalar_rows([f['source']],[f['effect']],[f['levels']],published,SCHEMA,PROOF,LEVELS)
|
|
def test_scalar_and_all_levels(self):
|
|
out=self.run_batch();row=out['rows'][0];new=row['record'];old=F['effect'];src=F['source']
|
|
self.assertEqual({k for k in old if old[k]!=new[k]},{'EffectBasePointsF','EffectRealPointsPerLevel'})
|
|
self.assertEqual((new['EffectBasePointsF'],new['EffectRealPointsPerLevel']),(185,1))
|
|
for level in range(1,256):
|
|
delta=max(0,min(level,src['maxLevel'])-src['spellLevel'])
|
|
self.assertEqual(src['effectBasePoints1']+int(delta*src['effectRealPointsPerLevel1'])+src['effectBaseDice1'],new['EffectBasePointsF']+delta*new['EffectRealPointsPerLevel'])
|
|
self.assertFalse(out['installed']);self.assertFalse(out['engine_accepted'])
|
|
self.assertEqual(out,self.run_batch())
|
|
def test_preserves_published_non_scalar_fields(self):
|
|
f=copy.deepcopy(F);e=f['effect'];e['EffectRadiusIndex']=[123,0];raw=encode(e,SCHEMA)
|
|
p=dict(table_name='SpellEffect',table_hash='0xf04238a5',id=e['ID'],record=e,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
|
|
out=self.run_batch(published=[p]);self.assertEqual(out['rows'][0]['record']['EffectRadiusIndex'],[123,0])
|
|
p['wire_hex']='00'
|
|
with self.assertRaises(ValueError):self.run_batch(published=[p])
|
|
def test_levels_overlay_checked(self):
|
|
l=copy.deepcopy(F['levels']);l['MaxLevel']+=1;raw=encode(l,LEVELS)
|
|
p=dict(table_name='SpellLevels',table_hash=hex(SUPPLEMENTAL_TABLES['SpellLevels'][0]),id=l['ID'],record=l,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
|
|
self.assertFalse(self.run_batch(published=[p])['rows'])
|
|
p['sha256']='0'*64
|
|
with self.assertRaises(ValueError):self.run_batch(published=[p])
|
|
def test_unreviewed_mechanics_blocked(self):
|
|
cases=[('source','effectRealPointsPerLevel1',.5),('source','effect2',6),('source','script_name','custom'),('source','attributes',0x80000),('source','effectDieSides1',4),('source','effectDicePerLevel1',1),('source','effectTriggerSpell1',123),('levels','MaxLevel',99),('effect','EffectAura',29),('effect','Coefficient',1),('effect','GroupSizeBasePointsCoefficient',2),('effect','PvpMultiplier',2),('effect','Node__Field_12_0_0_63534_001',1)]
|
|
for section,key,value in cases:
|
|
with self.subTest(key=key):
|
|
f=copy.deepcopy(F);f[section][key]=value;out=self.run_batch(f);self.assertFalse(out['rows']);self.assertEqual(len(out['blocked']),1)
|
|
def test_bad_numbers_and_identity(self):
|
|
for section,key,value in [('source','entry',True),('source','maxLevel',256),('source','effectBaseDice1',True),('source','effectRealPointsPerLevel1',float('nan')),('effect','ID',0)]:
|
|
with self.subTest(key=key):
|
|
f=copy.deepcopy(F);f[section][key]=value
|
|
with self.assertRaises(ValueError):self.run_batch(f)
|
|
def test_proof_schema_and_duplicate_rejected(self):
|
|
for source,effects,levels,schema,proof in [([F['source']]*2,[F['effect']],[F['levels']],SCHEMA,PROOF),([F['source']],[F['effect']]*2,[F['levels']],SCHEMA,PROOF),([F['source']],[F['effect']],[F['levels']],SCHEMA[:-1],PROOF),([F['source']],[F['effect']],[F['levels']],SCHEMA,{})]:
|
|
with self.assertRaises(ValueError):m.attack_power_scalar_rows(source,effects,levels,[],schema,proof,LEVELS)
|
|
if __name__=='__main__':unittest.main()
|