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

163 lines
11 KiB
Python

#!/usr/bin/env python3
"""Manual development support for the existing verified native channel policy.
Requires an already authenticated session; optionally waits for the user to
enter its world before enabling the existing policy. Never logs in, selects
a character, enters the world, resolves DNS, queries a database, or sends input,
chat, movement, or screenshots. Cold original code is observed for at most30s;
only the user may cause its natural execution through ordinary client controls.
Enabling/reusing this existing policy is not a native gameplay acceptance test.
"""
import argparse
import json
import os
from pathlib import Path
from client_installation import client_debug_socket
import time
from engine_channel_policy_host import TARGETS
from native_engine_character_test import Controller,ROOT,local_listeners
from native_manual_login import PROFILES,binding_for,require_genuine,require_realm
from native_test_guard import require_native_gameplay_policy
def contracts_ready(policy):
rows=policy.get('code_contracts')
if not isinstance(rows,list) or len(rows)!=len(TARGETS):raise ValueError('Fixed contract list differs')
ready=True
for row,(address,prefix) in zip(rows,TARGETS):
if row.get('address')!=hex(address) or any(type(row.get(key)) is not bool for key in ('readable','executable','prefix_matches')):
raise ValueError('Fixed contract metadata differs')
if row['prefix_matches'] and (not row['readable'] or row.get('observed_prefix',prefix)!=prefix):
raise ValueError('Fixed contract metadata contradicts its verified prefix')
# False flags alone can be ordinary protected/encoded cold pages.
# They never authorize calls, unprotection, or corruption diagnoses.
ready=ready and row['prefix_matches'] and row['executable']
return ready
def snapshot(c,pid,profile,pending=False,wait_world=False):
if int((ROOT/'runtime/native-client.pid').read_text())!=pid:raise ValueError('Owned client PID changed')
if 19085 in local_listeners():raise ValueError('External gateway is running')
binding_for(pid,profile)
account=c.rpc('inspect-wire-account');require_genuine(account)
if account['state']!=2 or account.get('transport_prepared')!=1 or account.get('transport_result')!=0:
raise ValueError('Require an existing prepared authenticated session')
realm=require_realm(account,account.get('selected_index'),profile)
pipe=c.rpc('inspect-engine-pipe');world=pipe.get('world',{})
engine=c.rpc('inspect-engine-session');net=engine.get('netclient',{})
if pipe.get('error')!=0 or pipe.get('closed')!=0 or pipe.get('world_auth')!=1:
raise ValueError('Require a live authenticated world transport')
world_ready=bool(world.get('login_sent')==1 and world.get('self_create')==1 and net.get('state_enum')==5 and
net.get('packet_host',{}).get('self_create_consumed') is True)
if not world_ready and not wait_world:
raise ValueError('Require a live authenticated engine-consumed world')
credentials=account.get('memory_credentials',{})
identity=(pid,profile,account['selected_index'],account['realm_count'],realm.get('name'),realm['address'],
realm.get('wire_id'),credentials.get('generation'),credentials.get('consumed_generation'))
if wait_world:
generation=credentials.get('generation');consumed=credentials.get('consumed_generation')
if type(generation) is not int or generation<=0 or type(consumed) is not int or consumed!=generation:
raise ValueError('World wait requires a consumed memory credential generation')
if not world_ready:return dict(identity=identity,realm=realm,world_ready=False)
policy=c.rpc('inspect-native-channel-policy')
if (policy.get('error')!=0 or type(policy.get('enabled')) is not bool or
type(policy.get('owner_matches')) is not bool or policy.get('command') not in ((0,1) if pending else (0,))):
raise ValueError('Channel policy is unhealthy or has another pending command')
if policy['enabled']:
require_native_gameplay_policy(policy)
if not policy['owner_matches']:raise ValueError('Enabled channel owner differs')
elif not pending and policy['owner_matches']:
raise ValueError('Disabled channel already has an owner; preserve it')
ready=contracts_ready(policy)
return dict(identity=identity,realm=realm,policy=policy,contracts_ready=ready,world_ready=True)
def run(profile,timeout,report,wait_world=0):
if profile not in PROFILES or not 1<=timeout<=30 or not 0<=wait_world<=120:raise ValueError('Invalid fixed profile or observation bound')
pid=int((ROOT/'runtime/native-client.pid').read_text())
if pid<=0 or not (client_debug_socket(ROOT)).is_socket():raise ValueError('Require existing owned client/debug owner')
report.update(pid=pid,endpoint_profile=profile,phase='validate-existing-world',wait_world_seconds=wait_world)
c=Controller(pid);initial=snapshot(c,pid,profile,wait_world=bool(wait_world));identity=initial['identity']
if wait_world:
world_started=time.monotonic();world_deadline=world_started+wait_world;polls=0
if not initial['world_ready']:
report['phase']='awaiting-manual-world-entry'
print('Waiting for you to enter the already authenticated world. This helper performs no login, selection, world entry, input, chat or movement.',flush=True)
while not initial['world_ready']:
remaining=world_deadline-time.monotonic()
if remaining<=0:raise TimeoutError('Manual world-entry wait expired; no policy action')
time.sleep(min(.2,remaining));polls+=1
initial=snapshot(c,pid,profile,wait_world=True)
if initial['identity']!=identity:raise ValueError('Authenticated account or selected realm changed')
if time.monotonic()>world_deadline:raise TimeoutError('Manual world-entry wait expired; no policy action')
report.update(world_wait_seconds=round(time.monotonic()-world_started,3),world_wait_polls=polls)
# A pending observation never relaxes the established activation guard.
initial=snapshot(c,pid,profile)
if initial['identity']!=identity:raise ValueError('Authenticated account or selected realm changed')
deadline=time.monotonic()+timeout;activation_deadline=None;requested=False;instructed=False;current=initial
while True:
if current['identity']!=identity:raise ValueError('Authenticated account or selected realm changed')
report.update(contracts_ready=current['contracts_ready'],
realm={key:current['realm'][key] for key in ('index','name','address','type','flags','population') if key in current['realm']},
code_contracts=[{key:row[key] for key in ('address','readable','executable','prefix_matches')} for row in current['policy']['code_contracts']])
if current['policy']['enabled']:
report.update(phase='existing-native-channel-policy-ready',reused=not requested,
policy_enabled=True,policy_owner_matches=True,policy_error=0)
return 0
if not requested and time.monotonic()>=deadline:raise TimeoutError('Original contract observation expired; no policy action')
if requested:
if time.monotonic()>=activation_deadline:raise TimeoutError('Existing policy activation did not complete')
elif current['contracts_ready']:
# Re-read every account/profile/world/owner guard after the ready
# contract observation; never use its earlier session snapshot.
current=snapshot(c,pid,profile)
if current['identity']!=identity:raise ValueError('Authenticated account or selected realm changed')
if current['policy']['enabled']:continue
if current['contracts_ready']:
if time.monotonic()>=deadline:raise TimeoutError('Original contract observation expired; no policy action')
report['phase']='enable-existing-native-channel-policy'
c.action('enable-native-channel-policy');requested=True
report['enable_action_requested']=True
activation_deadline=time.monotonic()+5
else:
report['phase']='awaiting-natural-original-code'
if not instructed:
print('Original channel contracts are cold. Use ordinary controls yourself in the already loaded game, if desired, to let the original engine execute naturally. This helper sends no input or chat and will stop after the bounded observation window.',flush=True)
instructed=True
if not requested and time.monotonic()>=deadline:raise TimeoutError('Original contracts remained cold; no policy action')
time.sleep(.2)
current=snapshot(c,pid,profile,pending=requested)
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--endpoint-profile',choices=PROFILES,default='octo')
parser.add_argument('--timeout',type=float,default=30,help='Natural-code observation bound,1..30seconds')
parser.add_argument('--wait-world',type=float,default=0,help='Optionally wait0..120seconds for manual world entry; default requires an existing world')
parser.add_argument('--output',type=Path,default=ROOT/'runtime'/('native-manual-gameplay-ready-'+str(time.time_ns())+'.json'))
args=parser.parse_args()
if not 1<=args.timeout<=30:parser.error('Timeout must be1..30seconds')
if not 0<=args.wait_world<=120:parser.error('World wait must be0..120seconds')
output=args.output.resolve()
if not output.is_relative_to(ROOT/'runtime') or output.exists() or not output.parent.is_dir():
parser.error('Require a new runtime output file in an existing directory')
os.umask(0o077);started=time.monotonic()
report=dict(kind='manual-existing-native-channel-policy-support',enable_action_requested=False,
policy_enabled=False,credential_input_automated=False,gameplay_input_automated=False,
screenshots_captured=False,native_acceptance_verified=False)
try:status=run(args.endpoint_profile,args.timeout,report,wait_world=args.wait_world)
except Exception as error:
# Never export potentially private RPC exceptions or touch a failed
# session. No disable/reset, reconnect, or gameplay retry is attempted.
report.update(stopped_safely=True,failure_type=type(error).__name__);status=2
report['elapsed_seconds']=round(time.monotonic()-started,3)
with output.open('x') as stream:json.dump(report,stream,indent=2);stream.write('\n')
print(json.dumps(dict(output=str(output),phase=report.get('phase'),endpoint_profile=args.endpoint_profile,
policy_enabled=report['policy_enabled'],reused=report.get('reused'),
native_acceptance_verified=False,failure_type=report.get('failure_type')),indent=2),flush=True)
return status
if __name__=='__main__':raise SystemExit(main())