test(tools): pin the Git Bash probe's detached stdin in the existing probe test
The new standalone test file duplicated TestGitBashExternalProgramProbe's harness; one assertion on the recorded kwargs covers the #78820 contract. The sibling ASLR-probe assertion is dropped (unchanged code, already green on main). Comment trimmed to the WHY.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user