Repository navigation
fix(lexbench): write chart SVGs as explicit UTF-8 - #211
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Reviewed head 4fab7c60 against main at 0565b4ab, which is still the current main. I found one P3 test-isolation defect and no defects in the fix itself.
Findings
P3: tests/test_explicit_utf8_io.py:39 (LEXBENCH_BUILD): the new report-build tests depend on the caller's environment.
- Problem:
ascii_locale_environment()passes throughLEXBENCH_REPORT_RUNNER_ROOT, a documented override insrc/harness/lexbench/README.md. The siblingtest_lexbench_reportremoves it withmonkeypatch.delenv, but the new subprocess does not. - Evidence: with
LEXBENCH_REPORT_RUNNER_ROOT=/nonexistent/runnerset, all threetest_lexbench_report_builds_under_an_ascii_localecases fail, whilepytest tests/test_golden_reports.py -k lexbenchpasses all three. CI does not set this variable, so CI is unaffected. - Fix: add
os.environ.pop('LEXBENCH_REPORT_RUNNER_ROOT', None)toLEXBENCH_BUILDbeforereport.main, matching the golden test.
What I verified
The fix
Path.write_textandread_textwithencoding="utf-8"give the same bytes as before under a UTF-8 locale.charts.pyhas no other text I/O.- No SVG route moved in any snapshot.
Golden snapshots
- The only moved route is
reproduction/plot_version_summary.py, in the three Lexbench snapshots. shutil.copy2inwrite_reproduction_filespublishescharts.pyunder that name. The old file at0565b4abhashes to062add8a…and the new file to8a68cbf7…, matching the snapshots.
Removed code
write_charts_as_utf8,PUBLISHED_COPYand#208have no remaining references in the tree.- With the shim gone,
test_report_builds_are_byte_identical_under_an_ascii_localeexercises the real write path.
Negative controls, each argument reverted separately
- Without the
write_textargument, 6 tests fail: the encoding guard, the byte-identical test, the three report-build cases and the chart command test. - Without the
read_textargument, 3 tests fail: the encoding guard, the byte-identical test and the chart command test. The chart command test therefore covers the read path on its own.
Stored evidence and earlier packages
verification.pyonly checks that the published copy exists, at line 787. The two scripts it hashes are the resource orchestrators.- The verifier does call
render_chartand compares SVG bytes with the package. SVG output is unchanged under UTF-8, so packages built under UTF-8 keep verifying. pack.pyrecords hashes in each package's ownbundle-manifest.json.- The old hash appears nowhere in the tree after this change.
- In the data home, the old hash appears only in the three files the PR describes: one pre-call contract and its two later versions. I searched the evidence, builds, reviews and report-builds directories, not the whole data home.
- Nothing in the repository reads
harness_files. - Recomputing that map against this head gives 246 entries: 202 differ, 25 are gone and 19 match, which agrees with the PR's figures.
- I found no built Lexbench package outside the data home's private originals, which I did not search. As the PR says, packages published elsewhere were not opened.
Scope and rules
- All items in #208 are done, so
Closes #208is accurate. HASH_BOUNDno longer listscharts.py, and no compatibility alias or parallel implementation was added.- Hash-bound evidence is untouched, and the PR text contains no private data.
Test and CI results
- Ruff (both gates): pass.
pytest tests/test_golden_reports.py tests/test_explicit_utf8_io.py tests/test_moli_version_resource_chart.py tests/test_lexbench_verification.py -n 2: 132 passed, 8 subtests passed.- CI on this head: all checks pass, including "Tests and static checks" and "Installation and packaging".
|
Review round 1: one finding, fixed. Nothing disputed. Fixed in be8b6dd (P3, Checked with |
There was a problem hiding this comment.
ℹ️ Review skipped · be8b6dd
No reviewable content was selected for this run.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Reviewed head be8b6dd4 against main at 0565b4ab, which is still the current main. No defects found. CI passes on this head.
What I verified
The round 1 finding
LEXBENCH_BUILDnow removesLEXBENCH_REPORT_RUNNER_ROOTbeforereport.main. With the variable set to a nonexistent path, all threetest_lexbench_report_builds_under_an_ascii_localecases pass.- The only change since round 1 is that one line.
The fix
render_chartandmainnameencoding="utf-8", andcharts.pyhas no other text I/O. Output under a UTF-8 locale is unchanged, and no SVG route moved.
Tests fail without the fix
- With both arguments removed, these tests failed: the encoding guard, the byte-identical ASCII-locale test, the three new report-build tests and the chart command test.
- With only the
read_textargument removed, the chart command test still failed, so the read path is covered separately.
Scope against #208 (Closes is accurate)
- The
HASH_BOUNDentry, thePUBLISHED_COPYreason andwrite_charts_as_utf8are gone, with no remaining references in the repository. - The ASCII-locale build test covers all three scenarios and asserts that the Chinese chart SVGs contain non-ASCII text.
Golden snapshots
- Only
reproduction/plot_version_summary.pymoved, in the three Lexbench snapshots, from062add8a…to8a68cbf7…. - Those values match
sha256ofcharts.pyat0565b4aband at this head.write_reproduction_filescopies that file withshutil.copy2, which explains the move.
Published copy and recorded hashes
verification.py:787only checks that the published copy exists.pack.pyhashes each file into that package's ownbundle-manifest.jsonand never compares it with current source, and no tracked definition other than the three snapshots holds the old hash.- A search of the local data home found the old hash only in
contract.json,contract-v2.jsonandcontract-v3.jsonof one Web Fetch pre-call contract, underharness_files, as the PR says. - No file under
src,scripts,tests,configsor top-levelevaluationreadsharness_files. - I recounted the 246 hashes in
contract.jsonagainst this head: 202 differ and 25 files are gone. The 202 includescharts.py, so 201 differed before this PR rather than the "already" 202 in the PR text. That difference does not change the conclusion, so I am not raising it as a finding. - I did not open any packages published elsewhere. The PR states the same limit.
Commands run
pytest tests/test_golden_reports.py tests/test_explicit_utf8_io.py tests/test_moli_version_resource_chart.py tests/test_lexbench_verification.py -n 2: 132 passed, 8 subtests passed.- Both ruff gates pass.
CI on be8b6dd4
- "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks" all pass.
render_chart and the chart command used the locale encoding, so a Lexbench report build crashed with UnicodeEncodeError under an ASCII locale. Name UTF-8 for both calls, drop the charts.py exemption and the test shim that hid the crash, and test the build and the chart command under an ASCII locale. The published reproduction/plot_version_summary.py copy changes by these two arguments, so its route moves in the three Lexbench snapshots. Nothing compares that copy with a recorded hash; each package binds only its own copy. Closes #208
be8b6dd to
8e1759d
Compare
Issues
Closes #208
Summary
A Lexbench report build crashed with
UnicodeEncodeErrorunder an ASCII locale, becauserender_chartwrote chart text such as†and Chinese legend notes with the locale encoding. This applies the default stated in the issue.src/harness/lexbench/charts.py: nameencoding="utf-8"inrender_chartand in theread_textcall inmain.tests/test_explicit_utf8_io.py: remove thecharts.pyentry fromHASH_BOUNDand thePUBLISHED_COPYreason, which nothing else used.tests/lexbench_report_fixture.py,tests/test_golden_reports.py: removewrite_charts_as_utf8. The existing byte-identical ASCII-locale test now runs the real Lexbench write path.chartcommand with non-ASCII input, each in a subprocess under an ASCII locale.Moved route
Only
reproduction/plot_version_summary.pymoved, intests/golden/lexbench-{minimal,macos,linux}.json, from062add8a…to8a68cbf7…. The report publishescharts.pyas that file, so the route changes by exactly the twoencodingarguments above. No SVG or other route moved. Behavior under a UTF-8 locale is unchanged.Published copy and recorded hashes
Nothing compares the published copy with a recorded hash, so stored evidence and earlier packages keep verifying.
verification.pyreproduction/plot_version_summary.pyexists. The two reproduction scripts it does hash are the resource orchestrators, not this one.pack.pybundle-manifest.json.evaluation,research,src,tests,configs)harness_filesmap of one Web Fetch pre-call contract and its two later versions.The
harness_filesmap is a point-in-time record of the source tree at that run's commit, covering 246 files. No code undersrc,scriptsortestsreads that field, and 202 of the 246 hashes already differ from current source, with 25 more files gone. It is not a live binding oncharts.py, and those contracts were not edited.That search covered this machine's data home only, which holds no built Lexbench package. Packages published elsewhere were not opened; the conclusion for them rests on the verifier and packer code above.
Future report packages differ from earlier ones in this one file, as the issue anticipated.
Test plan
Run locally on macOS with the locked environment:
pytest tests/test_golden_reports.py tests/test_explicit_utf8_io.py tests/test_moli_version_resource_chart.py tests/test_lexbench_verification.py -n 2: 132 passed, 8 subtests passed.pytest tests/test_golden_reports.py -k lexbenchfailed for all three scenarios, each naming onlyreproduction/plot_version_summary.pyas changed. All three pass afterUPDATE_GOLDEN=1.charts.pyarguments temporarily removed, the three new report-build tests, the chart command test and the encoding guard all failed (5 failed). The arguments were then restored.ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: all checks passed.