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

89 lines
7.6 KiB
Python

import copy,json,re,sys,unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
import aura_source_family_profile as family
import aura_definition_profile as base
FIX=ROOT/'docs/evidence/data/aura-profile/source-family-admission-20261021'
def read(name):return json.loads((FIX/name).read_text())
class SourceAuraFamily(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.source=read('source.json');cls.native=read('native-effective-projection.json');ns=read('namespace.json');cls.proof=family.namespace('\n'.join(ns['source']['lines']),'\n'.join(ns['target']['lines']));cls.parents={x['ID'] for x in read('native-parent-proof.json')}
def generate(self,source=None,native=None,proof=None,parents=None):return family.generate(self.source if source is None else source,self.native if native is None else native,enum_proof=self.proof if proof is None else proof,native_parent_ids=self.parents if parents is None else parents)
def owned(self,sid):return [copy.deepcopy(x) for x in self.source if x['entry']==sid],[copy.deepcopy(x) for x in self.native if x['SpellID']==sid]
def test_reproduces_entire198candidate_catalogue(self):
actual=self.generate();self.assertEqual(actual,read('review.json'));self.assertEqual(actual['counts'],{'source_rows':198,'family_candidates':198,'supported':86,'held':112})
def test_actual_holyshield_and_righteous_source_masks_exclude_native_only(self):
rows={x['spell']:x for x in self.generate()['definitions']};self.assertEqual(rows[20928]['active_flags'],3);self.assertEqual(rows[20928]['excluded_native_only_indices'],[2]);self.assertEqual(rows[25780]['active_flags'],1);self.assertEqual(rows[25780]['excluded_native_only_indices'],[1,2,3])
def test_all_supported_siblings_append_without_changing1451(self):
before=read('retained-baseline.json');after,merge=family.extend(before,self.generate());self.assertEqual(len(after['definitions']),1537);self.assertEqual(merge['conflicts'],[]);old={x['spell']:x['active_flags'] for x in before['definitions']};new={x['spell']:x['active_flags'] for x in after['definitions']};self.assertTrue(all(new[k]==v for k,v in old.items()));self.assertEqual(len(merge['added']),86)
def test_namespace_mapping_is_named_and_not_numeric_identity(self):
source,native=self.owned(25780);proof=copy.deepcopy(self.proof);proof['target']['SPELL_AURA_MOD_THREAT']=210
for row in native:
if row['EffectIndex']==0:row['EffectAura']=210
self.assertEqual(self.generate(source,native,proof)['definitions'][0]['active_flags'],1)
native[0]['EffectAura']=10;self.assertEqual(self.generate(source,native,proof)['definitions'],[])
def test_native_only_effect_is_never_admitted(self):
source,native=self.owned(20928);extra=next(x for x in native if x['EffectIndex']==2);extra['EffectAura']=self.proof['target']['SPELL_AURA_MOD_THREAT'];self.assertEqual(self.generate(source,native)['definitions'][0]['active_flags'],3)
def test_native_duplicate_index_ambiguity_held(self):
source,native=self.owned(20928);row=copy.deepcopy(native[0]);row['ID']=2147483000;native.append(row);r=self.generate(source,native);self.assertEqual(r['definitions'],[]);self.assertIn('ambiguous',r['excluded'][0]['reason'])
def test_missing_native_parent_held(self):
source,native=self.owned(20928);r=self.generate(source,native,parents=set());self.assertEqual(r['definitions'],[]);self.assertIn('parent missing',r['excluded'][0]['reason'])
def test_nondefault_difficulty_cannot_fill_missing_source_index(self):
source,native=self.owned(20928)
for row in native:
if row['EffectIndex']==1:row['DifficultyID']=1
self.assertEqual(self.generate(source,native)['definitions'],[])
def test_unreviewed_or_instant_source_dependencies_held(self):
source,native=self.owned(20928);source[0]['effectApplyAuraName2']=4;self.assertIn('unreviewed',self.generate(source,native)['excluded'][0]['reason']);source[0]['effect2']=64;self.assertIn('non-aura',self.generate(source,native)['excluded'][0]['reason'])
def test_wrong_named_aura_does_not_pass_shape_only(self):
source,native=self.owned(20928)
for row in native:
if row['EffectIndex']==1:row['EffectAura']=51
self.assertEqual(self.generate(source,native)['definitions'],[])
def test_namespace_missing_or_duplicate_meaning_rejected(self):
proof=copy.deepcopy(self.proof);proof['source']['SPELL_AURA_MOD_THREAT']=43
with self.assertRaises(ValueError):self.generate(proof=proof)
with self.assertRaises(ValueError):family.enum_witness('SPELL_AURA_MOD_THREAT=10,')
def test_enum_initializer_requires_whole_decimal_literal(self):
text='\n'.join(read('namespace.json')['source']['lines'])
self.assertEqual(family.enum_witness(text),self.proof['source'])
for suffix in [' + 1',' << 1',' | 1','u',' /* + 1 */']:
changed=re.sub(r'(SPELL_AURA_MOD_THREAT\s*=\s*10)(\s*,)',lambda m:m.group(1)+suffix+m.group(2),text)
self.assertNotEqual(changed,text)
with self.subTest(suffix=suffix),self.assertRaises(ValueError):family.enum_witness(changed)
commented=re.sub(r'(?m)^(\s*)(SPELL_AURA_MOD_THREAT)',r'\1// \2',text)
with self.assertRaises(ValueError):family.enum_witness(commented)
def test_removed_or_invalid_effect_and_parent_overlays_rejected(self):
for table in ['SpellEffect','Spell','SpellName']:
for status in ['removed','invalid',None,0,True]:
row={'table_name':table,'id':123,'record':{'ID':123},'record_status':status}
with self.subTest(table=table,status=status),self.assertRaises(ValueError):family.effective_table([{'ID':123}],[row],table)
def test_valid_overlay_identity_and_default_status(self):
original=[{'ID':123,'value':1}];row={'table_name':'SpellEffect','id':123,'record':{'ID':123,'value':2}}
self.assertEqual(family.effective_table(original,[row],'SpellEffect'),[{'ID':123,'value':2}]);self.assertEqual(original,[{'ID':123,'value':1}])
row['record_status']='valid';self.assertEqual(family.effective_table(original,[row],'SpellEffect')[0]['value'],2)
row['record']['ID']=124
with self.assertRaises(ValueError):family.effective_table(original,[row],'SpellEffect')
def test_duplicate_overlay_identity_rejected_even_when_identical(self):
for table in ['SpellEffect','Spell','SpellName']:
row={'table_name':table,'id':123,'record':{'ID':123,'value':2}}
self.assertEqual(family.effective_table([{'ID':123,'value':1}],[row],table)[0]['value'],2)
for value in [2,3]:
duplicate=copy.deepcopy(row);duplicate['record']['value']=value
with self.subTest(table=table,value=value),self.assertRaises(ValueError):family.effective_table([{'ID':123}],[row,duplicate],table)
def test_existing_conflicting_mask_is_retained_and_reported(self):
r=self.generate();p={'definitions':[{'spell':20928,'active_flags':1}]};after,merge=family.extend(p,r);self.assertEqual(next(x for x in after['definitions'] if x['spell']==20928)['active_flags'],1);self.assertEqual(merge['conflicts'],[{'spell':20928,'retained_mask':1,'proposed_mask':3}])
def test_tampered_mask_or_parent_report_rejected(self):
r=self.generate();r['definitions'][0]['active_flags']=255
with self.assertRaises(ValueError):family.extend({'definitions':[]},r)
r=self.generate();r['native_parent_ids']=[]
with self.assertRaises(ValueError):family.extend({'definitions':[]},r)
def test_duplicate_source_and_native_row_identity_rejected(self):
source,native=self.owned(20928)
with self.assertRaises(ValueError):self.generate(source+source,native)
with self.assertRaises(ValueError):self.generate(source,native+[native[0]])
def test_generation_does_not_mutate_native_or_source(self):
source,native=self.owned(20928);before=copy.deepcopy((source,native));self.generate(source,native);self.assertEqual((source,native),before)
if __name__=='__main__':unittest.main()