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

37 lines
2.7 KiB
Python

"""Conservative locator candidate scope: hidden bit, overrides and unknowns."""
import copy,hashlib,pathlib,sys,unittest
sys.path.insert(0,str(pathlib.Path(__file__).resolve().parents[1]/'ops'))
import spellbook_hidden_readiness as m
import spell_passive_compat as codec
ROOT=pathlib.Path(__file__).resolve().parents[1]
SCHEMA=m.builder.checked_schema(ROOT.parent/'tools/WoWDBDefs/definitions','SpellMisc')
def child(i,spell,attrs=0x80,difficulty=0):
r=copy.deepcopy(codec.NEW_MISC_NEUTRAL);r.update(ID=i,SpellID=spell,DifficultyID=difficulty,SpellIconFileDataID=134400);r['Attributes'][0]=attrs;return r
def canonical(spell,status='valid'):return dict(table_name='Spell',table_hash='0xe111669e',id=spell,record_status=status)
def overlay(rec,status='valid'):
wire=codec.encode(rec,SCHEMA)
return dict(table_name='SpellMisc',table_hash='0xc603ee28',id=rec['ID'],record_status=status,record=rec,wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest())
class HiddenCandidate(unittest.TestCase):
def test_hidden_only_not_passives_and_unknown_retained(self):
p=dict(rows=[canonical(i)for i in(1,2,3,4)])
r=m.classify(p,[child(11,1,0xc0),child(12,2,0x40),child(13,3,0)],SCHEMA)
self.assertEqual(r['hidden_ids'],[1]);self.assertEqual(r['held'],[dict(spell=4,reason='no_effective_default',child_ids=[])])
def test_effective_overlay_and_removal_precedence(self):
p=dict(rows=[canonical(1),canonical(2),canonical(3),overlay(child(11,1,0)),overlay(child(12,2,0x80)),overlay(child(13,3),status='removed')])
r=m.classify(p,[child(11,1),child(12,2,0),child(13,3)],SCHEMA)
self.assertEqual(r['hidden_ids'],[2]);self.assertEqual(r['held'][0]['spell'],3)
def test_ambiguous_default_or_visible_variant_never_excluded(self):
p=dict(rows=[canonical(1),canonical(2),canonical(3)])
native=[child(11,1),child(12,1),child(21,2),child(22,2,0,2),child(31,3,0x80,2)]
r=m.classify(p,native,SCHEMA);self.assertEqual(r['hidden_ids'],[]);self.assertEqual({x['reason']for x in r['held']},{'ambiguous_effective_default','no_effective_default'})
def test_noncanonical_and_removed_spell_rows_never_excluded(self):
r=m.classify(dict(rows=[canonical(1,'removed')]),[child(11,1),child(12,2)],SCHEMA);self.assertEqual(r['hidden_ids'],[])
def test_stale_wire_and_duplicate_identity_rejected(self):
r=overlay(child(11,1));r['sha256']='0'*64
with self.assertRaisesRegex(ValueError,'wire SHA'):m.classify(dict(rows=[canonical(1),r]),[],SCHEMA)
with self.assertRaisesRegex(ValueError,'Duplicate package'):m.classify(dict(rows=[canonical(1),canonical(1)]),[],SCHEMA)
def test_sorted_unique_header_handles_empty_set(self):
self.assertIn('COUNT 0u',m.header([],'a','b'))
with self.assertRaises(ValueError):m.header([2,1],'a','b')
if __name__=='__main__':unittest.main()