[GH-ISSUE #5201] tools: pr_ready's Python tests fail on Windows (perf_bench decodes cmd /C ver as UTF-8) #1590

Closed
opened 2026-11-02 15:48:12 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @iseaprojects on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5201

Originally assigned to: @iseaprojects on GitHub.

🤖 Filed by iseaprojects's AI agent (OpenCode, DeepSeek V4.1 Flash), not by iseaprojects personally.

python3 tools/pr_ready.py cannot pass its Python tests on Windows: tools/perf_bench.py reads cmd /C ver with text=True, and pr_ready runs the tests with PYTHONUTF8=1, so the reader thread decodes the console's OEM output as UTF-8 and stdout comes back None.

Environment: Windows 11 10.0.26200.9711 (Spanish), Python 3.12.10, main at 125875b84.

What happens:

ERROR: test_report_without_a_load_average (test_perf_bench.PortabilityTests...)
  File "tools/perf_bench.py", line 815, in windows_version
    out = subprocess.run(["cmd", "/C", "ver"], capture_output=True, text=True).stdout.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

The reader thread shows the cause:

Exception in thread Thread-1 (_readerthread):
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 26: invalid start byte

cmd /C ver prints Microsoft Windows [Versión 10.0.26200.9711] in the console's OEM code page (cp850 here). text=True decodes with the locale encoding, which PYTHONUTF8=1 (PEP 540) turns into UTF-8, so the decode fails inside subprocess and stdout is None.

Repro, without pr_ready:

$env:PYTHONUTF8="1"
python -c "import subprocess; print(repr(subprocess.run(['cmd','/C','ver'],capture_output=True,text=True).stdout))"
# None

Without PYTHONUTF8, the same command returns the text.

Why it matters: tools/pr_ready.py:456 sets PYTHONUTF8=1 for every step, so every Windows contributor gets Python tests: fail in the self-check block they paste into every pull request. The Python tests run in CI on ubuntu-latest, so CI never sees it.

Suggested fix: decode the console output with the OEM code page (encoding="oem" is Python's alias for it on Windows) or errors="replace", and/or fall back to platform.version() when stdout is None. windows_version() already falls back on an empty string; it just never gets one.

Test: PortabilityTests.test_report_without_a_load_average fails under PYTHONUTF8=1 and passes without it; a regression test can run it in a subprocess with the variable set.

Tooling only, Windows only; the benchmark report's os_version stays Microsoft Windows [Version ...].

Originally created by @iseaprojects on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5201 Originally assigned to: @iseaprojects on GitHub. > 🤖 Filed by iseaprojects's AI agent (OpenCode, DeepSeek V4.1 Flash), not by iseaprojects personally. `python3 tools/pr_ready.py` cannot pass its Python tests on Windows: `tools/perf_bench.py` reads `cmd /C ver` with `text=True`, and `pr_ready` runs the tests with `PYTHONUTF8=1`, so the reader thread decodes the console's OEM output as UTF-8 and `stdout` comes back `None`. **Environment:** Windows 11 10.0.26200.9711 (Spanish), Python 3.12.10, `main` at `125875b84`. **What happens:** ``` ERROR: test_report_without_a_load_average (test_perf_bench.PortabilityTests...) File "tools/perf_bench.py", line 815, in windows_version out = subprocess.run(["cmd", "/C", "ver"], capture_output=True, text=True).stdout.strip() AttributeError: 'NoneType' object has no attribute 'strip' ``` The reader thread shows the cause: ``` Exception in thread Thread-1 (_readerthread): UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 26: invalid start byte ``` `cmd /C ver` prints `Microsoft Windows [Versión 10.0.26200.9711]` in the console's OEM code page (cp850 here). `text=True` decodes with the locale encoding, which `PYTHONUTF8=1` (PEP 540) turns into UTF-8, so the decode fails inside `subprocess` and `stdout` is `None`. **Repro, without `pr_ready`:** ```powershell $env:PYTHONUTF8="1" python -c "import subprocess; print(repr(subprocess.run(['cmd','/C','ver'],capture_output=True,text=True).stdout))" # None ``` Without `PYTHONUTF8`, the same command returns the text. **Why it matters:** `tools/pr_ready.py:456` sets `PYTHONUTF8=1` for every step, so every Windows contributor gets `Python tests: fail` in the self-check block they paste into every pull request. The Python tests run in CI on `ubuntu-latest`, so CI never sees it. **Suggested fix:** decode the console output with the OEM code page (`encoding="oem"` is Python's alias for it on Windows) or `errors="replace"`, and/or fall back to `platform.version()` when `stdout` is `None`. `windows_version()` already falls back on an empty string; it just never gets one. **Test:** `PortabilityTests.test_report_without_a_load_average` fails under `PYTHONUTF8=1` and passes without it; a regression test can run it in a subprocess with the variable set. Tooling only, Windows only; the benchmark report's `os_version` stays `Microsoft Windows [Version ...]`.
Author
Owner

@iseaprojects commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6545376253 --> @iseaprojects commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#1590
No description provided.