367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
129 lines
6.0 KiB
Python
129 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Capture one actual X sit/stand cycle on an already logged-in disposable client.
|
|
|
|
The client launcher and login are owned by the caller. This runner does not
|
|
submit credentials, change server data, or retry an action after uncertainty.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import client_ui as ui
|
|
from client_session import Session
|
|
from native_engine_character_test import Controller, ROOT, local_listeners
|
|
from native_test_guard import (
|
|
require_authenticated_turtle_realm,
|
|
require_local_turtle_ports,
|
|
require_native_gameplay_policy,
|
|
)
|
|
from native_world_trace import WorldTrace
|
|
|
|
|
|
def latest_stand_field(pipe, guid, after):
|
|
fields = pipe.get('source_unit_fields')
|
|
if not fields or fields.get('retryable') or fields.get('available') is False:
|
|
return None
|
|
return next((row for row in reversed(fields.get('rows', []))
|
|
if row['legacy_guid'] == str(guid) and row['field'] == 138
|
|
and row['sequence'] > after), None)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--pid', type=int, required=True)
|
|
parser.add_argument('--self-guid', type=int, required=True)
|
|
parser.add_argument('--evidence', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
path = args.evidence.resolve()
|
|
if not 0 < args.pid or not 0 < args.self_guid < 2**64:
|
|
parser.error('Require positive client PID and actual source self GUID')
|
|
if not path.is_relative_to(ROOT / 'runtime') or path.suffix != '.json':
|
|
parser.error('Keep actual-client evidence under runtime in JSON')
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
os.umask(0o077)
|
|
require_local_turtle_ports(local_listeners())
|
|
controller = Controller(args.pid)
|
|
require_authenticated_turtle_realm(controller.rpc('inspect-wire-account'))
|
|
require_native_gameplay_policy(controller.rpc('inspect-native-channel-policy'))
|
|
|
|
def inspect():
|
|
pipe = controller.rpc('inspect-engine-pipe', unit_fields_only=True)
|
|
if pipe['error'] or pipe['closed'] or pipe['world'].get('self_create') != 1:
|
|
raise RuntimeError('Require live self-created native world; no action repeated')
|
|
if 'source_unit_fields' not in pipe:
|
|
raise RuntimeError('Source stand field observer unavailable; no action')
|
|
return pipe
|
|
|
|
report = dict(pid=args.pid, self_guid=str(args.self_guid), input='one X, then /stand cleanup',
|
|
native_payload_observed=False, renderer_application_verified=False)
|
|
action_index = None
|
|
try:
|
|
with Session(args.pid) as session, WorldTrace(controller) as trace:
|
|
ui_state = session.state()
|
|
if ui_state not in ('world', 'loading-or-unknown'):
|
|
raise RuntimeError('Require native world with no known login/roster screen; no action')
|
|
before = inspect()
|
|
stand = before['cast_result']
|
|
if stand['stand_state'] != 0:
|
|
raise RuntimeError('Require source-confirmed standing baseline; no action')
|
|
baseline_ack = stand['stand_received']
|
|
baseline_field = before['source_unit_fields']['total']
|
|
report['baseline'] = dict(stand_received=baseline_ack, stand_state=0,
|
|
field_sequence=baseline_field)
|
|
session.shot(path.with_name(path.stem + '-before.png'))
|
|
action_index = trace.bookmark()
|
|
ui.key(session.d, 'x')
|
|
report['x_sent'] = True
|
|
|
|
def seated():
|
|
pipe = inspect()
|
|
ack = pipe['cast_result']
|
|
row = latest_stand_field(pipe, args.self_guid, baseline_field)
|
|
if ack['stand_received'] > baseline_ack and ack['stand_state'] == 1 and row and row['value'] & 255 == 1:
|
|
return pipe, row
|
|
return None
|
|
|
|
try:
|
|
pipe, row = controller.wait(seated, 6)
|
|
report['seated_source'] = dict(ack=pipe['cast_result']['stand_received'], field=row)
|
|
session.shot(path.with_name(path.stem + '-seated.png'))
|
|
finally:
|
|
# Restore a source-confirmed seated state even when a field
|
|
# observation or screenshot failed. /stand is idempotent.
|
|
current = inspect()
|
|
if current['cast_result']['stand_state'] == 1:
|
|
report['stand_cleanup_attempted'] = True
|
|
cleanup_ack = current['cast_result']['stand_received']
|
|
cleanup_field = current['source_unit_fields']['total']
|
|
session.macro('/stand')
|
|
|
|
def upright():
|
|
current = inspect()
|
|
ack = current['cast_result']
|
|
field = latest_stand_field(current, args.self_guid, cleanup_field)
|
|
if ack['stand_received'] > cleanup_ack and ack['stand_state'] == 0 and field and field['value'] & 255 == 0:
|
|
return current, field
|
|
return None
|
|
|
|
pipe, row = controller.wait(upright, 6)
|
|
report['standing_source'] = dict(ack=pipe['cast_result']['stand_received'], field=row)
|
|
session.shot(path.with_name(path.stem + '-standing.png'))
|
|
except Exception as error:
|
|
report['error'] = str(error)
|
|
raise
|
|
finally:
|
|
if 'trace' in locals():
|
|
report['trace'] = trace.report()
|
|
if action_index is not None and 'trace' in report:
|
|
events = [event for event in report['trace']['trace'] if event['index'] > action_index]
|
|
report['stand_wire_events'] = [event for event in events if (event['direction'], event['opcode']) in {
|
|
(2, 0x3e0036), (1, 0x29d), (3, 0x4701c9), (3, 0x5e0000)}]
|
|
report['lost_metadata_rows'] = report['trace']['lost_metadata_rows']
|
|
path.write_text(json.dumps(report, indent=2) + '\n')
|
|
print('Actual disposable-client sit diagnostic:', path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|