Commit 1400a5c
fix(environments): pin PythonEnvironment._write_to_file encoding to UTF-8 (#2827)
* fix(environments): pin PythonEnvironment._write_to_file encoding to UTF-8
PythonEnvironment._write_to_file is the shared helper every concrete
PythonEnvironment subclass uses to land an agent-generated script on
disk before invoking subprocess. The bare 'open(script_path, "w")'
inherits 'locale.getpreferredencoding(False)' — cp1252 on default
Windows installs — so the first non-cp1252 character (CJK string
literal, emoji, smart quote from copy-pasted documentation, PEP 3131
identifier) raises 'UnicodeEncodeError' mid-write. The script is then
partially written, the subprocess runs an invalid file, and the agent
sees a syntax error or truncated output instead of the intended
behavior.
Pin encoding="utf-8" on the open call. Adds source-level regression
coverage in test/environments/test_python_environment_utf8.py that
runs on every CI lane (no PythonEnvironment subclass extras required)
so the kwarg cannot silently regress.
* chore: add license header to test/environments/__init__.py
`check-license-headers` pre-commit hook flagged the new test package
init as missing the standard SPDX header; add the 2023-2026 ag2 header
matching the sibling test file to clear the pre-commit-check / pr-check
failures.
* Remove outdated UTF-8 regression comment
Remove regression comment regarding UTF-8 encoding handling in PythonEnvironment._write_to_file.
---------
Co-authored-by: Qingyun Wu <qingyun0327@gmail.com>
Co-authored-by: Semen Frolov <148821259+vvlrff@users.noreply.github.com>1 parent f50307a commit 1400a5c
3 files changed
Lines changed: 26 additions & 1 deletion
File tree
- autogen/environments
- test/environments
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments