883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
88 lines
4.4 KiB
Python
88 lines
4.4 KiB
Python
import ast
|
|
import pathlib
|
|
import tempfile
|
|
import types
|
|
import unittest
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
|
ROOT=pathlib.Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class ExactRegionalOwnerTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temporary=tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.temporary.cleanup)
|
|
self.bundle=pathlib.Path(self.temporary.name)
|
|
tree=ast.parse((ROOT/'ops/debug_client_owner.py').read_text())
|
|
function=next(n for n in tree.body if isinstance(n,ast.FunctionDef) and n.name=='start_exact_regional_registration')
|
|
scope={'ROOT':self.bundle}
|
|
exec(compile(ast.Module(body=[function],type_ignores=[]),'<owned-registration-entry>','exec'),scope)
|
|
self.start=scope['start_exact_regional_registration']
|
|
self.policy={'enabled':True,'owner_matches':True,'error':0}
|
|
self.pipe={'closed':0,'error':0,'world_auth':1,'world':{'login_sent':1,'self_create':1}}
|
|
self.policy_read=Mock(side_effect=lambda pid:dict(self.policy))
|
|
self.pipe_read=Mock(side_effect=lambda pid:self.pipe)
|
|
self.factory=Mock(return_value=object())
|
|
guard_tree=ast.parse((ROOT/'ops/native_test_guard.py').read_text())
|
|
guard=next(n for n in guard_tree.body if isinstance(n,ast.FunctionDef) and n.name=='require_native_gameplay_policy')
|
|
guard_scope={}
|
|
exec(compile(ast.Module(body=[guard],type_ignores=[]),'<existing-gameplay-guard>','exec'),guard_scope)
|
|
modules={
|
|
'engine_channel_policy_host':types.SimpleNamespace(inspect=self.policy_read),
|
|
'engine_pipe_host':types.SimpleNamespace(inspect=self.pipe_read),
|
|
'native_test_guard':types.SimpleNamespace(require_native_gameplay_policy=guard_scope['require_native_gameplay_policy']),
|
|
'native_registration_trace':types.SimpleNamespace(RegistrationTrace=self.factory),
|
|
}
|
|
self.patches=patch.dict('sys.modules',modules)
|
|
self.patches.start()
|
|
self.addCleanup(self.patches.stop)
|
|
|
|
def call(self,**changes):
|
|
fields={'clean_copy':True,'poll_host':True,'probe':None}
|
|
fields.update(changes)
|
|
return self.start(7007,**fields)
|
|
|
|
def test_ready_world_uses_only_fixed_exact_observer(self):
|
|
observer,report=self.call()
|
|
self.assertIs(observer,self.factory.return_value)
|
|
self.factory.assert_called_once_with(7007,exact_regional_global=True,owned_image_path=self.bundle/'runtime/native-client/_classic_beta_/WowB.exe',result_path=self.bundle/'runtime/native-registration-regional-7007.json')
|
|
self.assertEqual(report['status'],'started-not-yet-armed')
|
|
self.assertFalse(report['credentials_submitted'])
|
|
self.assertFalse(report['code_bytes_modified'])
|
|
self.policy_read.assert_called_once_with(7007)
|
|
self.pipe_read.assert_called_once_with(7007)
|
|
|
|
def test_foreign_or_busy_host_never_reads_or_attaches(self):
|
|
cases=[{'clean_copy':False},{'poll_host':False},{'probe':types.SimpleNamespace(attached=True,done=False)},{'probe':types.SimpleNamespace(attached=False,done=False)}]
|
|
for fields in cases:
|
|
with self.subTest(fields=fields),self.assertRaises(RuntimeError):self.call(**fields)
|
|
self.policy_read.assert_not_called()
|
|
self.pipe_read.assert_not_called()
|
|
self.factory.assert_not_called()
|
|
|
|
def test_inactive_old_observer_can_be_replaced(self):
|
|
self.call(probe=types.SimpleNamespace(attached=False,done=True))
|
|
self.factory.assert_called_once()
|
|
|
|
def test_disabled_failed_or_foreign_policy_cannot_attach(self):
|
|
for fields in ({'enabled':False},{'error':1},{'owner_matches':False}):
|
|
original=dict(self.policy)
|
|
self.policy.update(fields)
|
|
with self.subTest(fields=fields),self.assertRaises(RuntimeError):self.call()
|
|
self.policy=original
|
|
self.pipe_read.assert_not_called()
|
|
self.factory.assert_not_called()
|
|
|
|
def test_world_teardown_or_missing_source_readiness_cannot_attach(self):
|
|
cases=[{'closed':1},{'error':1},{'world_auth':0},{'world':None},{'world':{}},{'world':{'login_sent':0,'self_create':1}},{'world':{'login_sent':1,'self_create':0}}]
|
|
for fields in cases:
|
|
original=self.pipe
|
|
self.pipe={**original,**fields}
|
|
with self.subTest(fields=fields),self.assertRaises(RuntimeError):self.call()
|
|
self.pipe=original
|
|
self.factory.assert_not_called()
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|