@@ -80,6 +80,16 @@ def test_doctor_checks_disk_space(self):
8080 )
8181 assert "PASS: Disk space" in result .stderr
8282
83+ def test_doctor_checks_build_venv_support (self ):
84+ """Doctor reports whether build-index can create Sphinx venvs."""
85+ result = subprocess .run (
86+ [sys .executable , "-m" , "mcp_server_python_docs" , "doctor" ],
87+ capture_output = True ,
88+ text = True ,
89+ timeout = 15 ,
90+ )
91+ assert "Build venv support" in result .stderr
92+
8393 def test_doctor_reports_missing_index (self ):
8494 """Doctor reports FAIL for Index database when pointed at empty dir."""
8595 with tempfile .TemporaryDirectory () as tmpdir :
@@ -115,3 +125,54 @@ def test_doctor_in_help(self):
115125 )
116126 combined = result .stdout + result .stderr
117127 assert "doctor" in combined
128+
129+
130+ class TestBuildVenvSupportProbe :
131+ """Verify the build-index venv prerequisite probe."""
132+
133+ def test_probe_reports_missing_ensurepip_with_platform_package_hint (self , monkeypatch ):
134+ """Missing ensurepip points users to the versioned Debian/Ubuntu venv package."""
135+
136+ def fake_run (* args , ** kwargs ):
137+ return subprocess .CompletedProcess (
138+ args = args [0 ],
139+ returncode = 1 ,
140+ stdout = "" ,
141+ stderr = "ModuleNotFoundError: No module named 'ensurepip'" ,
142+ )
143+
144+ monkeypatch .setattr (subprocess , "run" , fake_run )
145+
146+ from mcp_server_python_docs .diagnostics import check_build_venv_support
147+
148+ result = check_build_venv_support ()
149+
150+ assert result .passed is False
151+ assert "ensurepip" in result .detail
152+ assert (
153+ f"python{ sys .version_info .major } .{ sys .version_info .minor } -venv"
154+ in result .detail
155+ )
156+
157+ def test_probe_passes_when_venv_and_ensurepip_are_importable (self , monkeypatch ):
158+ """Available venv and ensurepip support passes the build prerequisite probe."""
159+
160+ def fake_run (* args , ** kwargs ):
161+ command = args [0 ]
162+ assert "ensurepip" in command [- 1 ]
163+ assert "venv" in command [- 1 ]
164+ return subprocess .CompletedProcess (
165+ args = command ,
166+ returncode = 0 ,
167+ stdout = "" ,
168+ stderr = "" ,
169+ )
170+
171+ monkeypatch .setattr (subprocess , "run" , fake_run )
172+
173+ from mcp_server_python_docs .diagnostics import check_build_venv_support
174+
175+ result = check_build_venv_support ()
176+
177+ assert result .passed is True
178+ assert "build-index" in result .detail
0 commit comments