Files
WoW-Hybrid-gateway/tests/native_world_gameplay_readiness_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

46 lines
2.6 KiB
Python

"""An armed route is asynchronous; do not replay it or authorize input early."""
import sys,unittest
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
from native_world_entry_test import enable_gameplay
class Controller:
def __init__(self,policies,timeout=8):self.policies=iter(policies);self.calls=[];self.timeout=timeout
def rpc(self,op):
self.calls.append(op)
return next(self.policies)if op=='inspect-native-channel-policy'else'queue-observation-armed'
def wait(self,ready,timeout):
assert timeout==self.timeout
for _ in range(3):
value=ready()
if value:return value
raise RuntimeError('Bounded wait expired')
class GameplayReadiness(unittest.TestCase):
def policy(self,enabled,owner=False,error=0):return dict(enabled=enabled,owner_matches=owner,error=error)
def test_async_arm_is_once_and_awaits_actual_owner(self):
c=Controller([self.policy(False),self.policy(False),self.policy(True),self.policy(True,True)])
r=enable_gameplay(c);self.assertTrue(r['armed_once']);self.assertTrue(r['policy']['owner_matches']);self.assertEqual(c.calls.count('request-native-channel-policy'),1)
def test_reuses_existing_enabled_route_without_rearm(self):
c=Controller([self.policy(True,True)]*2);self.assertFalse(enable_gameplay(c)['armed_once']);self.assertNotIn('request-native-channel-policy',c.calls)
def test_failed_existing_route_rejects_before_arm(self):
c=Controller([self.policy(False,error=1)])
with self.assertRaises(RuntimeError):enable_gameplay(c)
self.assertEqual(len(c.calls),1)
def test_failure_during_arm_is_not_retried(self):
c=Controller([self.policy(False),self.policy(False,error=1)])
with self.assertRaises(RuntimeError):enable_gameplay(c)
self.assertEqual(c.calls.count('request-native-channel-policy'),1)
def test_enabled_without_matching_owner_does_not_authorize_input(self):
c=Controller([self.policy(True)]*4)
with self.assertRaises(RuntimeError):enable_gameplay(c)
self.assertNotIn('request-native-channel-policy',c.calls)
def test_launcher_can_await_loading_safepoint_without_republishing(self):
c=Controller([self.policy(False),self.policy(False),self.policy(True),self.policy(True,True)],timeout=90)
self.assertTrue(enable_gameplay(c,timeout=90)['policy']['owner_matches'])
self.assertEqual(c.calls.count('request-native-channel-policy'),1)
def test_bad_deadline_never_touches_route(self):
for value in (True,0,121,float('nan')):
c=Controller([])
with self.assertRaises(ValueError):enable_gameplay(c,timeout=value)
self.assertEqual(c.calls,[])
if __name__=='__main__':unittest.main()