Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ucode/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import os
import shutil
import signal
import subprocess
import sys
Expand All @@ -25,7 +26,9 @@ def exec_or_spawn(argv: list[str]) -> None:
os.execvp(argv[0], argv)
return # unreachable on POSIX; keeps type-checkers happy

proc = subprocess.Popen(argv)
# Resolve npm .cmd shims because CreateProcess does not honor PATHEXT.
executable = shutil.which(argv[0]) or argv[0]
proc = subprocess.Popen([executable, *argv[1:]])
try:
returncode = proc.wait()
except KeyboardInterrupt:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_windows_spawns_and_waits(self):
with (
patch.object(launcher.os, "name", "nt"),
patch.object(launcher.os, "execvp") as execvp,
patch.object(launcher.shutil, "which", return_value=None),
patch.object(launcher.subprocess, "Popen", return_value=proc) as popen,
):
with pytest.raises(SystemExit) as exc:
Expand All @@ -38,11 +39,27 @@ def test_windows_spawns_and_waits(self):
proc.wait.assert_called_once()
assert exc.value.code == 0

def test_windows_resolves_npm_command_shim(self):
proc = MagicMock()
proc.wait.return_value = 0
resolved = r"C:\npm\claude.CMD"
with (
patch.object(launcher.os, "name", "nt"),
patch.object(launcher.shutil, "which", return_value=resolved) as which,
patch.object(launcher.subprocess, "Popen", return_value=proc) as popen,
):
with pytest.raises(SystemExit) as exc:
launcher.exec_or_spawn(["claude", "--settings", "x"])
which.assert_called_once_with("claude")
popen.assert_called_once_with([resolved, "--settings", "x"])
assert exc.value.code == 0

def test_windows_propagates_child_exit_code(self):
proc = MagicMock()
proc.wait.return_value = 42
with (
patch.object(launcher.os, "name", "nt"),
patch.object(launcher.shutil, "which", return_value=None),
patch.object(launcher.subprocess, "Popen", return_value=proc),
):
with pytest.raises(SystemExit) as exc:
Expand All @@ -55,6 +72,7 @@ def test_windows_keyboard_interrupt_forwards_sigint(self):
proc.wait.side_effect = [KeyboardInterrupt(), 130]
with (
patch.object(launcher.os, "name", "nt"),
patch.object(launcher.shutil, "which", return_value=None),
patch.object(launcher.subprocess, "Popen", return_value=proc),
):
with pytest.raises(SystemExit) as exc:
Expand Down