Verify visible hello MCP run and add shared control lease
This commit is contained in:
@@ -28,6 +28,7 @@ class DummyBridge:
|
||||
if command == 'snapshot': return {'state': self.state}
|
||||
if command == 'console_print': return {'printed': True}
|
||||
if command == 'memory': return {'hex': '00' * arguments['length']}
|
||||
if command == 'key': return {'accepted': True}
|
||||
raise AssertionError(command)
|
||||
|
||||
|
||||
@@ -217,6 +218,64 @@ class ServerTests(unittest.TestCase):
|
||||
finally:
|
||||
controller.close()
|
||||
|
||||
def test_control_lease_blocks_other_client_and_can_be_released_or_expire(self):
|
||||
controller = SessionController(DummySession())
|
||||
try:
|
||||
first = controller.call('claim_control', {'owner': 'mcp:a'})
|
||||
self.assertEqual(first['owner'], 'mcp:a')
|
||||
self.assertEqual(controller.call('status', {})['control_owner'], 'mcp:a')
|
||||
with self.assertRaisesRegex(SessionError, 'mcp:a'):
|
||||
controller.call('claim_control', {'owner': 'mcp:b'})
|
||||
controller.call('renew_control', {'owner': 'mcp:a'})
|
||||
self.assertFalse(controller.call('renew_control', {'owner': 'mcp:b'})['has_control'])
|
||||
controller.call('release_control', {'owner': 'mcp:b'})
|
||||
self.assertEqual(controller.call('status', {})['control_owner'], 'mcp:a')
|
||||
controller.call('release_control', {'owner': 'mcp:a'})
|
||||
self.assertEqual(controller.call('claim_control', {'owner': 'mcp:b'})['owner'], 'mcp:b')
|
||||
controller.control_deadline = 0
|
||||
self.assertEqual(controller.call('claim_control', {'owner': 'cli'})['owner'], 'cli')
|
||||
self.assertFalse(controller.call('renew_control', {'owner': 'mcp:b'})['has_control'])
|
||||
finally:
|
||||
controller.close()
|
||||
|
||||
def test_expired_mcp_owner_clears_points_without_touching_dap_points(self):
|
||||
session = DummySession()
|
||||
controller = SessionController(session)
|
||||
try:
|
||||
mine = controller.call('break_line', {
|
||||
'file': '/src/main.c', 'line': 3, 'owner': 'mcp:lost'})
|
||||
dap = controller.call('break_function', {'name': 'main', 'owner': 'cli'})
|
||||
controller.call('claim_control', {'owner': 'mcp:lost'})
|
||||
controller.owner_deadlines['mcp:lost'] = 0
|
||||
with controller.lock:
|
||||
controller._reap_owners()
|
||||
self.assertIn(mine['id'], session.cleared)
|
||||
self.assertNotIn(dap['id'], session.cleared)
|
||||
self.assertIsNone(controller.call('status', {})['control_owner'])
|
||||
self.assertEqual(controller.events[-1]['event'], 'owner_expired')
|
||||
finally:
|
||||
controller.close()
|
||||
|
||||
def test_expired_owner_releases_held_key(self):
|
||||
session = DummySession()
|
||||
controller = SessionController(session)
|
||||
try:
|
||||
with controller.lock:
|
||||
controller.running = True
|
||||
session.bridge.state = 'running'
|
||||
controller.call('input_key', {
|
||||
'owner': 'mcp:lost', 'tag': ':kbd:ms_naturl',
|
||||
'mask': 0x400, 'down': True})
|
||||
self.assertIn(('key', {'tag': ':kbd:ms_naturl', 'mask': 0x400,
|
||||
'down': True}), session.bridge.calls)
|
||||
controller.owner_deadlines['mcp:lost'] = 0
|
||||
controller._reap_owners()
|
||||
self.assertIn(('key', {'tag': ':kbd:ms_naturl', 'mask': 0x400,
|
||||
'down': False}), session.bridge.calls)
|
||||
self.assertFalse(controller.held_inputs)
|
||||
finally:
|
||||
controller.close()
|
||||
|
||||
def test_read_memory_is_bounded_and_generation_tied(self):
|
||||
session = DummySession()
|
||||
controller = SessionController(session)
|
||||
|
||||
Reference in New Issue
Block a user