Repository navigation
Fix the red Cross-platform parity run: decode PowerShell stdout as UTF-8 - #10476
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This duplicates #10432, which was opened yesterday for the same root cause and is already green, including The two diagnoses agree exactly:
Verified on #10432's run: Suggest closing this one in favour of #10432. Same fix, already proven on a Windows runner. For whoever picks this up: four open PRs are currently red on this alone (#10474, #10473, #10471, #10461), all showing the identical |
unslothai#10476 fixed the red Cross-platform parity run by decoding PowerShell's stdout as UTF-8, and its own windows-latest run is green, so the transport bug itself is closed. This is the part that failure exposed and that fix did not cover. errors is strict. `encoding = "utf-8"` alone still defaults to errors="strict" for subprocess text mode today, but the default is not the contract, and the cost of being wrong here is the exact failure unslothai#10476 just fixed: an undecodable byte becomes U+FFFD and fails an assertion about a value that was written correctly. Saying it makes the intent unambiguous at the one place that reads non-ASCII output. The assertion is the reason this cost an investigation rather than a glance. `assert result["After"] == expected, result` renders its diff through the same stdout under suspicion, so on a cp1252 console the EXPECTED side came back as U+FFFD while the actual side round-tripped, and the report read as though the correct half were the broken one. The raw log needed byte-level reading and a caret count to establish which operand was mangled. It now prints codepoints, which survive any code page, sliced from the common prefix so the message stays short. It names a cause only when the bytes show one: mojibake is the actual reading as expected's UTF-8 bytes back through a single-byte code page, so that is tested by re-encoding through cp1252, latin-1, cp437 and cp850 rather than pattern-matched. A genuine restore bug prints the codepoints and no explanation, because explaining a real bug away as an encoding artefact would be worse than saying nothing. Deliberately not included: an earlier revision of this branch also prepended install.ps1's UTF-8 preamble to pin the emit side. unslothai#10476's green run shows the runners already emit UTF-8, so that was defence against a condition that does not hold, and it is dropped rather than carried. 45 passed locally, kwarg-spacing check 62 passed, and both branches of the new assertion exercised directly: the cp1252 mojibake case names the code page, a substituted path does not.
…red (#10432) * Make the venv-hardening decode strict, and say which codepoints differed #10476 fixed the red Cross-platform parity run by decoding PowerShell's stdout as UTF-8, and its own windows-latest run is green, so the transport bug itself is closed. This is the part that failure exposed and that fix did not cover. errors is strict. `encoding = "utf-8"` alone still defaults to errors="strict" for subprocess text mode today, but the default is not the contract, and the cost of being wrong here is the exact failure #10476 just fixed: an undecodable byte becomes U+FFFD and fails an assertion about a value that was written correctly. Saying it makes the intent unambiguous at the one place that reads non-ASCII output. The assertion is the reason this cost an investigation rather than a glance. `assert result["After"] == expected, result` renders its diff through the same stdout under suspicion, so on a cp1252 console the EXPECTED side came back as U+FFFD while the actual side round-tripped, and the report read as though the correct half were the broken one. The raw log needed byte-level reading and a caret count to establish which operand was mangled. It now prints codepoints, which survive any code page, sliced from the common prefix so the message stays short. It names a cause only when the bytes show one: mojibake is the actual reading as expected's UTF-8 bytes back through a single-byte code page, so that is tested by re-encoding through cp1252, latin-1, cp437 and cp850 rather than pattern-matched. A genuine restore bug prints the codepoints and no explanation, because explaining a real bug away as an encoding artefact would be worse than saying nothing. Deliberately not included: an earlier revision of this branch also prepended install.ps1's UTF-8 preamble to pin the emit side. #10476's green run shows the runners already emit UTF-8, so that was defence against a condition that does not hold, and it is dropped rather than carried. 45 passed locally, kwarg-spacing check 62 passed, and both branches of the new assertion exercised directly: the cp1252 mojibake case names the code page, a substituted path does not. * Point the mojibake hint at the script, not the transport The hint said the shell's stdout had been read with the Windows ANSI code page and that the script did not lose the path. That is backwards now: _run_powershell decodes stdout as strict UTF-8, so a transport mis-decode raises there and never reaches this helper. Mojibake that does reach it was produced inside the script, which is the product defect these cases exist to catch, and a wrong explanation on a real restore bug costs more than none. Same byte test, opposite conclusion, plus where to look: a missing -Encoding utf8 on the marker read/write path. 45 tests in the file pass, and the rendered message on a seeded cp1252 round trip now reads 'the mis-decode happened inside the script, not in transport'.
Cross-platform parityhas been red onmainsince #10386 merged, and the failure is in the test harness rather than ininstall.ps1.What fails
test_a_non_ascii_marker_survives_the_rollbackfails on both shells:käffeeis the UTF-8 encoding ofkäffeeread back as cp1252.Why
_run_powershellcallsrun_pwsh(..., text = True)without anencoding, andrun_pwshforwards its kwargs tosubprocess.rununtouched.text = Trueon its own decodes with the locale codec, which is cp1252 on a Windows runner. Bothpwshand Windows PowerShell 5.1 write stdout as UTF-8, so the JSON the script emits is decoded with the wrong codec and every non-ASCII path in it turns to mojibake.The assertion is about a value that made a round trip through the marker file, so the mojibake looked like
Write-StudioUvCacheMarkerorRestore-StudioUvCacheMarkercorrupting it. They do not.Evidence that the product is fine
Driving the three real functions extracted from
install.ps1over the same round trip and reading the marker back as bytes:Byte-identical, still UTF-8. Separately, the mojibake reproduces exactly from the transport alone:
The second line is what the test expects and the third is what CI reported.
The fix
Pass
encoding = "utf-8"on that one call, so stdout is decoded as what the shells actually write.Scoped to this file rather than to
run_pwshitself. Defaulting the shared runner to UTF-8 would change decoding for every caller across the suite, and that is a wider blast radius than this failure justifies.Verification
Under a non-UTF-8 locale, before and after:
LC_ALL=Craises where cp1252 silently substitutes, but it is the same root cause: the locale codec is not what the shell wrote. Full file passes locally, 45 tests.The Windows leg of
Cross-platform parityon this PR is the real check, since neither locale here is cp1252.