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

137 lines
8.0 KiB
Python

#!/usr/bin/env python3
import copy
import json
import math
from pathlib import Path
import sys
import unittest
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import quest_objective_locations as q
def spawn(guid, entries, x, y, *, flags=0, wander=1.5, visibility=0.25):
return {'guid':guid,'entries':entries,'map':0,'x':x,'y':y,'z':35.0,'wander':wander,
'movement_type':1,'spawn_flags':flags,'visibility_mod':visibility}
def snapshot():
return {'schema':q.SNAPSHOT,'source':{'kind':'fixture'},
'quests':[{'id':60141,'creature_or_go':[0,101,-42,0],'creature_or_go_count':[0,2,1,0], 'required_spells':[0,0,0,0],
'items':[0,51868,0,0],'item_count':[0,8,0,0]}],
'direct_loot_rows':[{'creature':101,'loot_id':501,'item':51868,'chance':-100.0,'group':0,'min_or_ref':1,'max':1,'condition':0},
{'creature':202,'loot_id':502,'item':51868,'chance':20.0,'group':1,'min_or_ref':1,'max':2,'condition':17},
{'creature':303,'loot_id':503,'item':51868,'chance':100.0,'group':0,'min_or_ref':-99,'max':1,'condition':0}],
'templates':[{'creature':101,'loot_id':501,'phase_quest_id':0},{'creature':202,'loot_id':502,'phase_quest_id':99},
{'creature':303,'loot_id':503,'phase_quest_id':0}],
'spawns':[spawn(1,[101,202,0,0],-0.1,-128.1),spawn(2,[202,0,0,0],20.0,20.0),
spawn(3,[101,0,0,0],21.0,21.0,flags=2),spawn(4,[202,0,0,0],22.0,22.0,flags=128)],
'spawn_pools':[{'guid':1,'pool':50,'chance':50.0,'flags':0}],
'template_pools':[{'creature':202,'pool':60,'chance':25.0,'flags':0}],
'events':[{'guid':2,'event':-7}]}
class LocationsTest(unittest.TestCase):
def test_objective_order_multiple_sources_and_uncertainty(self):
result=q.build(snapshot(),'f'*64)
objs=result['quests'][0]['objectives']
self.assertEqual([(o['presentation_index'],o['source_slot'],o['native_storage_index'],o['target']) for o in objs],
[(0,1,1,101),(1,2,2,-42),(2,1,5,51868)])
self.assertEqual(objs[2]['candidate_presentation_id'],(60141<<3)|2)
self.assertEqual(objs[1]['status'],'held')
self.assertIn('gameobject_objective_not_implemented',objs[1]['holds'])
item=objs[2]
self.assertEqual([x['creature'] for x in item['supported_sources']],[101,202])
self.assertIn('loot_reference_row_not_resolved',item['holds'])
self.assertIn('source_quest_phase_condition_not_evaluated',item['holds'])
self.assertEqual(item['supported_sources'][1]['phase_quest_id'],99)
self.assertIn('disabled_source_spawns_excluded',item['holds'])
self.assertIn('dead_by_default_source_spawns_excluded',item['holds'])
pts=[p for c in item['clusters'] for p in c['points']]
self.assertEqual(sorted(p['guid'] for p in pts),[1,2])
shared=next(p for p in pts if p['guid']==1)
self.assertEqual(shared['possible_creature_entries'],[101,202])
self.assertEqual(shared['spawn_template_choices'],[101,202,0,0])
self.assertEqual(shared['spawn_pools'][0]['pool'],50)
self.assertEqual(shared['template_pools'][0]['pool'],60)
self.assertEqual(shared['visibility_mod'],0.25)
self.assertEqual(next(p for p in pts if p['guid']==2)['events'][0]['event'],-7)
self.assertEqual(shared['runtime_presence'],'not_verified')
self.assertEqual(shared['phase'],'not_resolved')
self.assertEqual(next(c['cell'] for c in item['clusters'] if any(p['guid']==1 for p in c['points'])),[-1,-2])
self.assertIn('not polygons',result['point_semantics'])
self.assertEqual(q.build(snapshot(),'f'*64),result)
def test_unknown_visibility_and_no_sources(self):
s=snapshot();s['spawns'][0]['visibility_mod']=None;s['direct_loot_rows']=[]
objs=q.build(s,'abc')['quests'][0]['objectives']
item=objs[-1]
self.assertEqual(item['clusters'],[])
self.assertIn('no_qualified_static_creature_spawn',item['holds'])
self.assertIn('reference_loot_gameobject_quest_spell_or_script_sources_not_exhaustively_resolved',item['holds'])
def test_bad_data_and_ranges_fail_closed(self):
for change in ('nan','duplicate','quest_shape','negative_wander'):
s=snapshot()
if change=='nan':s['spawns'][0]['x']=math.nan
elif change=='duplicate':s['spawns'].append(copy.deepcopy(s['spawns'][0]))
elif change=='quest_shape':s['quests'][0]['items']=[1]
else:s['spawns'][0]['wander']=-1
with self.subTest(change=change),self.assertRaises(ValueError):q.build(s,'abc')
with self.assertRaises(ValueError):q._numbers([True])
with self.assertRaises(ValueError):q._numbers([1,True])
with self.assertRaises(ValueError):q.capture('not-used',[0])
def test_phase_visibility_ranges_and_missing_template_are_explicit(self):
s=snapshot();s['spawns'][0]['x']=40000.0;s['spawns'][0]['spawn_flags']=0x40
s['templates']=[t for t in s['templates'] if t['creature']!=202]
item=q.build(s,'abc')['quests'][0]['objectives'][-1]
self.assertIn('source_creature_template_not_captured',item['holds'])
self.assertIn('some_source_spawns_flagged_not_visible',item['holds'])
self.assertIn('some_source_xyz_outside_native_int16_range',item['holds'])
point=next(p for c in item['clusters'] for p in c['points'] if p['guid']==1)
self.assertFalse(point['native_int16_xyz_range'])
self.assertEqual(point['possible_creature_entries'],[101])
def test_non_atomic_template_loot_change_is_held(self):
s=snapshot();s['templates'][1]['loot_id']=999
item=q.build(s,'abc')['quests'][0]['objectives'][-1]
self.assertIn('source_creature_loot_changed_during_capture',item['holds'])
self.assertEqual([v['creature'] for v in item['supported_sources']],[101])
def test_spell_target_is_not_mislabeled_as_kill(self):
s=snapshot();s['quests'][0]['required_spells'][1]=1234
s['quests'][0]['required_spells'][0]=5678
obj=q.build(s,'abc')['quests'][0]['objectives'][0]
self.assertEqual(obj['status'],'held')
self.assertEqual(obj['required_spell'],1234)
self.assertIn('spell_target_objective_not_implemented',obj['holds'])
self.assertEqual(obj['supported_sources'],[])
self.assertEqual(obj['clusters'],[])
self.assertEqual(q.build(s,'abc')['quests'][0]['holds'],[{'source_slot':0,'required_spell':5678,'reason':'spell_without_creature_or_gameobject_target_not_implemented'}])
def test_read_only_capture_queries_and_no_shell_interpolation(self):
quest='60141\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t51868\t0\t0\t0\t8\t0\t0\t0\n'
loot='524\t524\t51868\t-100\t0\t1\t1\t0\n'
spawns='3\t524\t0\t0\t0\t0\t-9700\t-10\t40\t2\t1\t0\t0.5\n'
outputs=iter(['42\tfixture-version\tfixture-host\n',quest,loot,'524\t524\t0\n',spawns,'','',''])
def run(argv,*,input,text,capture_output,check):
self.assertEqual(argv[:4],['docker','exec','-i','db;not-shell'])
self.assertTrue(input.startswith('SELECT '))
self.assertNotIn('INSERT ',input.upper());self.assertNotIn('UPDATE ',input.upper());self.assertNotIn('DELETE ',input.upper())
self.assertTrue(text and capture_output and check)
class Result: pass
r=Result();r.stdout=next(outputs);return r
with patch.object(q.subprocess,'run',side_effect=run):
snap=q.capture('db;not-shell',[60141])
self.assertEqual(snap['spawns'][0]['visibility_mod'],0.5)
self.assertEqual(snap['direct_loot_rows'][0]['creature'],524)
self.assertEqual(len(snap['source']['queries_sha256']),8)
self.assertEqual(snap['source']['server_id'],'42')
result=q.build(snap,'abc')
self.assertEqual(result['quests'][0]['objectives'][0]['native_storage_index'],4)
self.assertEqual(result['quests'][0]['objectives'][0]['clusters'][0]['points'][0]['guid'],3)
if __name__=='__main__':unittest.main()