883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
78 lines
6.7 KiB
Python
78 lines
6.7 KiB
Python
#!/usr/bin/env python3
|
|
import copy,hashlib,json,struct,sys,tempfile,unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import quest_poi_lookup as p
|
|
from map_row_compat import encode,WORLD_MAP_TABLES
|
|
|
|
def fl(x):return struct.unpack('<I',struct.pack('<f',x))[0]
|
|
def assignment(ident=1,uimap=100,region=None):
|
|
return {'ID':ident,'UiMin':[0.,0.],'UiMax':[1.,1.],'Region':region or [0.,0.,-100.,10.,10.,100.],
|
|
'UiMapID':uimap,'OrderIndex':0,'MapID':0,'AreaID':12,'WmoDoodadPlacementID':0,'WmoGroupID':0,'Unknown1125':0}
|
|
def fixture():
|
|
a=assignment();f=[[fl(x) for x in a[k]] for k in ('UiMin','UiMax','Region')]+[a['ID']]+[a[k] for k in ('UiMapID','OrderIndex','MapID','AreaID','WmoDoodadPlacementID','WmoGroupID','Unknown1125')]
|
|
physical={'UiMapAssignment':{'skipped':[],'rows':[{'id':a['ID'],'f':f}]},
|
|
'UiMap':{'skipped':[],'rows':[{'id':100,'f':[0,100,0,0,0,3],'Name':'Example'}]}}
|
|
decoded={'UiMapAssignment':{'skipped':[],'rows':[a]},'UiMap':{'skipped':[],'rows':[{'ID':100,'Type':3,'Name':'Example','ParentUiMapID':0,'Flags':0,'System':0}]}}
|
|
spawn=lambda guid,x,w=0:{'guid':guid,'entries':[101,0,0,0],'map':0,'x':x,'y':5.,'z':4.,'wander':w,'movement_type':0,'spawn_flags':0,'visibility_mod':0.}
|
|
snapshot={'schema':'tortoise-quest-location-snapshot-v2','spawns':[spawn(1,5),spawn(2,9,2),spawn(3,4)],'spawn_pools':[{'guid':3}], 'template_pools':[],'events':[]}
|
|
objective={'presentation_index':0,'candidate_presentation_id':400,'source_slot':1,'native_storage_index':5,'kind':'item','target':51868,'required_count':8,
|
|
'supported_sources':[{'creature':101,'condition_id':0,'phase_quest_id':0}], 'status':'partial', 'holds':['runtime_spawn_presence_not_verified'],
|
|
'clusters':[{'cell':[0,0],'point_refs':[[1,[101]],[2,[101]],[3,[101]]]}]}
|
|
dataset={'schema':'source-quest-objective-locations-v2','source_snapshot_sha256':'source-sha','quests':[{'quest_id':50,'holds':[],'objectives':[objective]}]}
|
|
return snapshot,dataset,physical,decoded,{'rows':[]},{'source_snapshot_sha256':'source-sha'}
|
|
|
|
def overlay(record,table='UiMapAssignment'):
|
|
record=copy.deepcopy(record)
|
|
for name,kind,_,_,count in WORLD_MAP_TABLES[table][2]:
|
|
if name not in record:record[name]=([0. if kind=='float' else 0]*count if count>1 else '' if kind=='locstring' else 0. if kind=='float' else 0)
|
|
raw=encode(record,WORLD_MAP_TABLES[table][2]);return {'table_name':table,'id':record['ID'],'record_status':'valid','record':record,'wire_hex':raw.hex(),'sha256':hashlib.sha256(raw).hexdigest()}
|
|
|
|
class LookupTest(unittest.TestCase):
|
|
def test_single_rectangle_is_only_a_held_candidate(self):
|
|
args=fixture();out=p.build(*args);o=out['quests'][0]['objectives'][0]
|
|
self.assertFalse(out['native_publication_allowed']);self.assertEqual(o['status'],'held_not_for_native_publication')
|
|
self.assertEqual((o['presentation_index'],o['native_storage_index']), (0,5))
|
|
self.assertEqual(o['input_spawn_refs'],3);self.assertEqual(o['candidate_spawn_refs'],1)
|
|
self.assertEqual(o['excluded_ref_counts'],{'crosses_assignment_boundary':1,'pool_or_event':1})
|
|
self.assertEqual(o['regions'][0]['candidate_uimap'],100);self.assertEqual(o['regions'][0]['bounds_xy'],[5,5,5,5])
|
|
self.assertIn('source_area_and_ancestry_not_verified',o['candidate_holds'])
|
|
def test_overlaps_wmo_replacements_and_no_native_ready(self):
|
|
s,d,physical,decoded,pkg,prov=fixture();pkg['rows']=[overlay({'ID':101,'Type':3},'UiMap'),overlay(assignment(2,101,[1.,1.,-100.,8.,8.,100.]))]
|
|
r=p.build(s,d,physical,decoded,pkg,prov);self.assertEqual(r['quests'][0]['objectives'][0]['status'],'held_no_area_candidates');self.assertEqual(r['coverage']['native_publishable_objectives'],0)
|
|
self.assertEqual(r['coverage']['excluded_reference_counts_all_objectives']['overlapping_zone_assignments'],1)
|
|
pkg['rows']=[overlay(assignment(1,100,[2.,2.,-100.,9.,9.,100.]))]
|
|
r=p.build(s,d,physical,decoded,pkg,prov);self.assertEqual(r['quests'][0]['objectives'][0]['regions'],[]) # old and intended assignments overlap
|
|
self.assertEqual(r['coverage']['excluded_reference_counts_all_objectives']['overlapping_zone_assignments'],1)
|
|
def test_unsafe_points_and_conditioned_source_are_not_candidates(self):
|
|
s,d,physical,decoded,pkg,prov=fixture();s['spawns'][0]['spawn_flags']=4
|
|
r=p.build(s,d,physical,decoded,pkg,prov);self.assertEqual(r['quests'][0]['objectives'][0]['regions'],[])
|
|
s['spawns'][0]['spawn_flags']=0;d['quests'][0]['objectives'][0]['supported_sources'][0]['condition_id']=42
|
|
r=p.build(s,d,physical,decoded,pkg,prov);self.assertEqual(r['quests'][0]['objectives'][0]['regions'],[])
|
|
def test_integrity_and_source_binding_fail_closed(self):
|
|
s,d,physical,decoded,pkg,prov=fixture();d['source_snapshot_sha256']='other'
|
|
with self.assertRaises(ValueError):p.build(s,d,physical,decoded,pkg,prov)
|
|
d['source_snapshot_sha256']='source-sha';d['quests'][0]['objectives'][0]['clusters'][0]['point_refs'].append([1,[101]])
|
|
with self.assertRaisesRegex(ValueError,'duplicate objective spawn'):p.build(s,d,physical,decoded,pkg,prov)
|
|
d['quests'][0]['objectives'][0]['clusters'][0]['point_refs'].pop();physical['UiMapAssignment']['rows'][0]['f'][4]=999
|
|
with self.assertRaises(ValueError):p.build(s,d,physical,decoded,pkg,prov)
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
f=Path(temp)/'x.json';f.write_text('{}')
|
|
with self.assertRaises(ValueError):p.load_pinned(f,'0'*64)
|
|
def test_wmo_phase_and_overlay_wire_mismatch_hold_or_reject(self):
|
|
s,d,physical,decoded,pkg,prov=fixture();data=assignment(2,101,[0.,0.,-100.,10.,10.,100.]);data['WmoDoodadPlacementID']=1
|
|
pkg['rows']=[overlay({'ID':101,'Type':3},'UiMap'),overlay(data)]
|
|
self.assertFalse(p.build(s,d,physical,decoded,pkg,prov)['quests'][0]['objectives'][0]['regions'])
|
|
pkg['rows']=[];d['quests'][0]['objectives'][0]['supported_sources'][0]['phase_quest_id']=42
|
|
self.assertFalse(p.build(s,d,physical,decoded,pkg,prov)['quests'][0]['objectives'][0]['regions'])
|
|
pkg['rows']=[overlay(assignment(2,100))];pkg['rows'][0]['sha256']='0'*64
|
|
with self.assertRaises(ValueError):p.build(s,d,physical,decoded,pkg,prov)
|
|
pkg['rows']=[overlay(assignment(2,100))];pkg['rows'][0]['record']['AreaID']=13
|
|
with self.assertRaisesRegex(ValueError,'record/wire mismatch'):p.build(s,d,physical,decoded,pkg,prov)
|
|
def test_source_alternatives_and_missing_visibility_held(self):
|
|
s,d,physical,decoded,pkg,prov=fixture();s['spawns'][0]['entries']=[101,102,0,0]
|
|
self.assertEqual(p.point_qualification(s['spawns'][0],p.map_index(physical,decoded,pkg),set(),set(),set())[1],'alternate_or_missing_creature')
|
|
s['spawns'][0]['entries']=[101,0,0,0];s['spawns'][0]['visibility_mod']=None
|
|
self.assertEqual(p.point_qualification(s['spawns'][0],p.map_index(physical,decoded,pkg),set(),set(),set())[1],'flags_or_visibility')
|
|
if __name__=='__main__':unittest.main()
|