Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

fix(doctor): fall through a python3 that cannot report its version (#201)

Leo Camus3a1a7e09e89d
diff --git a/scripts/test-verify-doctor.py b/scripts/test-verify-doctor.py
index 4591fe4..27c9e17 100644
--- a/scripts/test-verify-doctor.py
+++ b/scripts/test-verify-doctor.py
@@ -40,6 +40,27 @@ def seed_repo(module, root: Path) -> None:
touch(root / relative, f"Routes to {reference}.\n")
+class FakeCompletedProcess:
+ """Just enough of subprocess.CompletedProcess for the probe to read."""
+
+ def __init__(self, returncode: int, stdout: str = "", stderr: str = "") -> None:
+ self.returncode = returncode
+ self.stdout = stdout
+ self.stderr = stderr
+
+
+def fake_python_path(module, resolved: dict[str, str], responses: dict[str, object]):
+ """Pretend PATH resolves `resolved` and each interpreter answers `responses`."""
+ real_which, real_run = module.shutil.which, module.run_command
+ module.shutil.which = lambda name: resolved.get(name)
+ module.run_command = lambda command: responses[command[0]]
+ try:
+ yield
+ finally:
+ module.shutil.which, module.run_command = real_which, real_run
+
+
def expect_status(check, status: str, needle: str) -> None:
if check.status != status or needle not in check.message:
raise AssertionError(
@@ -98,6 +119,88 @@ def main() -> int:
)
print("OK: installed skill in an arbitrary user project does not require maintainer files")
+ # A name on PATH is not an interpreter. Windows ships a `python3` App
+ # Execution Alias that exits non-zero with a Microsoft Store prompt, so
+ # the probe has to fall through to `python` rather than report that a
+ # perfectly healthy machine has no usable Python.
+ alias_path = r"C:\Users\dev\AppData\Local\Microsoft\WindowsApps\python3.exe"
+ real_path = r"C:\Program Files\Python312\python.exe"
+ store_alias = FakeCompletedProcess(
+ 9009,
+ stderr=(
+ "Python was not found; run without arguments to install from the "
+ "Microsoft Store, or disable this shortcut from Settings"
+ ),
+ )
+ working_python = FakeCompletedProcess(0, stdout="3.12.9\n")
+
+ with fake_python_path(
+ verify,
+ {"python3": alias_path, "python": real_path},
+ {"python3": store_alias, "python": working_python},
+ ):
+ check, python_cmd = verify.check_python_runtime()
+ expect_status(check, verify.PASS, "Python 3.12.9 found via python")
+ if python_cmd != "python":
+ raise AssertionError(f"expected downstream checks to use python, got {python_cmd!r}")
+ probe = verify.probe_python_command()
+ if (probe.command, probe.version) != ("python", "3.12.9"):
+ raise AssertionError(f"probe did not fall through a non-running python3: {probe}")
+ print("OK: a python3 that cannot report its version falls through to python")
+
+ # When nothing on PATH runs, the failure still names the first candidate
+ # tried and carries that interpreter's own stderr.
+ with fake_python_path(
+ verify,
+ {"python3": alias_path, "python": alias_path},
+ {"python3": store_alias, "python": store_alias},
+ ):
+ check, python_cmd = verify.check_python_runtime()
+ expect_status(check, verify.FAIL, "Could not query version via python3")
+ if "Microsoft Store" not in check.message:
+ raise AssertionError("probe failure dropped the interpreter's own stderr")
+ # That FAIL still hands a command name downstream, so the Playwright
+ # check runs against an interpreter already known not to answer.
+ expect_status(
+ verify.check_playwright(python_cmd),
+ verify.WARN,
+ "Playwright package is not available",
+ )
+ print("OK: no runnable interpreter still fails, naming the first candidate")
+
+ # Some names on PATH cannot be launched at all rather than exiting
+ # non-zero. A directory stands in for the broken alias or dangling
+ # symlink: spawning it raises OSError on every platform we support.
+ launch_failure = verify.run_command([str(root), "-c", verify.VERSION_PROBE])
+ if launch_failure.returncode == 0 or not launch_failure.stderr:
+ raise AssertionError(
+ f"unlaunchable command did not report a failure: {launch_failure}"
+ )
+ print("OK: a command that cannot be launched is reported, not raised")
+
+ # And that reported shape has to fall through like any other dud, or the
+ # doctor dies on the candidate this fallback exists to survive.
+ with fake_python_path(
+ verify,
+ {"python3": alias_path, "python": real_path},
+ {
+ "python3": FakeCompletedProcess(1, stderr=str(launch_failure.stderr)),
+ "python": working_python,
+ },
+ ):
+ probe = verify.probe_python_command()
+ if (probe.command, probe.version) != ("python", "3.12.9"):
+ raise AssertionError(f"a python3 that cannot be launched did not fall through: {probe}")
+ print("OK: a python3 that cannot be launched falls through to python")
+
+ # No interpreter on PATH at all remains a hard failure.
+ with fake_python_path(verify, {}, {}):
+ check, python_cmd = verify.check_python_runtime()
+ expect_status(check, verify.FAIL, "No python3 or python command was found")
+ if python_cmd is not None:
+ raise AssertionError(f"expected no python command, got {python_cmd!r}")
+ print("OK: an empty PATH fails without naming a command")
+
summary_checks = [
verify.CheckResult("a", verify.PASS, "ok"),
verify.CheckResult("b", verify.WARN, "warn", "fix warn"),
diff --git a/scripts/verify-doctor.py b/scripts/verify-doctor.py
index 301949f..a839bae 100644
--- a/scripts/verify-doctor.py
+++ b/scripts/verify-doctor.py
@@ -50,6 +50,8 @@ ROUTING_SURFACES = {
Path("prompts/doctor.md"): "references/doctor.md",
}
+VERSION_PROBE = "import sys; print('.'.join(str(p) for p in sys.version_info[:3]))"
+
PASS = "pass"
WARN = "warn"
FAIL = "fail"
@@ -64,27 +66,69 @@ class CheckResult:
def run_command(command: list[str]) -> subprocess.CompletedProcess[str]:
- return subprocess.run(
- command,
- capture_output=True,
- text=True,
- encoding="utf-8",
- errors="replace",
- check=False,
- )
+ """Run a command, reporting a failure to launch the way a bad exit is reported.
+
+ A name on PATH is not always a runnable program: an App Execution Alias for
+ an uninstalled app, a dangling symlink, or a file without the exec bit raise
+ instead of exiting. Every caller here only asks whether the command answered,
+ so surface that as a non-zero result carrying the OS error rather than letting
+ it unwind the whole doctor.
+ """
+ try:
+ return subprocess.run(
+ command,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ check=False,
+ )
+ except OSError as exc:
+ return subprocess.CompletedProcess(command, 1, "", str(exc))
-def probe_python_command() -> tuple[str | None, str | None]:
- """Resolve python3 first, then python."""
+@dataclass
+class PythonProbe:
+ """What resolving an interpreter name actually turned up."""
+
+ command: str | None = None
+ executable: str | None = None
+ version: str | None = None
+ error: str | None = None
+
+
+def probe_python_command() -> PythonProbe:
+ """Resolve python3 first, then python, preferring a name that actually runs.
+
+ Presence on PATH is not evidence of an interpreter. On Windows the
+ ``python3`` App Execution Alias ships on PATH by default and exits
+ non-zero with a Microsoft Store prompt, so a machine with a working
+ ``python`` is otherwise reported as having no usable Python at all. Fall
+ through to the next candidate when the preferred name cannot report its
+ own version, and keep the first name found so a total failure still says
+ what was tried.
+ """
+ fallback = PythonProbe()
for candidate in ("python3", "python"):
executable = shutil.which(candidate)
- if executable:
- return candidate, executable
- return None, None
+ if executable is None:
+ continue
+ probe = run_command([candidate, "-c", VERSION_PROBE])
+ version = probe.stdout.strip()
+ if probe.returncode == 0 and version:
+ return PythonProbe(command=candidate, executable=executable, version=version)
+ if fallback.command is None:
+ fallback = PythonProbe(
+ command=candidate,
+ executable=executable,
+ error=probe.stderr.strip() or "version probe failed",
+ )
+ return fallback
def check_python_runtime() -> tuple[CheckResult, str | None]:
- command_name, executable = probe_python_command()
+ probe = probe_python_command()
+ command_name, executable = probe.command, probe.executable
if command_name is None or executable is None:
return (
CheckResult(
@@ -96,11 +140,8 @@ def check_python_runtime() -> tuple[CheckResult, str | None]:
None,
)
- version_probe = run_command(
- [command_name, "-c", "import sys; print('.'.join(str(p) for p in sys.version_info[:3]))"]
- )
- if version_probe.returncode != 0:
- detail = version_probe.stderr.strip() or "version probe failed"
+ if probe.version is None:
+ detail = probe.error or "version probe failed"
return (
CheckResult(
name="Python runtime",
@@ -111,7 +152,7 @@ def check_python_runtime() -> tuple[CheckResult, str | None]:
command_name,
)
- version_text = version_probe.stdout.strip()
+ version_text = probe.version
try:
major, minor, patch = (int(part) for part in version_text.split(".", 2))
except ValueError:
diff --git a/skills/diagram-design/references/doctor.md b/skills/diagram-design/references/doctor.md
index 73714b2..86e9e8e 100644
--- a/skills/diagram-design/references/doctor.md
+++ b/skills/diagram-design/references/doctor.md
@@ -30,7 +30,12 @@ If no flags are provided, run in standard mode.
Run all checks in this order and report each as `pass`, `warn`, or `fail`.
1. Python runtime
-- Resolve `python3` first, then `python`.
+- Resolve `python3` first, then `python`. A name that is on PATH but cannot report
+ its own version does not win the resolution: fall through to the next candidate.
+ (Windows ships a `python3` App Execution Alias that is a Microsoft Store stub, not
+ an interpreter, and it sits on PATH ahead of a python.org install.) A name that
+ cannot be launched at all counts as the same kind of dud, and is reported as a
+ failed check rather than ending the run.
- Require version >= 3.10.
- `fail` if no Python interpreter is found.
- `fail` if version is below 3.10.