Skip to content

fix(lexbench): write chart SVGs as explicit UTF-8 - #211

Merged
lanyue-llk merged 2 commits into
mainfrom
fix/lexbench-chart-encoding
Nov 4, 2026
Merged

lanyue-llk merged 2 commits into
mainfrom
fix/lexbench-chart-encoding

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #208

Summary

A Lexbench report build crashed with UnicodeEncodeError under an ASCII locale, because render_chart wrote 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: name encoding="utf-8" in render_chart and in the read_text call in main.
  • tests/test_explicit_utf8_io.py: remove the charts.py entry from HASH_BOUND and the PUBLISHED_COPY reason, which nothing else used.
  • tests/lexbench_report_fixture.py, tests/test_golden_reports.py: remove write_charts_as_utf8. The existing byte-identical ASCII-locale test now runs the real Lexbench write path.
  • New tests: the complete report command for all three scenarios, and the chart command with non-ASCII input, each in a subprocess under an ASCII locale.

Moved route

Only reproduction/plot_version_summary.py moved, in tests/golden/lexbench-{minimal,macos,linux}.json, from 062add8a… to 8a68cbf7…. The report publishes charts.py as that file, so the route changes by exactly the two encoding arguments 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.

Where What it does with this file Effect of the new bytes
verification.py Checks only that reproduction/plot_version_summary.py exists. The two reproduction scripts it does hash are the resource orchestrators, not this one. None
pack.py Records the SHA-256 of each file in that package's own bundle-manifest.json. Earlier packages keep their own copy and hash. A new package records the new hash.
Git-tracked definitions (evaluation, research, src, tests, configs) The old hash appears only in the three snapshots updated here. None
Private evidence under the data home (JSON, JSONL, text and Markdown files) The old hash appears in the harness_files map of one Web Fetch pre-call contract and its two later versions. None, see below

The harness_files map is a point-in-time record of the source tree at that run's commit, covering 246 files. No code under src, scripts or tests reads that field, and 202 of the 246 hashes already differ from current source, with 25 more files gone. It is not a live binding on charts.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.
  • Before regenerating, pytest tests/test_golden_reports.py -k lexbench failed for all three scenarios, each naming only reproduction/plot_version_summary.py as changed. All three pass after UPDATE_GOLDEN=1.
  • Negative control: with the two charts.py arguments 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 . and ruff check: all checks passed.
  • CI (Linux) is the full-suite gate. The full suite was not run locally.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 4fab7c6

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 through LEXBENCH_REPORT_RUNNER_ROOT, a documented override in src/harness/lexbench/README.md. The sibling test_lexbench_report removes it with monkeypatch.delenv, but the new subprocess does not.
  • Evidence: with LEXBENCH_REPORT_RUNNER_ROOT=/nonexistent/runner set, all three test_lexbench_report_builds_under_an_ascii_locale cases fail, while pytest tests/test_golden_reports.py -k lexbench passes all three. CI does not set this variable, so CI is unaffected.
  • Fix: add os.environ.pop('LEXBENCH_REPORT_RUNNER_ROOT', None) to LEXBENCH_BUILD before report.main, matching the golden test.

What I verified

The fix

  • Path.write_text and read_text with encoding="utf-8" give the same bytes as before under a UTF-8 locale. charts.py has 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.copy2 in write_reproduction_files publishes charts.py under that name. The old file at 0565b4ab hashes to 062add8a… and the new file to 8a68cbf7…, matching the snapshots.

Removed code

  • write_charts_as_utf8, PUBLISHED_COPY and #208 have no remaining references in the tree.
  • With the shim gone, test_report_builds_are_byte_identical_under_an_ascii_locale exercises the real write path.

Negative controls, each argument reverted separately

  • Without the write_text argument, 6 tests fail: the encoding guard, the byte-identical test, the three report-build cases and the chart command test.
  • Without the read_text argument, 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.py only checks that the published copy exists, at line 787. The two scripts it hashes are the resource orchestrators.
  • The verifier does call render_chart and compares SVG bytes with the package. SVG output is unchanged under UTF-8, so packages built under UTF-8 keep verifying.
  • pack.py records hashes in each package's own bundle-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 #208 is accurate.
  • HASH_BOUND no longer lists charts.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".

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1: one finding, fixed. Nothing disputed.

Fixed in be8b6dd (P3, tests/test_explicit_utf8_io.py): the ASCII-locale report build inherited LEXBENCH_REPORT_RUNNER_ROOT. The build script now removes the variable before report.main, as the golden Lexbench test does.

Checked with LEXBENCH_REPORT_RUNNER_ROOT set to a nonexistent path: all three test_lexbench_report_builds_under_an_ascii_locale cases failed before the change and pass after it. With the variable unset, tests/test_golden_reports.py and tests/test_explicit_utf8_io.py give 78 passed, and both ruff gates pass. This change touches only the test, so no snapshot moved.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Review skipped · be8b6dd

No reviewable content was selected for this run.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_BUILD now removes LEXBENCH_REPORT_RUNNER_ROOT before report.main. With the variable set to a nonexistent path, all three test_lexbench_report_builds_under_an_ascii_locale cases pass.
  • The only change since round 1 is that one line.

The fix

  • render_chart and main name encoding="utf-8", and charts.py has 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_text argument removed, the chart command test still failed, so the read path is covered separately.

Scope against #208 (Closes is accurate)

  • The HASH_BOUND entry, the PUBLISHED_COPY reason and write_charts_as_utf8 are 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.py moved, in the three Lexbench snapshots, from 062add8a… to 8a68cbf7….
  • Those values match sha256 of charts.py at 0565b4ab and at this head. write_reproduction_files copies that file with shutil.copy2, which explains the move.

Published copy and recorded hashes

  • verification.py:787 only checks that the published copy exists. pack.py hashes each file into that package's own bundle-manifest.json and 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.json and contract-v3.json of one Web Fetch pre-call contract, under harness_files, as the PR says.
  • No file under src, scripts, tests, configs or top-level evaluation reads harness_files.
  • I recounted the 246 hashes in contract.json against this head: 202 differ and 25 files are gone. The 202 includes charts.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.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
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
@lanyue-llk
lanyue-llk force-pushed the fix/lexbench-chart-encoding branch from be8b6dd to 8e1759d Compare November 4, 2026 02:55

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 8e1759d

No findings in this review.

@lanyue-llk
lanyue-llk merged commit fbf31d7 into main Nov 4, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the fix/lexbench-chart-encoding branch November 4, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(lexbench): version chart SVGs crash report builds under an ASCII locale

1 participant