Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(distill): run a forward-slash program path through cmd.exe on Windows (#3918)

Raghav Chamadiya6ef0c52ce98b
diff --git a/packages/cli/src/repowise/cli/commands/distill_cmd.py b/packages/cli/src/repowise/cli/commands/distill_cmd.py
index 1157a2227..51c000095 100644
--- a/packages/cli/src/repowise/cli/commands/distill_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/distill_cmd.py
@@ -244,9 +244,11 @@ def _render_command(tokens: tuple[str, ...]) -> str:
)
exe = tokens[0]
- # Windows paths cannot contain `"`, so plain quoting is unambiguous.
+ # Windows paths cannot contain `"`, so plain quoting is unambiguous. A `/`
+ # is quoted too: unquoted, cmd reads `./.venv/Scripts/python.exe` (the
+ # spelling a Git Bash command arrives in) as the program `.` and a switch.
if '"' not in exe and (
- any(ch.isspace() for ch in exe) or any(ch in _CMD_METACHARS for ch in exe)
+ any(ch.isspace() for ch in exe) or any(ch in _CMD_METACHARS or ch == "/" for ch in exe)
):
head = f'"{exe}"'
else:
diff --git a/tests/unit/distill/test_cli.py b/tests/unit/distill/test_cli.py
index 67ec74bea..35339fbd4 100644
--- a/tests/unit/distill/test_cli.py
+++ b/tests/unit/distill/test_cli.py
@@ -200,6 +200,31 @@ def test_render_command_keeps_an_executable_path_with_spaces_intact(tmp_path: Pa
assert "SHIM_OK" in proc.stdout
[email protected](sys.platform != "win32", reason="cmd.exe program-name resolution")
+def test_render_command_runs_a_forward_slash_program_path(tmp_path: Path) -> None:
+ """A Git Bash spelling like ``./bin/tool.cmd`` must reach cmd as one program.
+
+ Unquoted, cmd reads the leading ``.`` as the program and ``/bin`` as a
+ switch, so a rewritten ``./.venv/Scripts/python.exe -m pytest`` never ran.
+ """
+ (tmp_path / "bin").mkdir()
+ (tmp_path / "bin" / "tool.cmd").write_text("@echo TOOL_OK\n", encoding="utf-8")
+
+ proc = subprocess.run( # repowise-security-ignore: subprocess_shell_true
+ _render_command(("./bin/tool.cmd", "arg")),
+ shell=True,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ cwd=tmp_path,
+ timeout=60,
+ )
+
+ assert proc.returncode == 0, proc.stderr or proc.stdout
+ assert "TOOL_OK" in proc.stdout
+
+
@pytest.mark.skipif(sys.platform != "win32", reason="cmd.exe rendering rules")
def test_render_command_refuses_a_defined_env_var_expansion(monkeypatch) -> None:
"""cmd expands %VAR% and re-parses the result, so a metacharacter in the