Files
WoW-Hybrid-gateway/ops/native_talent_apply_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

104 lines
7.4 KiB
Python

#!/usr/bin/env python3
"""Stage real original-frame talent clicks and verify genuine source ACKs.
Only the designated disposable local Warrior; no GM talent grants, direct
packet injection, source DB writes, fake C_Traits configuration or auto-retry.
SavedVariables are audit evidence after UI reload, never authentication input.
"""
import argparse,json,time
from pathlib import Path
from client_session import Session
import client_ui as ui
from console_report import parse
from local_tortoise import db
from native_engine_character_test import ROOT,Controller,local_listeners
from native_test_guard import require_local_turtle_ports,require_authenticated_turtle_realm,require_native_gameplay_policy,require_solo_test_character
from native_world_trace import WorldTrace
from talent_ui_test import title_is_visible
def saved_file():
files=list((ROOT/'runtime/native-client/_classic_beta_/WTF').rglob('GatewayDiagnostics.lua'))
if not files:raise RuntimeError('No private provider audit file')
return max(files,key=lambda p:p.stat().st_mtime_ns)
def persisted(s):
p=saved_file();before=p.stat().st_mtime_ns;s.macro('/reload');until=time.monotonic()+8
while p.stat().st_mtime_ns==before:
if time.monotonic()>until:raise RuntimeError('UI save not observed; do not infer live state from stale audit')
time.sleep(.05)
s.wait_world(10)
return parse(p.read_text())
def show(s,path):
s.macro('/turtletalents');until=time.monotonic()+5
while True:
s.shot(path)
if title_is_visible(path):return
if time.monotonic()>until:raise RuntimeError('Original talent page not verified; no click')
time.sleep(.05)
def rank(t,state,successors=None):
known=state['known']
def learned(spell):
ids=[spell]+(successors or {}).get(str(spell),(successors or {}).get(spell,[]))
return any(known.get(ident,known.get(str(ident),False))for ident in ids)
return max((i for i,r in enumerate(t['ranks'],1) if learned(r['id'])),default=0)
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--target',action='append',required=True,help='Authentic source TALENT:FINAL_RANK; multiple allowed')
p.add_argument('--output',type=Path,required=True);a=p.parse_args();out=a.output.resolve()
if not out.is_relative_to(ROOT/'runtime') or out.exists() or not out.parent.is_dir():p.error('Require new runtime output with existing parent')
data=json.loads((ROOT/'build/turtle-data/talents.json').read_text());by_id={t['id']:t for t in data['talents']}
targets={}
for value in a.target:
pair=value.split(':')
if len(pair)!=2 or not all(x.isdecimal()for x in pair):p.error('Require source talent:rank')
key,n=map(int,pair);t=by_id.get(key)
if not t or key in targets or not 1<=n<=len(t['ranks']):p.error('Invalid/duplicate genuine talent rank')
targets[key]=n
require_local_turtle_ports(local_listeners());require_solo_test_character(4509,db('SELECT guid FROM tw_char.characters WHERE online<>0 ORDER BY guid;'))
c=Controller(int((ROOT/'runtime/native-client.pid').read_text()));require_authenticated_turtle_realm(c.rpc('inspect-wire-account'));require_native_gameplay_policy(c.rpc('inspect-native-channel-policy'))
report=dict(pid=c.pid,build=70334,external_gateway_running=False,targets=targets,verified=False);old=ui.KEY_DELAY;failure=None
with WorldTrace(c)as trace:
try:
with Session(c.pid)as s:
s.wait_world();ui.KEY_DELAY=.03;show(s,out.with_name(out.stem+'-baseline.png'))
baseline=persisted(s);state=baseline.get('turtleLastAcknowledgedState')
if not state or state['guid']!=4509 or state['class']!=1 or state['level']!=60:raise RuntimeError('Fresh provider source identity differs')
report['before']=state;report['blocked_before']=len(baseline.get('turtleBlockedActions',[]))
tabs=sorted((t for t in data['talent_tabs']if t['classMask']&1),key=lambda t:t['order']);groups={t['id']:i for i,t in enumerate(tabs)}
cost=sum(n-rank(by_id[key],state,data.get('rank_successors'))for key,n in targets.items())
if not 0<cost<=state['points'] or any(by_id[key]['tab']not in groups or n<=rank(by_id[key],state,data.get('rank_successors'))for key,n in targets.items()):raise RuntimeError('Targets unchanged/lower/wrong class or exceed real points')
show(s,out.with_name(out.stem+'-ready.png'))
for key,n in sorted(targets.items(),key=lambda row:(by_id[row[0]]['row'],row[0])):
t=by_id[key];x=468+400*groups[t['tab']]+60*t['column'];y=285+60*t['row']
for _ in range(n-rank(t,state,data.get('rank_successors'))):
ui.click_at(s.d,s.win,x,y);time.sleep(.04) # Measured release-frame requirement, not ACK.
s.shot(out.with_name(out.stem+'-staged.png'));bookmark=trace.bookmark();ui.click_at(s.d,s.win,960,727)
# Genuine source spell responses establish execution; audit
# below additionally checks every rank and exact point cost.
until=time.monotonic()+10
while True:
observation=trace.report()
learns=[r for r in observation['trace']if r['index']>bookmark and r['direction']==1 and r['opcode']in(0x12b,0x12c)]
if len(learns)>=cost:break
if observation['observer_error']or time.monotonic()>until:raise RuntimeError('Source rank responses incomplete; no purchase replay')
time.sleep(.05)
s.shot(out.with_name(out.stem+'-after.png'));s.macro('/s .save')
after=persisted(s);report['after']=after.get('turtleLastAcknowledgedState');report['apply']=after.get('turtleApply');report['blocked_after']=len(after.get('turtleBlockedActions',[]))
state2=report['after'];apply=report['apply']
if not state2 or not apply or apply['status']!='complete' or apply['accepted']!=cost or apply['total']!=cost or state2['points']!=state['points']-cost or any(rank(by_id[key],state2,data.get('rank_successors'))!=n for key,n in targets.items()):raise RuntimeError('Real rank/point/Apply audit incomplete; preserve accepted state and inspect without retry')
if report['blocked_after']!=report['blocked_before']:raise RuntimeError('New blocked-action event occurred')
ids=[by_id[key]['ranks'][n-1]['id']for key,n in targets.items()]
expected={str(i)for i in ids}
saved=db('SELECT spell FROM tw_char.character_spell WHERE guid=4509 AND active=1 AND disabled=0 AND spell IN ('+','.join(map(str,ids))+') ORDER BY spell;')
report['source_saved_spells']=saved.splitlines()
if set(saved.splitlines())!=expected:raise RuntimeError('Saved source ranks differ after legitimate save')
show(s,out.with_name(out.stem+'-verified.png'));report['verified']=True
except Exception as e:failure=type(e).__name__+': '+str(e)
finally:ui.KEY_DELAY=old
report.update(trace.report());report['failure']=failure;out.write_text(json.dumps(report,indent=2)+'\n');out.chmod(0o600)
print(json.dumps({k:report.get(k)for k in ('pid','targets','verified','apply','blocked_before','blocked_after','source_saved_spells','failure','lost_metadata_rows','observer_error')}))
return 0 if report['verified']and not trace.error else 2
if __name__=='__main__':raise SystemExit(main())