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

75 lines
6.8 KiB
Python

#!/usr/bin/env python3
"""One genuine original trainer button purchase, with source identity checks.
Requires selected/reviewed original service and exact saved wallet. No spell
GM grant, SQL write, packet injection, modern trait purchase or automatic retry.
"""
import argparse,json
from pathlib import Path
from client_session import Session
import client_ui as ui
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 native_vendor_buy_test import inventory
def main():
p=argparse.ArgumentParser(description=__doc__)
for name in ('character','npc-entry','service','learned','cost','money','x','y'):p.add_argument('--'+name,type=int,required=True)
p.add_argument('--temporarily-visible',action='store_true',help='Controlled GM-invisibility comparison; exact flags restored in finally')
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() or any(not 0<v<2**31 for v in (a.character,a.npc_entry,a.service,a.learned,a.cost,a.money)) or not(0<a.x<1920 and 0<a.y<1080):p.error('Require bounded explicit reviewed source service/wallet and new runtime output')
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'));require_native_gameplay_policy(c.rpc('inspect-native-channel-policy'));require_solo_test_character(a.character,db('SELECT guid FROM tw_char.characters WHERE online<>0 ORDER BY guid;'))
money=lambda:db(f'SELECT money FROM tw_char.characters WHERE guid={a.character};')
spell=lambda:db(f'SELECT spell,active,disabled FROM tw_char.character_spell WHERE guid={a.character} AND spell={a.learned};')
if money()!=str(a.money) or spell():raise RuntimeError('Saved wallet/learned baseline differs; no action')
source=db(f'SELECT n.spellcost,s.effectTriggerSpell1 FROM tw_world.npc_trainer n JOIN tw_world.spell_template s ON s.entry=n.spell WHERE n.entry={a.npc_entry} AND n.spell={a.service};')
if source!=f'{a.cost}\t{a.learned}':raise RuntimeError('Source service cost/learn-wrapper relation differs; no action')
baseline_flags=int(db(f'SELECT extra_flags FROM tw_char.characters WHERE guid={a.character};'));visibility_changed=False
if a.temporarily_visible and (not baseline_flags&16 or not baseline_flags&1):raise RuntimeError('Require recorded GM+invisibility baseline for this controlled comparison')
baseline=inventory(a.character);report=dict(pid=c.pid,external_gateway_running=False,npc_entry=a.npc_entry,service=a.service,learned=a.learned,cost=a.cost,money_before=a.money,source_offer=source,before_inventory=baseline,purchase_attempted=False,server_training_verified=False,ui_review_required=True);failure=None;old=ui.KEY_DELAY
with WorldTrace(c) as trace:
try:
with Session(c.pid) as s:
if s.state()!='world':raise RuntimeError('Require original world/trainer UI')
ui.KEY_DELAY=.03
if a.temporarily_visible:
report['baseline_extra_flags']=baseline_flags;report['visibility_restoration_pending']=True;visibility_changed=True
s.macro('/s .gm visible on');s.macro('/s .save')
c.wait(lambda:int(db(f'SELECT extra_flags FROM tw_char.characters WHERE guid={a.character};'))==baseline_flags&~16,8)
report['visible_extra_flags']=baseline_flags&~16
s.macro(f'/run print("GW before training",IsPlayerSpell({a.learned}),IsSpellKnown({a.learned}))');s.shot(out.with_name(out.stem+'-before.png'))
report['purchase_attempted']=True;ui.click_at(s.d,s.win,a.x,a.y)
try:report['native_request']=trace.wait(2,0x3f0046,3)
except RuntimeError as error:
if str(error)!='Bounded native opcode observation expired; do not repeat a state change without inspection':raise
report['outgoing_metadata_missing']=True
report['source_learn']=trace.wait(1,0x12b,5);report['native_learn']=trace.wait(3,0x690040,5);report['source_training_success']=trace.wait(1,0x1b3,5)
s.macro('/s .save');c.wait(lambda:money()==str(a.money-a.cost) and spell()==f'{a.learned}\t1\t0',8)
report.update(money_after=money(),saved_learned=spell(),after_inventory=inventory(a.character))
if report['after_inventory']!=baseline:raise RuntimeError('Training unexpectedly changed original inventory')
s.macro(f'/run print("GW after training",IsPlayerSpell({a.learned}),IsSpellKnown({a.learned}),GetMoney())');s.shot(out.with_suffix('.png'))
pipe=c.rpc('inspect-engine-pipe');report.update(pipe_error=pipe['error'],pipe_closed=pipe['closed'],server_training_verified=not pipe['error'] and not pipe['closed'])
except Exception as error:
failure=type(error).__name__+': '+str(error);report.update(saved_money_after_failure=money(),saved_spell_after_failure=spell())
finally:
try:
if visibility_changed:
with Session(c.pid) as s:
if s.state()!='world':raise RuntimeError('World lost before GM visibility restoration')
ui.KEY_DELAY=.03;s.macro('/s .gm visible off')
# Source SetGMVisible(false) clears accept-whispers. Restore
# that separately, without changing account permissions.
if baseline_flags&4:s.macro('/s .whispers on')
s.macro('/s .save');c.wait(lambda:int(db(f'SELECT extra_flags FROM tw_char.characters WHERE guid={a.character};'))==baseline_flags,8)
report['restored_extra_flags']=baseline_flags;report['visibility_restoration_pending']=False
except Exception as error:report['visibility_restoration_error']=type(error).__name__+': '+str(error)
ui.KEY_DELAY=old
report.update(trace.report())
if failure: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','native_request','source_learn','native_learn','source_training_success','money_after','saved_learned','server_training_verified','lost_metadata_rows','observer_error','failure','restored_extra_flags','visibility_restoration_pending','visibility_restoration_error')}))
return 0 if report['server_training_verified'] and not trace.error and not report.get('visibility_restoration_pending',False) else 2
if __name__=='__main__':raise SystemExit(main())