Shell Middleware Unit Tests Fail On Windows Due To POSIX-Only Assumptions And Missing Guards
26 unit tests across test_shell_tool.py and test_shell_execution_policies.py fail on Windows because ShellToolMiddleware hardcodes /bin/bash, uses POSIX-only signals and the resource module, and the tests lack platform skip markers or proper patching of the _HAS_RESOURCE flag.
ShellToolMiddleware is POSIX-only by design: _normalize_shell_command defaults to (/bin/bash,), _kill_process calls os.killpg(..., signal.SIGKILL), and HostExecutionPolicy requires the resource module. The tests do not guard against Windows, and in test_shell_execution_policies.py the _HAS_RESOURCE flag is set once at import time to False on Windows, so even with a mocked resource module the constructor raises before reaching the mocked code.
On Windows, clone the repo, cd libs/langchain_v1, run uv sync --group test, then uv run pytest tests/unit_tests/agents/middleware/implementations/test_shell_tool.py tests/unit_tests/agents/middleware/implementations/test_shell_execution_policies.py. Result: 26 failed, 30 passed, 2 skipped.
Fixing Code Block
# In tests/unit_tests/agents/middleware/implementations/test_shell_tool.py
import sys
import pytest
requires_posix_shell = pytest.mark.skipif(
sys.platform == "win32",
reason=(
"ShellToolMiddleware requires a POSIX shell (`/bin/bash`) and POSIX "
"process-group signals (`os.killpg`, `signal.SIGKILL`)"
),
)
# Apply @requires_posix_shell to the 23 shell-spawning tests.
# Example:
@requires_posix_shell
def test_shell_tool_spawns_process(...):
...
# In tests/unit_tests/agents/middleware/implementations/test_shell_execution_policies.py
# In the three tests that construct HostExecutionPolicy with limits and mock resource,
# after the existing monkeypatch.setattr(_execution, "resource", fake_resource), add:
monkeypatch.setattr(_execution, "_HAS_RESOURCE", True, raising=False)
The fix is test-only and aligns with existing practices in the same test tree. For the 23 truly POSIX-dependent tests, a shared pytest.mark.skipif marker is added to skip them on Windows. For the 3 HostExecutionPolicy tests, the _HAS_RESOURCE flag is patched to True so the mocked resource module is actually used, making those tests pass on all platforms without changing production code.
Edge Case Audit
The fix only affects tests and does not change runtime behavior. Skipping Windows tests may hide future regressions in shell middleware on Windows; the _HAS_RESOURCE patch makes tests pass but the actual resource module remains unavailable on Windows, so HostExecutionPolicy still raises a clear error in production. Rollback is straightforward by reverting the test file changes. No production code is touched, so upgrade/downgrade risk is minimal.