Repository navigation
Name the encoding when reading wslinfo's output - #9142
Conversation
Backend CI is red on main. test_text_io_names_its_encoding[lan_access.py] reports lan_access.py:127 running subprocess with text = True and no encoding, which falls back to the Windows ANSI codepage and corrupts non-ASCII. The call reads wslinfo --networking-mode, whose output is ASCII in practice, so this is the guard being right about the shape rather than about this particular command. The guard scans every backend module and does not special-case commands whose output happens to be safe today, which is the correct posture: the next caller to copy this block would inherit the defect. Reproduced on main and verified: 453 pass with the fix, and reverting it fails exactly the one test.
The failure message named only the Windows ANSI codepage, which invites a correct-sounding rejection: the call this caught sits behind an explicit sys.platform != linux early return, so it can never run on Windows. That reasoning is wrong, and the message was what made it available. The fallback is locale.getencoding(), which is the ANSI codepage on Windows and ASCII under a C or POSIX locale on Linux, as containers and CI runners routinely have. A linux-only path still meets the second one. Message only. Detection is unchanged: 453 pass before and after, and reverting the lan_access fix still fails exactly one test.
Blame, and both readings of itWhat introduced it. Reading one, the source is wrong. The two other Reading two, the guard is over-broad, and it deserves a real answer rather than a dismissal. Why reading one wins. The message was incomplete, not the detection. The fallback is Robustifying the guardRather than only fixing the call, the second commit rewrites the failure message to name both mechanisms and to say explicitly that a platform guard above the call does not make it safe. That closes the escape hatch that made reading two available in the first place. Message only. Detection is untouched:
So the check still discriminates after the change, verified by reverting the fix rather than asserted. What I deliberately did not doNo sweep, and no waiver mechanism. If the same shape exists elsewhere in the backend the guard already scans every module and will say so; finding it by hand would be less reliable than the tool that just found this one. |
|
CI note, so the red does not get read as this change. The only failing job here is
This PR touches The guard itself still discriminates: 453 pass on this branch, and checking out |
Backend CI is red on
main, and has been since the encoding guard started scanning this file.studio/backend/tests/test_text_io_encoding.py::test_text_io_names_its_encoding[lan_access.py]reports:text = Truewith noencodingdecodes withlocale.getpreferredencoding(False), which on Windows is the ANSI codepage rather than UTF-8, so non-ASCII output is corrupted rather than merely mis-rendered.The call reads
wslinfo --networking-mode, whose output is ASCII in practice, so this is the guard being right about the shape rather than about this particular command. That is the correct posture for it to take: it scans every backend module and does not special-case commands whose output happens to be safe today, because the next caller to copy this block inherits the defect.subprocess.runacceptsencodingdirectly and impliestextmode, so naming it is the whole fix.Verification
Reproduced on
mainate46319458before changing anything.test_text_io_encoding.pymain, unmodifiedThe test discriminates: reverting the one line brings the failure straight back, so this is not a change that passes either way.
test_lan_access_settings.pyis unaffected, 65 of 65. Two collection errors appear when running the whole backend directory with-k lan_access, and they are identical on unmodifiedmain, so they are pre-existing and out of scope here.Why this is separate
This is a one-line repair to unblock
main, not a sweep. If the guard is worth having, and it is, then the same shape elsewhere should be found by the guard itself rather than by hand, and it already scans every backend module.