Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/utils/env/test_env.py" line_range="613" />
<code_context>
assert venv_marker_env == system_marker_env
+
+
+def test_run_tolerates_output_that_cannot_be_decoded(tmp_venv: VirtualEnv) -> None:
+ # A command can print bytes that are not valid in the locale encoding: pip
+ # does so on Windows hosts whose code page is not UTF-8 (e.g. GBK). Reading
+ # that output must not raise UnicodeDecodeError.
+ output = tmp_venv._run(
+ [sys.executable, "-c", "import sys; sys.stdout.buffer.write(b'\\x80')"]
+ )
+
+ assert "\ufffd" in output
</code_context>
<issue_to_address>
**issue (testing):** The regression test fails on locales whose encoding accepts byte `0x80` (for example Latin-1 or Windows-1252): the subprocess output decodes to a valid character rather than U+FFFD, so the final assertion fails even though `_run` correctly tolerates the output.
**Triggers:** When the test runs with a non-UTF-8 locale encoding that defines byte `0x80`.
**Suggested fix:** Assert that the call returns successfully and produces output, or choose/assert against a byte sequence known to be undecodable for the active locale rather than requiring U+FFFD.
```suggestion
assert output
```
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/utils/env/test_env.py:613
…encoding `BaseEnv._run` reads the output of the commands it runs with `encoding="locale"`. A command can print bytes that are not valid in that encoding: on a Windows host whose code page is not UTF-8, pip does so while installing a distribution, and reading that output raised `UnicodeDecodeError` and aborted the caller. Decode with `errors="replace"` so an undecodable byte becomes U+FFFD instead of an exception. The locale encoding is unchanged, so hosts whose subprocess output does match the locale keep decoding exactly as before. Reproduced on a Windows host with a GBK code page: `tests/utils/test_pip.py::test_pip_install_successful` failed with `'gbk' codec can't decode byte 0x80 in position 20` and passes with this change. The regression test writes the same byte from a child process and asserts that the call returns instead of raising; whether the byte decodes depends on the active locale (Latin-1 and cp1252 accept it), so the test does not require a replacement character.
kokokoXUY
force-pushed
the
fix/tolerate-undecodable-subprocess-output
branch
from
September 26, 2026 14:51
01861d2 to
02c2bb5
Compare
Author
|
Fixed in You are right that a byte-level assertion was the wrong contract here: whether Verified locally on a host with a GBK code page: the test passes with the fix in place, and still fails against the unmodified |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
Summary
BaseEnv._runreads the output of the commands it runs withencoding="locale". A command can print bytes that are not valid in that encoding — pip does so on Windows hosts whose code page is not UTF-8 — and reading that output raisedUnicodeDecodeError, aborting the caller. On such a host,poetry installfails while installing a distribution.The read now uses
errors="replace", so an undecodable byte becomes U+FFFD instead of an exception. The locale encoding itself is unchanged: hosts whose subprocess output does match the locale decode exactly as before, and non-ASCII output that is valid in the locale is untouched.Reproduction
On a Windows host with a GBK code page:
With this change the same test passes.
The added regression test does not depend on that code page: it runs a child process that writes the single byte
0x80and asserts the call returns instead of raising. Before the change it fails on any platform, because0x80is not a valid standalone byte in UTF-8 either.Changed
src/poetry/utils/env/base_env.py:BaseEnv._rundecodes subprocess output witherrors="replace".tests/utils/env/test_env.py: regression test for undecodable subprocess output.Validation
ruff checkreportsAll checks passed!and both files passruff format --check.Notes
_runis not the only place that reads subprocess output;env_manager.pyhas two furtherencoding="locale"reads. They are not touched here — this change is limited to the path I reproduced, and the same treatment can be applied to those if you want it. Untouched as well: the 9 other failures intests/console/commands/envandtests/utils/test_python_manager.pyon this host, which are missing-shell and Windows-specific issues unrelated to decoding.