367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
82 lines
5.3 KiB
Python
82 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""One legitimate local GM revive/death for the journaled rank0 Praxiscopy fixture.
|
|
|
|
Test setup only. Never a player-recovery/Forever compatibility acceptance claim.
|
|
No database writes, new privileges, arbitrary commands, credential exports or
|
|
public endpoints. The server still validates the existing GM's permissions.
|
|
"""
|
|
import argparse
|
|
import datetime
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
from local_tortoise import db,private
|
|
from native_engine_character_test import ROOT,Controller,local_listeners
|
|
from native_test_guard import (require_authenticated_turtle_realm,
|
|
require_native_gameplay_policy,require_local_turtle_ports,require_solo_test_character)
|
|
from native_world_trace import WorldTrace
|
|
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--executable',type=Path,default=ROOT/'build/local-fixture-recovery')
|
|
parser.add_argument('--evidence',type=Path,required=True)
|
|
parser.add_argument('--action',choices=('revive','die'),default='revive')
|
|
parser.add_argument('--allow-archived-praxiscopy-4518-fixture',action='store_true',
|
|
help='Explicit developer-only opt-in for the archived fixed4518 fixture; never current user characters')
|
|
args=parser.parse_args()
|
|
if not args.allow_archived_praxiscopy_4518_fixture:
|
|
parser.error('Archived mutation fixture disabled; require --allow-archived-praxiscopy-4518-fixture and the exact historical actor guards')
|
|
out=args.evidence.resolve();exe=args.executable.resolve()
|
|
if not out.is_relative_to(ROOT/'runtime') or out.exists() or not exe.is_relative_to(ROOT/'build') or not exe.is_file():
|
|
parser.error('Require a built local fixture tool and new runtime evidence path')
|
|
os.umask(0o077);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(4518,db('SELECT guid FROM tw_char.characters WHERE online<>0 ORDER BY guid;'))
|
|
admin=int(db('SELECT account FROM tw_char.characters WHERE guid=4509;'))
|
|
target=int(db("SELECT account FROM tw_char.characters WHERE guid=4518 AND name='Praxiscopy';"))
|
|
if admin==target or db(f'SELECT `rank`,active FROM tw_logon.account WHERE id={admin};')!='4\t1' or db(f'SELECT `rank` FROM tw_logon.account WHERE id={target};')!='0':
|
|
raise RuntimeError('Existing authorized fixture-account/ordinary-target contract differs')
|
|
matches=[]
|
|
for path in (ROOT/'secrets').glob('*/account.json'):
|
|
account=json.loads(path.read_text())
|
|
if account.get('account_id')==admin:matches.append((path.parent.resolve(),account))
|
|
if len(matches)!=1 or not matches[0][0].is_relative_to(ROOT/'secrets'):
|
|
raise RuntimeError('Ambiguous private fixture inputs; nothing sent')
|
|
directory,account=matches[0]
|
|
recovery=ROOT/'recovery'/('authorized-revive-fixture-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))
|
|
recovery.mkdir(mode=0o700)
|
|
report=dict(kind='authorized-local-recovery-fixture-only',action=args.action,target=4518,admin_actor=4509,
|
|
target_rank=0,original_gm_rank=4,completed=False,
|
|
before_saved=db('SELECT guid,health,playerFlags,extra_flags FROM tw_char.characters WHERE guid IN(4509,4518) ORDER BY guid;'))
|
|
private(recovery/'baseline.json',json.dumps(report,indent=2).encode())
|
|
trace=WorldTrace(c)
|
|
try:
|
|
with trace:
|
|
child=subprocess.run([str(exe),str(directory),args.action,'--allow-archived-praxiscopy-4518-fixture'],input=account['username']+'\n',
|
|
capture_output=True,text=True,timeout=65)
|
|
allowed={'SERVER_GM_READ_PERMISSION_VERIFIED','REVIVE_REQUESTED_ONCE','SERVER_REVIVE_REPLY','CONTROLLED_DEATH_REQUESTED_ONCE','FIXTURE_LOGOUT_REJECTED_COMBAT','SERVER_FIXTURE_COMBAT_CLEARED','FIXTURE_LOGGED_OUT'}
|
|
events=child.stdout.splitlines()
|
|
if not all(line in allowed for line in events):raise RuntimeError('Unexpected fixture output withheld')
|
|
report.update(returncode=child.returncode,events=events,completed=child.returncode==0)
|
|
if child.returncode:raise RuntimeError('Fixture stopped; inspect target/peer state before retry, private details withheld')
|
|
finally:
|
|
report.update(trace.report())
|
|
report['after_saved']=db('SELECT guid,health,playerFlags,extra_flags FROM tw_char.characters WHERE guid IN(4509,4518) ORDER BY guid;')
|
|
report['target_rank_after']=db(f'SELECT `rank` FROM tw_logon.account WHERE id={target};')
|
|
report['corpse_saved']=db('SELECT guid,corpse_type FROM tw_char.corpse WHERE player=4518;')
|
|
report['admin_saved_offline']=db('SELECT online FROM tw_char.characters WHERE guid=4509;')=='0'
|
|
report['pipe_error']=c.rpc('inspect-engine-pipe').get('error')
|
|
report['recovery']=str(recovery.relative_to(ROOT))
|
|
(recovery/'baseline.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
out.parent.mkdir(parents=True,exist_ok=True);out.write_text(json.dumps(report,indent=2)+'\n');out.chmod(0o600)
|
|
print(json.dumps({k:report[k]for k in ('completed','events','target_rank_after','corpse_saved','admin_saved_offline','pipe_error')}))
|
|
return 0
|
|
|
|
|
|
if __name__=='__main__':raise SystemExit(main())
|