diff --git a/tests/tools/test_find_shell.py b/tests/tools/test_find_shell.py index d9ea4680cf..2fb3e31abb 100644 --- a/tests/tools/test_find_shell.py +++ b/tests/tools/test_find_shell.py @@ -155,6 +155,8 @@ class TestGitBashExternalProgramProbe: assert gitbash_probe._bash_starts(r"C:\Git\bin\bash.exe") is True assert calls[0][0][-1] == "/usr/bin/true; /usr/bin/cat --version >/dev/null" + # #78820: the probe must not inherit the TUI gateway's stdin pipe (MSYS flips it to PIPE_NOWAIT). + assert calls[0][1].get("stdin") is subprocess.DEVNULL @pytest.mark.windows_only def test_aslr_failure_surfaces_targeted_windows_command( diff --git a/tests/tools/test_gitbash_probe_stdin.py b/tests/tools/test_gitbash_probe_stdin.py deleted file mode 100644 index 57533467a2..0000000000 --- a/tests/tools/test_gitbash_probe_stdin.py +++ /dev/null @@ -1,47 +0,0 @@ -"""The Windows Git Bash / ASLR probes must not inherit the caller's stdin (#78820). - -``local._find_bash`` runs these probes on the first ``LocalEnvironment`` of a -process. Inside the TUI that process is the stdio gateway, whose stdin is the -pipe tui-parent reads JSON-RPC from. A probe started with ``capture_output`` -alone inherits that pipe; the MSYS2 runtime then switches the shared pipe to -``PIPE_NOWAIT`` and the gateway's next ``sys.stdin.readline()`` fails with -``OSError: [Errno 22]``. Passing ``stdin=subprocess.DEVNULL`` keeps the -gateway's pipe out of the child entirely. -""" - -import subprocess - -import pytest - -from tools.environments import local_gitbash_probe as gitbash_probe - - -@pytest.fixture -def run_calls(monkeypatch): - """Record every ``subprocess.run`` kwargs dict instead of spawning.""" - calls = [] - - def fake_run(argv, **kwargs): - calls.append(kwargs) - return subprocess.CompletedProcess(argv, 0, stdout="OFF\n", stderr="") - - monkeypatch.setattr(gitbash_probe.subprocess, "run", fake_run) - return calls - - -def test_bash_starts_detaches_stdin(run_calls): - gitbash_probe._bash_starts_cache.clear() - gitbash_probe._bash_probe_details_cache.clear() - - assert gitbash_probe._bash_starts(r"C:\Git\bin\bash.exe") is True - assert len(run_calls) == 1 - assert run_calls[0].get("stdin") is subprocess.DEVNULL - - -def test_mandatory_aslr_probe_detaches_stdin(run_calls, monkeypatch): - monkeypatch.setattr(gitbash_probe, "_mandatory_aslr_enabled_cache", None) - monkeypatch.setattr(gitbash_probe.shutil, "which", lambda _name: "powershell.exe") - - assert gitbash_probe._mandatory_aslr_enabled() is False - assert len(run_calls) == 1 - assert run_calls[0].get("stdin") is subprocess.DEVNULL diff --git a/tools/environments/local_gitbash_probe.py b/tools/environments/local_gitbash_probe.py index 108d9792fd..ac7dabf27e 100644 --- a/tools/environments/local_gitbash_probe.py +++ b/tools/environments/local_gitbash_probe.py @@ -91,10 +91,7 @@ def _bash_starts(bash: str) -> bool: [bash, "--noprofile", "--norc", "-c", _BASH_EXTERNAL_PROGRAM_PROBE], capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=15, creationflags=windows_hide_flags() if _IS_WINDOWS else 0, - # Detach stdin (#78820): with capture_output alone the MSYS bash - # inherits the TUI gateway's stdin pipe and flips it to PIPE_NOWAIT, - # so the gateway's next readline() raises OSError(EINVAL). - stdin=subprocess.DEVNULL) + stdin=subprocess.DEVNULL) # #78820: never hand the TUI gateway's stdin pipe to MSYS bash ok = result.returncode == 0 if not ok: combined = f"{result.stdout or ''}{result.stderr or ''}".strip()