Support bounded machine instruction step counts in MCP

This commit is contained in:
Александр Петров
2026-09-17 23:22:37 +03:00
parent e8189b137a
commit 259c782190
13 changed files with 62 additions and 10 deletions
+19 -1
View File
@@ -111,13 +111,16 @@ class StepBridge:
def __init__(self, owner):
self.owner = owner
self.calls = []
self.step_counts = []
def close(self): pass
def request(self, command, **arguments):
self.calls.append(command)
if command in ('step', 'step_over', 'step_out'):
self.owner.index = min(self.owner.index + 1,
count = arguments.get('count', 1) if command == 'step' else 1
self.step_counts.append(count)
self.owner.index = min(self.owner.index + count,
len(self.owner.locations) - 1)
return {'accepted': True}
if command == 'snapshot':
@@ -482,6 +485,21 @@ class ServerTests(unittest.TestCase):
finally:
controller.close()
def test_instruction_step_count_is_bounded_and_forwarded(self):
session = StepSession()
controller = SessionController(session)
try:
with self.assertRaisesRegex(SessionError, '1..64'):
controller.call('step', {'count': 0, 'owner': 'mcp:test'})
for bad in (65, 1.5, True):
with self.assertRaisesRegex(SessionError, '1..64'):
controller.call('step', {'count': bad, 'owner': 'mcp:test'})
result = controller.call('step', {'count': 2, 'owner': 'mcp:test'})
self.assertEqual(result['sources'][0]['line'], 4)
self.assertEqual(session.bridge.step_counts, [2])
finally:
controller.close()
def test_source_step_preserves_user_breakpoint_on_same_line(self):
session = StepSession()
controller = SessionController(session)