Files
WoW-Hybrid-gateway/ops/native_weapon_tooltip_test.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

161 lines
11 KiB
Python

#!/usr/bin/env python3
"""Read original item-tooltip source damage in a local native world.
Actual font strings and provider counters, not just raw C_TooltipInfo output.
No equip, item grants, DB writes or compiled-engine damage claims.
"""
import argparse
import json
import secrets
import time
from pathlib import Path
from client_session import Session
from console_report import parse
from item_damage_profile import verified_payload
from native_engine_character_test import Controller, ROOT, local_listeners
from native_test_guard import require_authenticated_turtle_realm, require_local_turtle_ports
import client_ui as ui
def commands(ident, equipped_slot=None, native_primary=False):
rows = [
f'/run GameTooltip:SetOwner(UIParent,"ANCHOR_NONE");GameTooltip:SetHyperlink("item:{ident}")',
'/run GameTooltip:ClearAllPoints();GameTooltip:SetPoint("CENTER",UIParent,"CENTER",0,0)',
'/run for _,n in ipairs({"ShoppingTooltip1","ShoppingTooltip2"})do local t=_G[n];if t then t:Hide()end end',
f'/run GatewayDiagnosticsSaved.weaponTooltips.items[{ident}]={{left={{}},right={{}}}};GWWT=GatewayDiagnosticsSaved.weaponTooltips.items[{ident}]',
'/run local n=GameTooltip:NumLines();if not issecretvalue(n)and type(n)=="number"and n>=1 and n<=40 then GWWT.lineCount=n end',
'/run for i=1,GWWT.lineCount or 0 do local f=_G["GameTooltipTextLeft"..i];local t=f and f:GetText();if not issecretvalue(t)and type(t)=="string"then GWWT.left[i]=t end end',
'/run for i=1,GWWT.lineCount or 0 do local f=_G["GameTooltipTextRight"..i];local t=f and f:GetText();if not issecretvalue(t)and type(t)=="string"then GWWT.right[i]=t end end',
'/run local t=GameTooltip:GetPrimaryTooltipInfo();if t then GWWT.getter=t.getterName;GWWT.argument=t.getterArgs and t.getterArgs[1]end;GWWT=nil;GWRAW=nil',
]
if native_primary:
rows[-1:-1]=[
'/run GWWT.native={left={},right={}};GWRAW=C_TooltipInfo.GetItemByID('+str(ident)+');if issecretvalue(GWRAW)or not(type(GWRAW)=="table")then GWRAW=nil end',
'/run if GWRAW then local i,l=GWRAW.id,GWRAW.lines;if not issecretvalue(i)and i=='+str(ident)+' and not issecretvalue(l)and type(l)=="table"and #l<=80 then GWRAW=l else GWRAW=nil end end',
'/run for i,r in ipairs(GWRAW or{})do if not issecretvalue(r)and type(r)=="table"then local t=r.leftText;if not issecretvalue(t)and type(t)=="string"then GWWT.native.left[i]=t end end end',
'/run for i,r in ipairs(GWRAW or{})do if not issecretvalue(r)and type(r)=="table"then local t=r.rightText;if not issecretvalue(t)and type(t)=="string"then GWWT.native.right[i]=t end end end',
]
if equipped_slot is not None:
if type(equipped_slot)is not int or not 1<=equipped_slot<=19:raise ValueError('Original equipment slot bound')
rows[0]=f'/run GameTooltip:ClearLines();local i=GetInventoryItemID("player",{equipped_slot});if not issecretvalue(i)and i=={ident} then GameTooltip:SetOwner(UIParent,"ANCHOR_NONE");GameTooltip:SetInventoryItem("player",{equipped_slot})end'
rows.insert(-1,f'/run local i=GetInventoryItemID("player",{equipped_slot});if not issecretvalue(i)then GWWT.equippedItemID=i end')
return rows
def effect_expectations(values,items):
if not isinstance(values,dict)or set(values)!={str(i)for i in items}:
raise ValueError('One explicit effect expectation list per sampled item required')
for lines in values.values():
if not isinstance(lines,list)or not 1<=len(lines)<=8 or any(not isinstance(s,str)or not s or len(s)>4096 for s in lines):
raise ValueError('Bounded independent source effect text required')
return values
def missing_effect_lines(observed,expected):
left=observed.get('left',{})
lines=list(left.values())if isinstance(left,dict)else left
if not isinstance(lines,list):return list(expected)
return [line for line in expected if line not in lines]
def item_context_matches(observed,ident,slot=None):
if slot is None:
return observed.get('getter')=='GetHyperlink'and observed.get('argument')=='item:'+str(ident)
return(observed.get('getter')=='GetInventoryItem'and observed.get('argument')=='player'
and observed.get('equippedItemID')==ident)
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--profile',type=Path,required=True)
p.add_argument('--items',type=int,nargs='+',required=True)
p.add_argument('--output',type=Path,required=True)
p.add_argument('--reload',action='store_true',help='Reload the installed UI provider once before testing')
p.add_argument('--equipped-slots',type=int,nargs='+',help='Read corresponding actual equipment slots instead of base hyperlinks; never changes equipment')
p.add_argument('--expected-effects',type=Path,help='JSON item-ID to exact source-backed effect lines; base damage acceptance alone does not validate effects')
p.add_argument('--expect-native-primary',action='store_true',help='Also require original C_TooltipInfo base primary damage/speed/DPS, before any presentation callback')
a=p.parse_args();out=a.output.resolve()
if not out.is_relative_to(ROOT/'runtime')or out.exists()or not 1<=len(a.items)<=6 or len(set(a.items))!=len(a.items):
p.error('Fresh runtime evidence and1..6 distinct item IDs required')
verified_payload(a.profile,ROOT/'runtime/all-item-templates-20261017',Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'))
profile=json.loads((a.profile/'profile.json').read_text())
if profile.get('primary_tooltips')is not True or not set(a.items)<=set(profile['primary_item_ids']):
raise ValueError('Every sample requires verified physical-weapon primary source data')
rows={r['item_id']:r for r in profile['records']}
if a.equipped_slots is not None and len(a.equipped_slots)!=len(a.items):raise ValueError('One actual equipment slot per expected source item required')
slots=a.equipped_slots or [None]*len(a.items)
effects={}if a.expected_effects is None else effect_expectations(json.loads(a.expected_effects.read_text()),a.items)
macros={i:commands(i,slot,a.expect_native_primary)for i,slot in zip(a.items,slots)}
if any(len(c)>255 or '`'in c or '~'in c for cs in macros.values()for c in cs):raise ValueError('Macro bound')
require_local_turtle_ports(local_listeners());c=Controller(int((ROOT/'runtime/native-client.pid').read_text()))
require_authenticated_turtle_realm(c.rpc('inspect-wire-account'))
pipe=c.rpc('inspect-engine-pipe')
if pipe['error']or pipe['closed']or not pipe['world_auth']or not pipe['world']['self_create']:raise RuntimeError('Native local world required')
saved=ROOT/'runtime/native-client/_classic_beta_/WTF/Account/SavedVariables/GatewayDiagnostics.lua'
nonce=secrets.token_hex(4);out.mkdir(mode=0o700);started=time.monotonic()
report=dict(kind='actual-native-source-weapon-instance-tooltips'if a.equipped_slots else'actual-native-source-weapon-base-tooltips',pid=c.pid,local_only=True,
external_gateway_running=False,character_modified=False,compiled_damage_verified=False)
try:
with Session(c.pid)as s:
s.wait_world()
if a.reload:s.macro('/run ReloadUI()');s.wait_world(timeout=15)
# Verified original chat-menu button catches mouseover without
# clicking or changing character state. A passing world creature
# otherwise replaces a manually anchored GameTooltip mid-capture.
size=s.win.get_geometry()
if size.width<640 or size.width>8192 or size.width*9!=size.height*16:raise RuntimeError('Unverified tooltip pointer aspect/size')
ui.click_at(s.d,s.win,round(16*size.width/1920),round(920*size.height/1080),button=None)
s.macro('/run GatewayDiagnosticsSaved.weaponTooltips={run="'+nonce+'",items={}}')
for ident,cs in macros.items():
for command in cs:s.macro(command)
s.shot(out/(str(ident)+'.png'));print('Captured original weapon tooltip',ident,flush=True)
s.macro('/run GatewayDiagnosticsSaved.weaponTooltips.diagnostics=GatewaySourceWeaponDamageDiagnostics;GameTooltip:Hide()')
s.macro('/run ReloadUI()')
def observed():
try:
v=parse(saved.read_text()).get('weaponTooltips',{})
return v if v.get('run')==nonce else None
except(OSError,ValueError):return None
actual=c.wait(observed,15);s.wait_world(timeout=15)
samples=[]
for ident,slot in zip(a.items,slots):
row=rows[ident];band=row['bands'][0]
dps=sum((b['minimum']+b['maximum'])/2 for b in row['bands'])*1000/row['delay_ms']
expected=dict(damage='%g - %g Damage'%(band['minimum'],band['maximum']),
speed='Speed %.2f'%(row['delay_ms']/1000),dps='(%.1f damage per second)'%dps)
got=actual.get('items',{}).get(ident,{})
left=got.get('left',{});right=got.get('right',{})
if isinstance(left,dict):left=list(left.values())
if isinstance(right,dict):right=list(right.values())
context_match=item_context_matches(got,ident,slot)
good=context_match and all(v in (right if k=='speed'else left)for k,v in expected.items())
if slot is not None:good=good and got.get('equippedItemID')==ident
sample=dict(item_id=ident,expected=expected,observed=got,source_lines_match=good,item_context_match=context_match)
if effects:
missing=missing_effect_lines(got,effects[str(ident)])
sample.update(expected_effect_lines=effects[str(ident)],missing_effect_lines=missing,source_effect_lines_match=not missing)
if a.expect_native_primary:
primary=dict(expected,dps='(%.1f damage per second)'%((band['minimum']+band['maximum'])*500/row['delay_ms']))
native=got.get('native',{});ls=native.get('left',{});rs=native.get('right',{})
if isinstance(ls,dict):ls=list(ls.values())
if isinstance(rs,dict):rs=list(rs.values())
sample.update(expected_native_primary=primary,native_primary_match=all(v in(rs if k=='speed'else ls)for k,v in primary.items()))
samples.append(sample)
diag=actual.get('diagnostics',{})
report.update(samples=samples,diagnostics=diag,all_samples_match=all(s['source_lines_match']for s in samples),
callback_errors=diag.get('errors'),provider_executed=diag.get('damageLines',0)>=len(a.items)and diag.get('dpsLines',0)>=len(a.items))
if a.equipped_slots:report['provider_executed']=report['provider_executed']and diag.get('instanceBaseMatches',0)>=len(a.items)
if effects:report['all_effect_lines_match']=all(s['source_effect_lines_match']for s in samples)
if a.expect_native_primary:report['all_native_primary_match']=all(s['native_primary_match']for s in samples)
except Exception as error:
report['failure']=type(error).__name__+': '+str(error);raise
finally:
report['elapsed_seconds']=round(time.monotonic()-started,3)
(out/'result.json').write_text(json.dumps(report,indent=2)+'\n')
print('Original tooltip source lines:',report['all_samples_match'],'provider:',report['provider_executed'],'errors:',report['callback_errors'])
return 0 if report['all_samples_match']and report['provider_executed']and report['callback_errors']==0 and report.get('all_effect_lines_match',True)and report.get('all_native_primary_match',True)else 2
if __name__=='__main__':raise SystemExit(main())