fix(report): write the report card as UTF-8, not the platform locale encoding - #35
Open
dchaudhari7177 wants to merge 1 commit into
Open
fix(report): write the report card as UTF-8, not the platform locale encoding#35dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
…encoding build_report crashed on Windows: the card carries non-ASCII (the delta column header in the side-effects table, the warning sign on degenerate-trap callouts), and Path.write_text with no encoding= falls back to the locale encoding, which is cp1252 on a stock install and cannot encode either character. tests/test_cli.py's three rendering tests fail there on a clean checkout with UnicodeEncodeError; they pass on CI only because Linux defaults to UTF-8. Name the encoding at every text I/O site in the package: the two card writes, both CSV readers, the side-effects stub, and the MMLU/GSM8K slice cache. The HTML already declares charset=utf-8, so writing it in anything else was self-contradictory. The regression test runs the whole CSV-in / card-out path in a fresh interpreter under -X warn_default_encoding and fails if any EncodingWarning is attributed to a file inside the package, so it catches a regression on UTF-8 platforms too rather than only where the crash happens. Reverting the fix makes it fail and name all five call sites.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while working on #30 — filing separately rather than folding an unrelated fix into that PR.
Problem
steer-reportcannot write a card on Windows. Three tests intests/test_cli.pyfail on a cleanmaincheckout there:The card is not ASCII — the side-effects table header is
Δ, the degenerate-trap callouts start with⚠️, and the prose uses±.Path.write_textwith noencoding=falls back to the platform locale encoding, which iscp1252on a stock Windows install and cannot encode any of them. CI is green only because Linux runners default to UTF-8.The same latent mismatch is in the readers:
Path.open(newline="")decodes both sweep CSVs and the side-effects CSV in the locale encoding, so abenchmarkname written as UTF-8 by the Modal harness would mojibake when the card is rendered on a non-UTF-8 machine.Change
Name the encoding at every text I/O site in
src/steerbench— five call sites, all one-liners:report.pymd_path.write_text/html_path.write_textreport.py_read_sweep_rows/load_side_effectsCSV openscli.py_ensure_side_csvstub writemetrics.pyNo behaviour change on a UTF-8 platform; the bytes written are identical. The HTML already emits
<meta charset="utf-8">, so writing it in the locale encoding was self-contradictory.experiments/modal_app.pyis left alone deliberately: it runs only inside the Modal Linux containers, and it is outside the lint/type gates (extend-exclude).Test
test_report_files_are_written_as_utf8intests/test_report.py.Asserting on the written bytes alone would pass with or without the fix on a UTF-8 runner, so the test instead runs the whole CSV-in / card-out path in a fresh interpreter under
-X warn_default_encoding. In that modeio.text_encoding()reports every call that relies on the default encoding as anEncodingWarningattributed to its caller, so unencoded I/O is detectable on every platform, not just where it crashes. Only warnings whose file lives inside the installed package count — optional third-party dependencies (matplotlib's font manager raises one) are not this repo's problem, and the first version of this test caught that instead, which is what led to the narrower filter.It also reads both artefacts back as UTF-8 and asserts the
Δand⚠️survive.Reverting just the
src/half makes it fail and name all five sites:I followed the existing
test_no_matplotlib_importedfresh-interpreter pattern rather than inventing a new one.Checks
ruff check .,ruff format --check .,mypy src,pytest -qall pass — and on Windows the full suite is now green under the defaultcp1252locale, where it was 2 failed before this change (3 with the new test).One unrelated local note:
mypy srcreports a syntax error insidenumpy/__init__.pyiif numpy is present in the environment (it arrives with the optionalreportextra, not with thedevgroup) because the config targetspython_version = "3.11".mypy --python-version 3.12 srcis clean, and CI does not install numpy.