fix(test): read add_contributor.py with explicit UTF-8 encoding

test_cli_entrypoint_end_to_end copies add_contributor.py with
read_text()/write_text() and no encoding argument, so both fall back to
the system locale. add_contributor.py contains UTF-8 multi-byte
characters (an em dash), which makes the read raise UnicodeDecodeError
on any non-UTF-8 Windows locale (observed on cp950 / Traditional
Chinese). The trailing mapping-file read gets the same treatment for
symmetry.

Same footgun class as the subprocess text=True sweep in #60741, just on
the pathlib read_text/write_text side.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
Michael 2026-08-06 00:04:54 +08:00 committed by Teknium
parent 45ff814380
commit a619616736
1 changed files with 7 additions and 2 deletions

View File

@ -100,7 +100,12 @@ def test_cli_entrypoint_end_to_end(tmp_path):
scripts = tmp_path / "scripts"
scripts.mkdir()
for name in ("add_contributor.py",):
(scripts / name).write_text((SCRIPTS_DIR / name).read_text())
# Explicit encoding: add_contributor.py contains UTF-8 multi-byte
# characters (an em dash), so the locale-default read_text() raises
# UnicodeDecodeError on non-UTF-8 Windows locales (e.g. cp950).
(scripts / name).write_text(
(SCRIPTS_DIR / name).read_text(encoding="utf-8"), encoding="utf-8"
)
# Minimal stub release.py so the legacy lookup import works
(scripts / "release.py").write_text("LEGACY_AUTHOR_MAP = {}\n")
proc = subprocess.run(
@ -109,5 +114,5 @@ def test_cli_entrypoint_end_to_end(tmp_path):
cwd=tmp_path, capture_output=True, text=True,
)
assert proc.returncode == 0, proc.stderr
out = (tmp_path / "contributors" / "emails" / "cli@example.com").read_text()
out = (tmp_path / "contributors" / "emails" / "cli@example.com").read_text(encoding="utf-8")
assert out.splitlines()[0] == "cliperson"