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

63 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""One insufficient-money UI check with legitimate GM setup and restoration.
Requires the real original merchant already open and an exact saved baseline.
A client-side refusal is labelled separately from a genuine server failure.
Never retries a purchase or fabricates a response; no SQL writes.
"""
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
from native_world_trace import WorldTrace
from native_vendor_buy_test import inventory
def main():
p=argparse.ArgumentParser(description=__doc__)
for key in ('character','money','x','y'):p.add_argument('--'+key,type=int,required=True)
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 not 0<a.character<2**32 or not 0<a.money<2**31 or not(0<a.x<1920 and 0<a.y<1080):p.error('Require explicit bounded baseline and new runtime report')
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'))
money=lambda:db(f'SELECT money FROM tw_char.characters WHERE guid={a.character};')
if money()!=str(a.money):raise RuntimeError('Saved baseline differs; no change')
baseline=inventory(a.character);report=dict(pid=c.pid,external_gateway_running=False,money_before=a.money,before_inventory=baseline,purchase_attempted=False,restoration_pending=False,real_server_error_verified=False,ui_review_required=True);changed=False;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 native world')
ui.KEY_DELAY=.03;ui.key(s.d,'F1');changed=True;report['restoration_pending']=True
s.macro(f'/s .modify money -{a.money}');s.macro('/s .save');c.wait(lambda:money()=='0',8)
s.macro('/run print("GW zero-money fixture",GetMoney())');s.shot(out.with_name(out.stem+'-before.png'))
report['purchase_attempted']=True;ui.click_at(s.d,s.win,a.x,a.y,ui.ecodes.BTN_RIGHT)
# Capture transient UI error before save/print commands can outlast it.
s.shot(out.with_name(out.stem+'-immediate.png'))
try:
report['source_failure']=trace.wait(1,0x1a5,4);report['native_failure']=trace.wait(3,0x470173,4);report['real_server_error_verified']=True
except RuntimeError as error:
if str(error)!='Bounded native opcode observation expired; do not repeat a state change without inspection':raise
report['server_failure_not_observed']=True
s.macro('/s .save');report['money_after_attempt']=money();report['after_inventory']=inventory(a.character)
if report['money_after_attempt']!='0' or report['after_inventory']!=baseline:raise RuntimeError('Rejected purchase changed authoritative state')
s.macro('/run print("GW rejected buy",GetMoney())');s.shot(out.with_suffix('.png'))
except Exception as error:failure=type(error).__name__+': '+str(error)
finally:
try:
if changed:
with Session(c.pid) as s:
if s.state()!='world' or money()!='0':raise RuntimeError('Restoration baseline differs; preserve evidence')
ui.KEY_DELAY=.03;ui.key(s.d,'F1');s.macro(f'/s .modify money {a.money}');s.macro('/s .save');c.wait(lambda:money()==str(a.money),8)
if inventory(a.character)!=baseline:raise RuntimeError('Inventory changed during fixture')
report['restoration_pending']=False;report['money_restored']=money()
s.macro('/run print("GW wallet restored",GetMoney())');s.shot(out.with_name(out.stem+'-restored.png'))
except Exception as error:report['restoration_error']=type(error).__name__+': '+str(error)
ui.KEY_DELAY=old
report.update(trace.report());report['native_buy_request_observed']=any(r['direction']==2 and r['opcode']==0x3f003b for r in report['trace'])
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','purchase_attempted','real_server_error_verified','native_buy_request_observed','money_after_attempt','money_restored','restoration_pending','lost_metadata_rows','observer_error','failure','restoration_error')}))
return 0 if not failure and not report['restoration_pending'] and not trace.error else 2
if __name__=='__main__':raise SystemExit(main())