883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
40 lines
3.4 KiB
Python
40 lines
3.4 KiB
Python
"""Early read-only registration is current-child scoped, independent of input readiness."""
|
|
import ast,json,sys,tempfile,types,unittest
|
|
from pathlib import Path
|
|
from unittest.mock import Mock,patch
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
class EarlyRegistrationTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup);self.root=Path(self.tmp.name)
|
|
tree=ast.parse((ROOT/'ops/debug_client_owner.py').read_text())
|
|
node=next(n for n in tree.body if isinstance(n,ast.FunctionDef)and n.name=='start_early_spellbook_registration')
|
|
scope={'ROOT':self.root};exec(compile(ast.Module(body=[node],type_ignores=[]),'<existing-owner-early-stage>','exec'),scope);self.start=scope[node.name]
|
|
self.identity={'native_pid':7007,'native_starttime':1234,'owner_pid':4321,'owner_starttime':9876,'launch_id':'a'*32,'launch_monotonic_ns':10}
|
|
self.read_launch=Mock(return_value=dict(self.identity));self.factory=Mock(return_value=types.SimpleNamespace())
|
|
self.policy=Mock(side_effect=AssertionError('read-only initial observation must not require gameplay'))
|
|
self.modules=patch.dict(sys.modules,{'native_client_lifecycle':types.SimpleNamespace(read_launch=self.read_launch),'native_registration_trace':types.SimpleNamespace(RegistrationTrace=self.factory),'engine_channel_policy_host':types.SimpleNamespace(inspect=self.policy)})
|
|
self.modules.start();self.addCleanup(self.modules.stop)
|
|
def call(self,**changes):
|
|
args=dict(clean_copy=True,poll_host=True,native_roster=True,lifecycle_identity=dict(self.identity));args.update(changes)
|
|
return self.start(7007,**args)
|
|
def test_initial_owned_child_uses_exact_filter_and_current_launch_result(self):
|
|
observer,report=self.call()
|
|
self.assertIs(observer,self.factory.return_value);self.assertEqual(observer.owned_lifetime,self.identity)
|
|
self.factory.assert_called_once_with(7007,exact_spellbook_tooltip=True,owned_image_path=self.root/'runtime/native-client/_classic_beta_/WowB.exe',result_path=self.root/'runtime'/('native-registration-spellbook-'+'a'*32+'.json'))
|
|
self.assertEqual(report['status'],'started-not-yet-armed');self.assertEqual(report['native_starttime'],1234)
|
|
self.assertFalse(report['credentials_submitted']);self.assertFalse(report['code_bytes_modified']);self.policy.assert_not_called()
|
|
def test_nonmanaged_modes_never_reach_current_child_or_observer(self):
|
|
for field in ['clean_copy','poll_host']:
|
|
with self.subTest(field=field),self.assertRaises(RuntimeError):self.call(**{field:False})
|
|
self.read_launch.assert_not_called();self.factory.assert_not_called()
|
|
def test_missing_or_replaced_lifetime_cannot_observe(self):
|
|
for current in [None,{**self.identity,'native_starttime':1235},{**self.identity,'launch_id':'b'*32}]:
|
|
self.read_launch.return_value=current
|
|
with self.subTest(current=current),self.assertRaises(RuntimeError):self.call()
|
|
self.factory.assert_not_called();self.policy.assert_not_called()
|
|
def test_lifetime_result_paths_cannot_reuse_an_old_launch(self):
|
|
first=self.call()[1]['result'];self.identity={**self.identity,'launch_id':'c'*32};self.read_launch.return_value=dict(self.identity)
|
|
second=self.call()[1]['result'];self.assertNotEqual(first,second)
|
|
self.assertEqual(self.factory.call_count,2)
|
|
if __name__=='__main__':unittest.main()
|