Write Dockerfiles and build-context files as UTF-8 #23922
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 304 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #23922"
general
weight: 0.35
simin-yuan
What this does
ImageBuilderwrote the build context and the Dockerfile with the platform default encoding:Path.write_text(text)inwrite_text(), andopen("w")inbuild()andgenerate_default_dockerfile(). On a host whose locale is not UTF-8 (cp936/cp1252 on Windows) a context file containing a character the locale cannot encode raisesUnicodeEncodeError, and the hashed file is left in the context empty, so the Dockerfile generated afterwards references a truncated file.This passes
encoding="utf-8"to those three writes. The bytes no longer depend on the host locale, which is what the Dockerfile format expects and what Linux CI produces.Reproduction (before)
Windows 11,
locale.getpreferredencoding(False) == "cp936":and the context directory keeps the empty
.<sha256>file.After the change the same call writes the file and the test reads it back as UTF-8.
Tests
tests/utilities/test_dockerutils.pynow covers the three writes this PR changes:ImageBuilder.write_text(),ImageBuilder.build()andgenerate_default_dockerfile().The tests run in-process. A fixture wraps
pathlib.Path.write_textandPath.openso a call that omitsencodingwrites as ASCII, reproducing the cp936/cp1252 failure on any machine, while an explicit encoding is passed through untouched. Each test writes non-ASCII content (the emoji, and a non-ASCII context directory for the default Dockerfile) and asserts the file on disk is UTF-8.Mutation check: removing the three
encoding="utf-8"arguments makes all three tests fail withUnicodeEncodeError: 'ascii' codec can't encode ...; restoring them passes the file (19 passed).The earlier child-process test under
LC_ALL=Cwas removed rather than patched again. It did pass on CI here, so the reported child import failure was not reproduced; it was dropped because it could only work while the child process stayed importable and ASCII-clean, which is exactly the environment dependency this test should not have.Fixes #23921