feat(debug): enable Python debug workflow and debug server integration

Adds an end-to-end Python debug workflow for the extension.
Includes a new prepare-debug.ps1 script and a VS Code task.
Extends the Python server and extension to coordinate a debug session and safe startup.

- Add prepare-debug.ps1 and a VS Code task to build the debug bundle
- Enable Python debug wiring in the server and tests
- Ensure a single stable Python debug session during startup
This commit is contained in:
Christoph Brandau
2026-08-17 11:02:22 +02:00
parent 35a4357551
commit 33cf282b0a
14 changed files with 349 additions and 73 deletions
@@ -0,0 +1,53 @@
import sys
from pathlib import Path
import pytest
THIS_DIR = Path(__file__).parent
SRC_DIR = THIS_DIR.parent.parent / "src"
if str(SRC_DIR) not in sys.path:
sys.path.insert(0, str(SRC_DIR))
import _debug_server
def test_debug_endpoint_defaults(monkeypatch):
monkeypatch.delenv("NXPS_DEBUG_HOST", raising=False)
monkeypatch.delenv("NXPS_DEBUG_PORT", raising=False)
assert _debug_server._debug_endpoint() == ("127.0.0.1", 5678)
@pytest.mark.parametrize("port", ["invalid", "0", "65536"])
def test_debug_endpoint_rejects_invalid_port(monkeypatch, port):
monkeypatch.setenv("NXPS_DEBUG_PORT", port)
with pytest.raises(RuntimeError):
_debug_server._debug_endpoint()
def test_connect_debugger_retries_until_adapter_is_ready(monkeypatch):
class FakeDebugpy:
def __init__(self):
self.connect_calls = 0
self.wait_calls = 0
def connect(self, endpoint):
assert endpoint == ("127.0.0.1", 5678)
self.connect_calls += 1
if self.connect_calls < 3:
raise ConnectionRefusedError("listener is starting")
def wait_for_client(self):
self.wait_calls += 1
fake_debugpy = FakeDebugpy()
monkeypatch.setattr(_debug_server.time, "sleep", lambda _seconds: None)
_debug_server._connect_debugger(
fake_debugpy, "127.0.0.1", 5678, timeout=1.0
)
assert fake_debugpy.connect_calls == 3
assert fake_debugpy.wait_calls == 1