fix(tests): make run_tests.sh work on native Windows (#67385) - #67387
fix(tests): make run_tests.sh work on native Windows (#67385)#67387Hotragn wants to merge 2 commits into
Conversation
) 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).
|
Reviewed against #67385. This looks correct, minimal, and well-scoped — it fully addresses both failure modes the issue describes. What's solid
Minor notes (non-blocking)
No behavior change on POSIX, real fix on native Windows, no new deps. LGTM pending the standard CI gates. |
Related to #66496 and #63642. The live branch combines native-Windows venv |
|
@PRATHAMESH75 thanks for the careful review — agreed on both notes: Git Bash uppercases the vars and the Windows CRT getenv is case-insensitive, so On alt-glitch's consolidation question — the three open runner PRs fix three independent breakages, and native Windows needs all three before
They compose cleanly: #66496's probe fix gets you a Python; this PR's whitelist gets that Python through collection. (#66496's repro file never touches Equally happy to fold the whitelist into #66496 instead if @TheSmokeDev and maintainers would rather take the runner work as one PR — whatever makes the merge easiest. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the Windows environment failure. The HOME premise is verified on current main: scripts/run_tests.sh:94-104 uses env -i and preserves only HOME; under a clean environment, ntpath.expanduser("~") remains ~ until USERPROFILE is supplied.
Problems
- This patch alone does not make ordinary native-Windows venv invocation work: current
scripts/run_tests.sh:45-63only probesbin/activateandbin/python. The documented repro therefore requiresHERMES_PYTHON. - Open #66496 modifies the same
env -iblock and adds the missingScripts/activate/Scripts/python.exeprobe. It overlaps this patch's whitelist work.
Suggested changes
- Consolidate with #66496 (or include its
Scripts/probe here), retaining this PR'sTEMP,TMP, andPYTHONUTF8coverage.
Automated hermes-sweeper review.
| PATH="$PATH" \ | ||
| HOME="$HOME" \ | ||
| TZ=UTC \ | ||
| LANG=C.UTF-8 \ |
There was a problem hiding this comment.
Open #66496 edits this same env -i block and adds the missing Scripts/python.exe native-Windows venv probe. Please consolidate the changes, retaining this PR's TEMP/TMP whitelist, so normal Windows venvs do not still require HERMES_PYTHON.
…HERMES_PYTHON Consolidation requested by review: adopt NousResearch#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 NousResearch#66496. Co-authored-by: TheSmokeDev <194188786+TheSmokeDev@users.noreply.github.com>
|
Consolidation done as requested: One correction to my earlier comparison table: #66496's Verified on Windows 11 with no #66496's |
|
Follow-up on my earlier review — the new commit The venv-discovery change is correct and POSIX-neutral. On Linux/macOS a One scope note (non-blocking): this commit fixes venv discovery, which is a distinct Windows failure from the No behavior change on POSIX, both Windows failure modes (venv layout + env-stripped |
|
Author of #66496 confirming the consolidation: #67387 is my preferred canonical Maintainers do not need to choose between competing wrapper diffs on my account. If this lands, I will close #66496 as superseded for the wrapper work. I will keep any direct- |
monerostar
left a comment
There was a problem hiding this comment.
Native Windows verification (monerostar)
Physical Windows 11 · Git Bash · Python 3.11.15 (Hermes venv) · PR head 97ce96b2e.
Control on current main (run_tests.sh allowlist = HOME only)
env -i PATH=… HOME=… TZ=UTC LANG=C.UTF-8 …
python -c "from pathlib import Path; Path.home()"
→ RuntimeError: Could not determine home directory.
Also observed on main when running the canonical runner: progress printing dies with
UnicodeEncodeError: 'charmap' codec can't encode character '\u2713' … (cp1252)
This PR
| Check | Result |
|---|---|
Scripts/ venv probe |
Present |
USERPROFILE / HOMEDRIVE / HOMEPATH / SYSTEMROOT / TEMP / TMP |
Present (:+ guarded) |
PYTHONUTF8=1 |
Present |
Path.home() under PR’s env -i line |
OK → C:\Users\Admin |
bash scripts/run_tests.sh tests/test_hermes_constants.py -q |
Completes — no collection home crash, no glyph UnicodeEncodeError |
Out of that file: 105 passed, 6 failed, 15 skipped. The 6 failures are symlink privilege (WinError 1314 / no developer mode symlink) in TestGetHermesDir — not caused by this PR; same class needs @skipif or Developer Mode, separate from #67385.
Relation to siblings
| PR | Overlap |
|---|---|
| #66496 | Also has Scripts/ + home vars; plus _make_stdio_glyph_safe + encoding=utf-8 on runner self-tests — this PR relies on PYTHONUTF8=1 for glyphs (worked here) but doesn’t harden run_tests_parallel.py subprocess text=True decode |
| #70813 | Asks for LOCALAPPDATA/APPDATA + parallel runner encoding="utf-8", errors="replace" — not in this PR; optional follow-up |
| #39347 | Older / broader; prefer this or #66496 |
Recommend merge (or merge #66496’s parallel stdio bits into this one). CI green + live Win11 proof. Closes the “CONTRIBUTING says use run_tests.sh but Windows can’t” hole.
|
Opened a combined native-Windows runner PR that includes this allowlist + Scripts/ probe (rebased on current main, which already has the pytest-in-venv gate): #71591. Happy to close in favor of whichever the maintainers prefer. |
|
Closing in favor of #71591 (@monerostar) — it does the exact consolidation the needs-decision on this PR was waiting for: it combines this PR's env allowlist + PYTHONUTF8 + Scripts/ probe with #66496's parallel-runner encoding and #70813's LOCALAPPDATA/APPDATA vars, rebased on current main, and credits all three by name. I verified it preserves this PR's fix faithfully (same six guarded vars, same UTF-8 mode, same Scripts/ layout branch). One combined, rebased PR is the right thing to merge here rather than three overlapping ones. Thanks @monerostar for folding these together — #71591 is the one to land. |
What does this PR do?
Makes the canonical test runner usable on native Windows.
env -i's allowlist was POSIX-centric: it passedHOME, which CPython on Windows never reads —Path.home()/expanduserresolve viaUSERPROFILE(orHOMEDRIVE+HOMEPATH),ssl/sockets needSystemRoot, andtempfileneedsTEMP/TMP. With those stripped, every test file touchingPath.home()died at collection withRuntimeError: Could not determine home directory— all oftests/gateway/included. Full traceback and analysis in #67385.Also sets
PYTHONUTF8=1: the runner and per-file subprocesses print✓/⚠glyphs, which crash withUnicodeEncodeErrorunder legacy Windows codepages (cp1252).Hermetic intent preserved: none of the six passed-through vars carry secrets — credential vars stay stripped. All six are guarded on being set (
${VAR:+...}), so the Linux/macOS environment is byte-identical to before;PYTHONUTF8=1is a no-op there sinceLANG=C.UTF-8already forces UTF-8. CI is unaffected either way — the workflows invokerun_tests_parallel.pydirectly, not this wrapper.Related Issue
Fixes #67385.
Type of Change
Changes Made
scripts/run_tests.sh— guarded passthrough ofUSERPROFILE,HOMEDRIVE,HOMEPATH,SYSTEMROOT,TEMP,TMPin theenv -iblock +PYTHONUTF8=1, with a comment documenting why each is needed on Windows.How to Test
python -m venv.venv(post-consolidation, commit97ce96b2e):bash scripts/run_tests.sh tests/gateway/test_42039_duplicate_user_message.py tests/agent/test_turn_overlap_tripwire.pyerror: no virtualenv foundat startup (Scripts/ layout unprobed); withHERMES_PYTHONsupplied,RuntimeError: Could not determine home directoryat collection (0 collected)..venv/Scripts/python.exe, collection succeeds, 16/16 pass, no UnicodeEncodeError.${VAR:+...}-guarded),bin/activateis still probed first, and UTF-8 mode was already in effect viaLANG.Regression guard: the fix is shell-level, so the guard is the reproducible command above rather than a test file. If maintainers want it mechanized, a small CI job running that exact command under
windows-latest+ Git Bash would lock both failure modes permanently — happy to add it here or as a follow-up.Checklist
Code
Documentation & Housekeeping