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

71 lines
6.6 KiB
Python

#!/usr/bin/env python3
"""Save one genuine known spell to an empty original action slot, or inspect relog.
No SQL writes, spell grants, packet injection, overwrite or action retry. The
original C_Spell.PickupSpell cursor is checked before original PlaceAction.
"""
import argparse,json,time
from pathlib import Path
from client_installation import client_debug_socket
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','spell','slot'):p.add_argument('--'+name,type=int,required=True)
p.add_argument('--logout-and-check',action='store_true',help='Required for assignment: normal close exercises MasterPlayer action save')
p.add_argument('--check-saved',action='store_true',help='Read-only original client API/saved-state inspection after relog')
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.spell<2**24 or not 1<=a.slot<=120:p.error('Require new runtime report and bounded authentic source spell/slot')
if not a.check_saved and not a.logout_and_check:p.error('Assignment requires explicit normal logout/save verification')
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;'))
if db(f'SELECT active,disabled FROM tw_char.character_spell WHERE guid={a.character} AND spell={a.spell};')!='1\t0':raise RuntimeError('Source spell is not saved active/learned; no input')
bars=lambda:db(f'SELECT button,action,type FROM tw_char.character_action WHERE guid={a.character} ORDER BY button;')
row=lambda:db(f'SELECT action,type FROM tw_char.character_action WHERE guid={a.character} AND button={a.slot-1};')
before=bars();baseline=inventory(a.character);state=lambda:db(f'SELECT level,health,money,extra_flags FROM tw_char.characters WHERE guid={a.character};');before_state=state()
if row()!=(f'{a.spell}\t0' if a.check_saved else ''):raise RuntimeError('Source slot does not match empty/known baseline; no action')
report=dict(pid=c.pid,external_gateway_running=False,character=a.character,spell=a.spell,slot=a.slot,check_saved=a.check_saved,before_actions=before,before_character_state=before_state,action_attempted=False,server_action_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 actual native world')
ui.KEY_DELAY=.03
if not a.check_saved:
# Existing cursor is preserved unless the exact source spell
# was already picked up; no swap of a populated native slot.
s.macro(f'/run if not GetCursorInfo() and not GetActionInfo({a.slot}) and IsSpellKnown({a.spell}) then C_Spell.PickupSpell({a.spell}) end;print("GW action cursor",GetCursorInfo())')
report['action_attempted']=True
s.macro(f'/run local t,_,_,id=GetCursorInfo();if t=="spell" and id=={a.spell} and not GetActionInfo({a.slot}) then PlaceAction({a.slot}) end;print("GW assigned",GetActionInfo({a.slot}))')
report['native_request']=trace.wait(2,0x440062,4)
# Source .save calls Player::SaveToDB, not MasterPlayer::SaveActions.
# Do not wait for a database update before normal logout.
s.macro(f'/run print("GW saved action",GetActionInfo({a.slot}));print("GW saved known",IsPlayerSpell({a.spell}),IsSpellKnown({a.spell}));print("GW cursor",GetCursorInfo())')
s.shot(out.with_suffix('.png'));report.update(after_actions=bars(),after_character_state=state(),inventory_unchanged=inventory(a.character)==baseline)
expected=sorted((before.splitlines() if before else [])+([] if a.check_saved else [f'{a.slot-1}\t{a.spell}\t0']),key=lambda v:int(v.split('\t')[0]))
if (a.check_saved and report['after_actions'].splitlines()!=expected) or report['after_character_state']!=before_state or not report['inventory_unchanged']:raise RuntimeError('Original source actions/character/inventory changed unexpectedly')
pipe=c.rpc('inspect-engine-pipe');report.update(pipe_error=pipe['error'],pipe_closed=pipe['closed'],native_pipe_healthy=not pipe['error'] and not pipe['closed'],server_action_verified=a.check_saved and not pipe['error'] and not pipe['closed'])
except Exception as error:failure=type(error).__name__+': '+str(error);report['saved_actions_after_failure']=bars()
finally:ui.KEY_DELAY=old
report.update(trace.report())
if not failure and not a.check_saved:
try:
from client_installation import close_test_client
close_test_client();end=time.monotonic()+35
while db('SELECT COUNT(*) FROM tw_char.characters WHERE online<>0;')!='0' or (client_debug_socket(ROOT)).exists():
if time.monotonic()>end:raise RuntimeError('Normal logout/save not complete; client state preserved')
time.sleep(.15)
report.update(after_logout_actions=bars(),after_logout_character_state=state())
if report['after_logout_actions'].splitlines()!=expected or state()!=before_state or inventory(a.character)!=baseline:raise RuntimeError('Logout action save/original character state differs; inspect before retry')
report['server_action_verified']=report['native_pipe_healthy']
except Exception as error:failure=type(error).__name__+': '+str(error)
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','spell','slot','check_saved','native_request','server_action_verified','inventory_unchanged','lost_metadata_rows','observer_error','failure')}))
return 0 if report['server_action_verified'] and not trace.error else 2
if __name__=='__main__':raise SystemExit(main())