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

90 lines
6.7 KiB
Python

import copy,json,unittest,uuid
from types import SimpleNamespace
from prepare_disarm_aura_profile import prepare
from pathlib import Path
import aura_disarm_profile as disarm
import aura_definition_profile as original
ROOT=Path(__file__).resolve().parents[1]
DATA=ROOT/'docs/evidence/data/aura-profile/disarm-family-20261022'
class DisarmProfile(unittest.TestCase):
def setUp(self):
self.source=json.loads((DATA/'source.json').read_text());self.native=json.loads((DATA/'native-effective-projection.json').read_text());self.proof=json.loads((DATA/'namespace.json').read_text())['enum_proof'];self.parents={r['ID'] for r in json.loads((DATA/'native-parent-proof.json').read_text())};self.base=json.loads((DATA/'retained-baseline.json').read_text())
def review(self):return disarm.generate(self.source,self.native,enum_proof=self.proof,native_parent_ids=self.parents)
def native676(self):return next(r for r in self.native if r['SpellID']==676 and r['DifficultyID']==0 and r['EffectIndex']==0)
def source676(self):return next(r for r in self.source if r['entry']==676)
def test_whole23_family_and_all1537_masks_preserved(self):
candidate,review,merge=disarm.compose(self.base,self.source,self.native,enum_proof=self.proof,native_parent_ids=self.parents)
self.assertEqual(review['counts'],{'source_rows':23,'family_candidates':23,'supported':15,'held':8})
expected=[676,5259,6608,6713,8379,10851,11879,13534,14180,15752,22691,23365,25057,25655,27581]
self.assertEqual(merge['added'],expected);self.assertFalse(merge['conflicts']);self.assertEqual(merge['retained'],1537)
before={r['spell']:r['active_flags'] for r in self.base['definitions']};after={r['spell']:r['active_flags'] for r in candidate['definitions']}
self.assertEqual(len(after),1552);self.assertEqual({s:after[s] for s in before},before)
self.assertEqual(after[676],1);self.assertEqual(after[6713],1)
self.assertEqual({r['spell'] for r in review['excluded']},{5376,9794,14251,19718,22419,24743,24832,54017})
self.assertEqual(len(original.header(candidate['definitions']).split('inline constexpr Definition Rows[]=')),2)
def test_native_only_effect_excluded(self):
row=dict(self.native676(),ID=max(r['ID'] for r in self.native)+1,EffectIndex=1,EffectAura=99);self.native.append(row)
result=next(r for r in self.review()['definitions'] if r['spell']==676)
self.assertEqual(result['active_flags'],1);self.assertEqual(result['excluded_native_only_indices'],[1])
def test_actual_source_slot_not_assumed_zero(self):
source=self.source676();source['effect1']=source['effectApplyAuraName1']=0;source['effect3']=6;source['effectApplyAuraName3']=67;self.native676()['EffectIndex']=2
result=next(r for r in self.review()['definitions'] if r['spell']==676)
self.assertEqual(result['source_effect_indices'],[2]);self.assertEqual(result['active_flags'],4)
def test_native_mismatch_is_held(self):
self.native676()['EffectAura']=68
self.assertIn({'spell':676,'reason':'named source/native aura kind mismatch'},self.review()['excluded'])
def test_duplicate_native_effect_index_is_held(self):
self.native.append(dict(self.native676(),ID=max(r['ID'] for r in self.native)+1))
self.assertIn({'spell':676,'reason':'same-ID native effect index missing or ambiguous'},self.review()['excluded'])
def test_nondefault_difficulty_not_substituted(self):
self.native676()['DifficultyID']=1
self.assertIn({'spell':676,'reason':'same-ID native effect index missing or ambiguous'},self.review()['excluded'])
def test_missing_parent_held(self):
self.parents.remove(676)
self.assertIn({'spell':676,'reason':'same-ID native Spell/SpellName parent missing'},self.review()['excluded'])
def test_mixed_aura_and_non_aura_execution_held(self):
held={r['spell']:r['reason'] for r in self.review()['excluded']}
self.assertEqual(held[5376],'source mixes an unreviewed aura family');self.assertEqual(held[14251],'source has non-aura execution dependency')
def test_inactive_source_aura_ambiguous(self):
self.source676()['effectApplyAuraName2']=67
self.assertIn({'spell':676,'reason':'inactive source effect carries ambiguous aura kind'},self.review()['excluded'])
def test_duplicate_source_and_native_IDs_rejected(self):
self.source.append(copy.deepcopy(self.source[0]))
with self.assertRaises(ValueError):self.review()
self.source.pop();self.native.append(copy.deepcopy(self.native[0]))
with self.assertRaises(ValueError):self.review()
def test_boolean_fields_and_invalid_indices_rejected(self):
self.source676()['effect1']=True
with self.assertRaises(ValueError):self.review()
self.source676()['effect1']=6;self.native676()['EffectIndex']=32
with self.assertRaises(ValueError):self.review()
def test_exact_named_literal_not_arithmetic_or_duplicate(self):
line=' SPELL_AURA_MOD_DISARM = 67, // named witness\n'
self.assertEqual(disarm.namespace(line,line),self.proof)
for invalid in [line.replace('67,','67 + 1,'),line+line,line.replace('67,','68,'),line.replace('67,','0x43,')]:
with self.assertRaises(ValueError):disarm.namespace(invalid,line)
def test_namespace_or_parent_type_tampering_rejected(self):
self.proof['target']['SPELL_AURA_MOD_DISARM']=68
with self.assertRaises(ValueError):self.review()
self.proof['target']['SPELL_AURA_MOD_DISARM']=67;self.parents.add(True)
with self.assertRaises(ValueError):self.review()
def test_conflicting_retained_mask_never_overwritten(self):
self.base['definitions'].append({'spell':676,'active_flags':2})
candidate,review,merge=disarm.compose(self.base,self.source,self.native,enum_proof=self.proof,native_parent_ids=self.parents)
self.assertEqual(next(r['active_flags'] for r in candidate['definitions'] if r['spell']==676),2)
self.assertEqual(merge['conflicts'],[{'spell':676,'retained_mask':2,'proposed_mask':1}]);self.assertNotIn(676,merge['added'])
def test_duplicate_retained_masks_rejected(self):
self.base['definitions'].append(copy.deepcopy(self.base['definitions'][0]))
with self.assertRaises(ValueError):disarm.compose(self.base,self.source,self.native,enum_proof=self.proof,native_parent_ids=self.parents)
def test_source_and_native_order_do_not_change_candidate(self):
expected=self.review();self.source.reverse();self.native.reverse();self.assertEqual(self.review(),expected)
def test_preparer_refuses_canonical_output_before_writes(self):
with self.assertRaises(ValueError):prepare(SimpleNamespace(output=ROOT/'include/gateway'))
def test_preparer_wrong_input_pin_refuses_without_output(self):
output=ROOT/'runtime'/('disarm-refused-'+uuid.uuid4().hex)
args=SimpleNamespace(output=output,baseline=DATA/'retained-baseline.json',package=DATA/'source.json',expected_baseline_sha256='0'*64,expected_package_sha256='0'*64)
with self.assertRaises(ValueError):prepare(args)
self.assertFalse(output.exists())
if __name__=='__main__':unittest.main()