Skip to content

tests: subprocess.run(["bash", ...]) fails with WinError 2 outside Git Bash on Windows #665

Description

@Dakshkweera

Description

Several tests shell out to .sh hook scripts via subprocess.run(["bash", ...]). This works when pytest runs inside a Git Bash session, but fails with FileNotFoundError: [WinError 2] The system cannot find the file specified when run from a standard PowerShell or cmd.exe terminal — the more common setup for Windows contributors and CI runners.

Root cause: Git for Windows adds Git\cmd and Git\mingw64\bin to the system PATH, but bash.exe actually lives in Git\usr\bin, which is only added to PATH by Git Bash's own launcher — not the system-wide PATH. So subprocess.run(["bash", ...]) can't resolve bash outside a Git Bash shell.

Affected files:

  • tests/test_claude_hooks.py (10 call sites)
  • tests/test_codex_parse_rollout.py
  • tests/test_claude_parse_transcript.py
  • tests/test_codex_stop_hook_utf8.py

Expected: Tests should pass regardless of which Windows shell pytest is invoked from.

Proposed fix: Add a shared helper (e.g. new tests/conftest.py) resolving the bash executable via shutil.which("bash"), falling back to the literal "bash", and use that resolved path in all subprocess.run calls instead of the hardcoded string. Happy to submit a PR for this.

Steps to reproduce

  1. On Windows, with Git for Windows installed normally (not via WSL2)
  2. Open a plain PowerShell or cmd.exe terminal (not Git Bash)
  3. Run: git clone https://github.com/zilliztech/memsearch.git
    cd memsearch
    uv sync --all-extras
    uv run python -m pytest tests/test_claude_hooks.py -x

Error output / logs

FileNotFoundError: [WinError 2] The system cannot find the file specified

tests\test_claude_hooks.py:42: in test_claude_hook_memsearch_disable_exits_before_writing_memory
    result = subprocess.run(
C:\Program Files\Python313\Lib\subprocess.py:554: in run
    with Popen(*popenargs, **kwargs) as process:
C:\Program Files\Python313\Lib\subprocess.py:1036: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
C:\Program Files\Python313\Lib\subprocess.py:1548: in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

memsearch version

memsearch, version 0.4.17

Operating system

Windows

Python version

Python 3.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions