Skip to content

The agent that grows with you

fix(test-runner): preserve PATHEXT for native PowerShell children

ethernetd2c60dbdf87d
diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh
index fe01385ef1e..7c33d8e0cd1 100755
--- a/scripts/run_tests.sh
+++ b/scripts/run_tests.sh
@@ -113,12 +113,14 @@ fi
# resolves Path.home() from USERPROFILE (or HOMEDRIVE+HOMEPATH), stdlib
# platform paths come from LOCALAPPDATA/APPDATA, ssl/sockets need SYSTEMROOT,
# and tempfile needs TEMP/TMP. Dropping them breaks collection on native
-# Windows (issues #67385, #70813). These are location variables, not
+# Windows (issues #67385, #70813). PATHEXT is also required: without .EXE,
+# PowerShell can return success without executing a native child.
+# These are location variables, not
# credentials, so forwarding them keeps the isolation intent intact. Each is
# only forwarded when actually set, so POSIX runs are byte-for-byte unchanged.
WIN_ENV=()
for _win_var in USERPROFILE HOMEDRIVE HOMEPATH LOCALAPPDATA APPDATA SYSTEMROOT TEMP TMP \
- ComSpec PROGRAMFILES ProgramFiles PROGRAMDATA ProgramData; do
+ ComSpec PATHEXT PROGRAMFILES ProgramFiles PROGRAMDATA ProgramData; do
if [ -n "${!_win_var:-}" ]; then
WIN_ENV+=("$_win_var=${!_win_var}")
fi
diff --git a/tests/scripts/test_run_tests_shell.py b/tests/scripts/test_run_tests_shell.py
index 82098571350..c47a823aef0 100644
--- a/tests/scripts/test_run_tests_shell.py
+++ b/tests/scripts/test_run_tests_shell.py
@@ -12,9 +12,10 @@ def test_shell_runner_executes_tests_and_propagates_failure(tmp_path):
case = tmp_path / "test_runner_canary.py"
marker = tmp_path / "executed"
case.write_text(
- "from pathlib import Path\n"
+ "from pathlib import Path\nimport os\n"
"def test_canary():\n"
f" Path({str(marker)!r}).write_text('executed')\n"
+ " assert os.environ['PATHEXT'] == '.COM;.EXE;.BAT;.CMD'\n"
" assert False, 'runner failure propagation canary'\n",
encoding="utf-8",
)
@@ -22,7 +23,8 @@ def test_shell_runner_executes_tests_and_propagates_failure(tmp_path):
result = subprocess.run(
["bash", str(root / "scripts/run_tests.sh"), "-j", "1", str(case)],
cwd=tmp_path, capture_output=True, text=True, timeout=180,
- env={**os.environ, "HERMES_PYTHON": sys.executable, "HERMES_TEST_FILE_RETRIES": "0"},
+ env={**os.environ, "HERMES_PYTHON": sys.executable, "HERMES_TEST_FILE_RETRIES": "0",
+ "PATHEXT": ".COM;.EXE;.BAT;.CMD"},
)
assert marker.read_text(encoding="utf-8") == "executed", result.stdout + result.stderr
assert result.returncode != 0, result.stdout + result.stderr