test_executable_line_validation.py•3.81 kB
"""
Manual test to verify executable line validation.
This script tests the new feature that prevents setting breakpoints
on non-executable lines (blank lines, comments, etc.).
"""
from pathlib import Path
import sys
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from mcp_debug_tool.sessions import SessionManager
from mcp_debug_tool.schemas import StartSessionRequest, BreakpointRequest
def main():
workspace = Path(__file__).parent.parent
manager = SessionManager(workspace)
print("=" * 60)
print("Testing Executable Line Validation")
print("=" * 60)
# Create session
print("\n1. Creating debug session...")
request = StartSessionRequest(entry="manual_test/manual_test_code.py", pythonPath=sys.executable)
response = manager.create_session(request)
session_id = response.sessionId
print(f" ✓ Session created: {session_id}")
# Test 1: Try setting breakpoint on blank line (line 16)
print("\n2. Testing breakpoint on BLANK line (line 16)...")
try:
breakpoint_request = BreakpointRequest(
file="manual_test/manual_test_code.py",
line=16
)
response = manager.run_to_breakpoint(session_id, breakpoint_request)
print(f" ✗ Should have failed but got: {response}")
except ValueError as e:
print(f" ✓ Correctly rejected: {e}")
# Test 2: Try setting breakpoint on comment line (line 17)
print("\n3. Testing breakpoint on COMMENT line (line 17)...")
try:
breakpoint_request = BreakpointRequest(
file="manual_test/manual_test_code.py",
line=17
)
response = manager.run_to_breakpoint(session_id, breakpoint_request)
print(f" ✗ Should have failed but got: {response}")
except ValueError as e:
print(f" ✓ Correctly rejected: {e}")
# Test 3: Set breakpoint on executable line (line 15 - for loop)
print("\n4. Testing breakpoint on EXECUTABLE line (line 15 - for loop)...")
try:
breakpoint_request = BreakpointRequest(
file="manual_test/manual_test_code.py",
line=15
)
response = manager.run_to_breakpoint(session_id, breakpoint_request)
if response.hit:
print(f" ✓ Breakpoint hit successfully!")
print(f" ✓ Locals captured: {list(response.locals.keys())}")
else:
print(f" ? Breakpoint not hit: {response}")
except Exception as e:
print(f" ✗ Unexpected error: {e}")
# Test 4: Set breakpoint on another executable line (line 19 - addition assignment)
print("\n5. Testing breakpoint on EXECUTABLE line (line 19 - addition)...")
try:
# Create new session
request2 = StartSessionRequest(entry="manual_test/manual_test_code.py", pythonPath=sys.executable)
response2 = manager.create_session(request2)
session_id2 = response2.sessionId
breakpoint_request = BreakpointRequest(
file="manual_test/manual_test_code.py",
line=19
)
response = manager.run_to_breakpoint(session_id2, breakpoint_request)
if response.hit:
print(f" ✓ Breakpoint hit successfully!")
print(f" ✓ Locals captured: {list(response.locals.keys())}")
else:
print(f" ? Breakpoint not hit: {response}")
manager.end_session(session_id2)
except Exception as e:
print(f" ✗ Unexpected error: {e}")
# Cleanup
print("\n6. Cleaning up...")
manager.end_session(session_id)
print(" ✓ Session ended")
print("\n" + "=" * 60)
print("Test complete!")
print("=" * 60)
if __name__ == "__main__":
main()