From d2940d3678514be7a9c5f0876c9adc3464dd920e Mon Sep 17 00:00:00 2001 From: hotragn Date: Sun, 19 Jul 2026 03:29:45 -0500 Subject: [PATCH 1/2] fix(tests): make run_tests.sh work on native Windows (#67385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit env -i's allowlist was POSIX-centric: it passed HOME, which CPython on Windows never reads — Path.home()/expanduser resolve via USERPROFILE (or HOMEDRIVE+HOMEPATH), and ssl/sockets need SystemRoot, tempfile needs TEMP/TMP. With those stripped, every test file touching Path.home() died at collection with 'RuntimeError: Could not determine home directory' — taking out all of tests/gateway/ on native Windows, the platform the PowerShell installer itself sets up. Pass the six Windows vars through guarded on being set, so the Linux/macOS environment is byte-identical to before; none of them carry secrets, preserving the hermetic credential-stripping intent. Also set PYTHONUTF8=1 so the runner's ✓/⚠ output doesn't crash with UnicodeEncodeError under legacy Windows codepages — a no-op on Linux/macOS where LANG=C.UTF-8 already forces UTF-8. Verified on Windows 11: tests/gateway collection goes from RuntimeError to green (16/16 across the previously-failing files). --- scripts/run_tests.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 24ad3e8409ec7..9544ffbdbb74b 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -91,6 +91,19 @@ echo "▶ pre-compiling bytecode cache" "$PYTHON" -m compileall -q -j 0 -- $(git ls-files '*.py') >/dev/null 2>&1 || true echo "▶ launching test runner" +# Windows (native, via Git Bash): CPython on Windows ignores HOME — +# Path.home()/expanduser need USERPROFILE (or HOMEDRIVE+HOMEPATH), ssl and +# sockets need SystemRoot, and tempfile needs TEMP/TMP. With env -i +# stripping them, every test that touches Path.home() dies at collection +# with "RuntimeError: Could not determine home directory." None of these +# carry secrets, so passing them through preserves the hermetic intent +# (credential vars stay stripped). All are guarded on being set, so the +# Linux/macOS environment is byte-identical to before. +# +# PYTHONUTF8=1: the runner and per-file subprocesses print ✓/⚠ glyphs; +# Windows consoles default to a legacy codepage (cp1252) and crash with +# UnicodeEncodeError. UTF-8 mode is a no-op on Linux/macOS, where +# LANG=C.UTF-8 already forces UTF-8. exec env -i \ PATH="$PATH" \ HOME="$HOME" \ @@ -98,6 +111,13 @@ exec env -i \ LANG=C.UTF-8 \ LC_ALL=C.UTF-8 \ PYTHONHASHSEED=0 \ + PYTHONUTF8=1 \ + ${USERPROFILE:+USERPROFILE="$USERPROFILE"} \ + ${HOMEDRIVE:+HOMEDRIVE="$HOMEDRIVE"} \ + ${HOMEPATH:+HOMEPATH="$HOMEPATH"} \ + ${SYSTEMROOT:+SYSTEMROOT="$SYSTEMROOT"} \ + ${TEMP:+TEMP="$TEMP"} \ + ${TMP:+TMP="$TMP"} \ ${HERMES_RUN_SLOW_PET_TESTS:+HERMES_RUN_SLOW_PET_TESTS="$HERMES_RUN_SLOW_PET_TESTS"} \ ${EXTRA_PYTHONPATH:+PYTHONPATH="$EXTRA_PYTHONPATH"} \ ${EXTRA_PYTEST_PLUGINS:+PYTEST_PLUGINS="$EXTRA_PYTEST_PLUGINS"} \ From 97ce96b2ed5bac8b641f386802bbfa21825ef27c Mon Sep 17 00:00:00 2001 From: hotragn Date: Sun, 19 Jul 2026 03:56:28 -0500 Subject: [PATCH 2/2] fix(tests): probe Scripts/ venv layout so Windows venvs work without HERMES_PYTHON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consolidation requested by review: adopt #66496's native-Windows venv probe (python.exe and activate live under Scripts/ with no bin/) so the env-whitelist fix in this branch is reachable with an ordinary python -m venv / uv venv — no HERMES_PYTHON escape hatch needed. Probe shape credited to #66496. Co-authored-by: TheSmokeDev <194188786+TheSmokeDev@users.noreply.github.com> --- scripts/run_tests.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 9544ffbdbb74b..e40415497561d 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -42,15 +42,27 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # (HERMES_PYTHON is exported by the devShell hook and ships [dev] extras: # pytest, pytest-asyncio, pytest-timeout, ruff, ty). VENV="" +VENV_PYTHON="" for candidate in "$REPO_ROOT/.venv" "$REPO_ROOT/venv" "$HOME/.hermes/hermes-agent/venv"; do if [ -f "$candidate/bin/activate" ]; then VENV="$candidate" + VENV_PYTHON="$candidate/bin/python" + break + fi + # Native Windows venv layout: python.exe and activate live under + # Scripts/, and there is no bin/. Anyone running this script from + # Git Bash / MSYS with a `python -m venv`- or uv-created venv hits + # this branch — without it the canonical runner refuses to start. + # (Probe shape from #66496.) + if [ -f "$candidate/Scripts/activate" ]; then + VENV="$candidate" + VENV_PYTHON="$candidate/Scripts/python.exe" break fi done if [ -n "$VENV" ]; then - PYTHON="$VENV/bin/python" + PYTHON="$VENV_PYTHON" elif [ -n "${HERMES_PYTHON:-}" ] && [ -x "$HERMES_PYTHON" ] \ && "$HERMES_PYTHON" -c 'import pytest' 2>/dev/null; then # Guard with an import check: HERMES_PYTHON may point at the RELEASE