Files
WoW-Hybrid-gateway/tests/aura_visual_profile_test.py

83 lines
6.3 KiB
Python

"""Visual references must be real unconditional target-build row IDs."""
import copy
import hashlib
import json
import sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
from aura_visual_profile import generate,header,extend_with_package,CONDITIONS
p=ROOT/'docs/evidence/data/aura-profile/visuals'
s=json.loads((p/'tortoise.json').read_text());n=json.loads((p/'forever-links.json').read_text())
expected=json.loads((p/'profile.json').read_text())
actual=generate(s,n)
assert actual['definitions']==expected['definitions'] and len(actual['definitions'])==7
assert expected['input_sha256']=={k:hashlib.sha256((p/v).read_bytes()).hexdigest() for k,v in [('source','tortoise.json'),('native','forever-links.json')]}
compiled=actual['definitions']
extension_path=p/'profile-package-links.json'
if extension_path.exists():
from spell_passive_compat import fields
extension=json.loads(extension_path.read_text());package=json.loads((ROOT/'docs/evidence/data/item-sparse-compat/package.json').read_text())
native=[r for r in package['rows']if r['table_name']=='SpellXSpellVisual'and r.get('source_spell_id')in {s['entry']for s in extension['source']}]
assert native==extension['records'] and extension['base_snapshots_modified']is False
# The existing52732extension includes a reviewed destination-only visual
# mapping. Validate its retained candidate instead of treating it as a
# same-ID link. The active records already had this mapping at706480c.
owned=extension.get('source_owned_visuals')
kwargs={}if owned is None else dict(visual_candidates={int(k):v for k,v in owned.items()},
visual_schemas={t:fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in('SpellVisual','SpellVisualEvent')})
compiled=extend_with_package(compiled,extension['source'],package,fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellXSpellVisual.dbd','SpellXSpellVisual'),**kwargs)
assert [r for r in compiled if r not in actual['definitions']]==extension['definitions']
set_path=ROOT/'docs/evidence/data/aura-profile/set-effect-visual-extension.json'
if set_path.exists():
from spell_passive_compat import fields
extension=json.loads(set_path.read_text());package=json.loads((ROOT/'docs/evidence/data/item-sparse-compat/package.json').read_text());before=compiled
ids={s['entry']for s in extension['source']}
assert [r for r in package['rows']if r['table_name']=='SpellXSpellVisual'and r.get('source_spell_id')in ids]==extension['visual_records']
graphs={int(k):v for k,v in extension['source_owned_visuals'].items()}
tables={r['table_name']for g in graphs.values()for r in g['records']}
schemas={t:fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in tables}
compiled=extend_with_package(compiled,extension['source'],package,fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellXSpellVisual.dbd','SpellXSpellVisual'),visual_candidates=graphs,visual_schemas=schemas)
assert [r for r in compiled if r not in before]==extension['visual_definitions']
ghost=ROOT/'docs/evidence/gameplay/native-death-release-20261019/ghost-profile'
extra=generate(json.loads((ghost/'source-ghost-visual.json').read_text()),json.loads((ghost/'native-ghost-visual.json').read_text()))
assert extra['definitions']==json.loads((ghost/'visual-profile.json').read_text())['definitions']
compiled=sorted(compiled+extra['definitions'],key=lambda r:r['spell'])
defensive_path=ROOT/'docs/evidence/data/aura-profile/defensive-effect-visual-extension.json'
if defensive_path.exists():
from aura_visual_profile import review_lifecycle_link
extension=json.loads(defensive_path.read_text());package=json.loads((ROOT/'docs/evidence/data/item-sparse-compat/package.json').read_text())
for candidate in extension['visual_links'].values():
reviewed=review_lifecycle_link(candidate,extension['schemas']['SpellXSpellVisual'])
assert reviewed==candidate
ids={r['entry']for r in extension['source']}
assert [r for r in package['rows']if r['table_name']=='SpellXSpellVisual'and r.get('source_spell_id')in ids]==[r for r in extension['component']['records']if r['table_name']=='SpellXSpellVisual']
before=compiled
compiled=extend_with_package(compiled,extension['source'],package,extension['schemas']['SpellXSpellVisual'])
assert [r for r in compiled if r not in before]==extension['visual_definitions']
# The same already-reviewed reflection children have exact unconditional links.
from aura_reflection_profile_support import reviewed_reflection_extension
reflection=reviewed_reflection_extension();before=compiled
compiled=extend_with_package(compiled,reflection['visual_source'],reflection['package'],reflection['schemas']['SpellXSpellVisual'])
assert [r for r in compiled if r not in before]==reflection['visual_definitions']
assert not {52975,23216}&{r['spell']for r in compiled}
_cat_dir=ROOT/'docs/evidence/data/aura-profile/catalogue-admission-20261111'
_baseline=json.loads((_cat_dir/'retained-baseline.json').read_text())
_catalogue=json.loads((_cat_dir/'catalogue.json').read_text())
assert compiled==[r for r in _baseline['visual_links']]or all(any(b['spell']==r['spell']and b['spell_x_spell_visual']==r['spell_x_spell_visual']for b in _baseline['visual_links'])for r in compiled)
from aura_definition_profile import merge_catalogue
_subset=json.loads((ROOT/'docs/evidence/data/aura-profile/subset-admission-20261126/report.json').read_text())
assert header(merge_catalogue(merge_catalogue(_baseline['visual_links'],_catalogue['visual_links'],'spell_x_spell_visual'),_subset['visual_links'],'spell_x_spell_visual'))==(ROOT/'include/gateway/aura_visual_profile.hpp').read_text()
for field in ('DifficultyID','Flags2','SpellVisualID',*CONDITIONS):
wrong=copy.deepcopy(n[:1]);wrong[0][field]+=1
assert not generate(s[:1],wrong)['definitions'],field
assert not generate(s[:1],n[:1]*2)['definitions']
assert not generate(s[:1],[])['definitions']
assert not generate([dict(s[0],spellVisual2=1)],n)['definitions']
assert not generate(s[:1],[dict(n[0],Probability=.5)])['definitions']
for src in (s+s[:1],[dict(s[0],entry=0)]):
try:generate(src,n)
except ValueError:pass
else:raise AssertionError('Invalid/duplicate spell accepted')
print(len(compiled),'genuine visual links; base snapshots retained; package extensions checked against exact active records. Rendering requires real-client test.')