Repository navigation
Make the venv-hardening decode strict, and say which codepoints differed - #10432
Conversation
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. |
#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.
e8db458 to
a608876
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a608876ab9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if _looks_like_a_mis_decode(actual[head:], expected[head:]): | ||
| lines.append( | ||
| " actual is expected's UTF-8 bytes decoded as a single-byte code page, i.e. this " | ||
| "shell's stdout was read with the Windows ANSI code page. The script did not lose " | ||
| "the path." |
There was a problem hiding this comment.
Avoid blaming stdout for marker corruption
If Write-StudioUvCacheMarker regresses to reading the BOM-less marker with Windows PowerShell's ANSI codec—the exact product failure this test covers—the restored value is also expected.encode("utf-8").decode("cp1252"). This predicate therefore matches both transport corruption and corruption inside the script, then misleadingly states that the script preserved the path. Since _run_powershell now decodes stdout as strict UTF-8, the helper cannot infer where the mojibake occurred from the final strings alone; keep the codepoint diff but do not claim a transport-only cause without raw-byte evidence.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and the conclusion was backwards rather than merely unprovable. _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 defect these cases exist to catch. Fixed in 66dc5dc: same byte test, opposite conclusion, plus where to look (a missing -Encoding utf8 on the marker read/write path). Rendered on a seeded cp1252 round trip it now reads 'the mis-decode happened inside the script, not in 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'.
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Rebased and narrowed. #10476 landed the decode fix and its
parity (windows-latest)is green, so the transport bug is closed and this PR no longer carries it. What remains is the part that failure exposed and that fix did not cover.errors = "strict"encoding = "utf-8"on its own already defaults toerrors="strict"in subprocess text mode today, so this changes no behaviour. But the default is not the contract, and the cost of being wrong here is precisely the failure #10476 just fixed: an undecodable byte becomes U+FFFD and fails an assertion about a value that was written correctly. Worth stating at the one helper in this file that reads non-ASCII output.The assertion
This is the substantive half. The old line was:
which renders its diff through the same stdout under suspicion. On a cp1252 console the expected side came back as U+FFFD while the actual side round-tripped, so the report read as though the correct half were the broken one. Establishing which operand was mangled took byte-level reading of the raw log plus a caret count: one caret under expected, two under actual.
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/cp850 rather than pattern-matched. A genuine restore bug prints the codepoints and no explanation:
Explaining a real restore bug away as an encoding artefact would be worse than saying nothing, which is why the claim is earned rather than asserted.
Deliberately dropped
The earlier revision of this branch also prepended
install.ps1's UTF-8 preamble to_run_powershell, pinning the emit side so the result would not depend on the runner's console code page. #10476's green run shows the runners already emit UTF-8, so that was defence against a condition that does not hold. Dropped rather than carried.Verification
pytest tests/python/test_windows_python_venv_hardening.py-> 45 passedpytest tests/test_enforce_kwargs_spacing.py-> 62 passedNet delta against main is 50 insertions, 1 deletion, one file.