Repository navigation
refactor(lexbench): split report main into named typed stages - #207
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Head reviewed: 33c92555. CI on this head fails: "Tests and static checks" reports 2 failed, 19774 passed. Both failures come from this PR's new test files, and both reproduce on macOS. The refactor itself held up in every comparison I ran. The blockers are in the new test and the fixture.
Findings
P0: tests/test_golden_reports.py:66 (test_lexbench_report), root cause in src/harness/lexbench/charts.py:453
- Problem:
tests/test_explicit_utf8_io.py::test_report_builds_are_byte_identical_under_an_ascii_localere-runs the golden suite underLC_ALL=C, and all three new scenarios fail withUnicodeEncodeError.render_chartcallsoutput.write_text(...)with no encoding, and the charts contain Chinese text.charts.pyis an existingHASH_BOUNDexemption (PUBLISHED_COPY) in that test. This is an existing defect onmainthat the new build exposes, so a real report build also crashes under an ASCII locale. - Probe: adding
encoding="utf-8"at that line clears the error, and the only remaining snapshot difference isreproduction/plot_version_summary.py. That is the only locale defect in these builds. It also means the direct fix changes published bytes, which conflicts with this PR's byte-identity claim. - Suggested fix: do not edit
charts.pyin this PR. Make the Lexbench golden test independent of the locale, for example by having the fixture runreport.render_chartwith UTF-8 as the default write encoding. Open a follow-up issue for the production crash, with the owner deciding whether to change the published copy and move that snapshot route.
P0: tests/lexbench_report_fixture.py:107
- Problem: the
stderr.logfixture line contains a literal/Users/<name>path whose name is not inPLACEHOLDER_HOMES, sotests/test_public_tree_privacy.py::test_tracked_text_has_no_private_valuesfails withhome: 1. - Suggested fix: use a name already in
PLACEHOLDER_HOMES, such asfixture, and do not extend the allowlist. This line feeds the evidence bytes, so regenerate the three snapshots on the unchanged code (commit 1) and on the refactor, then confirm they still match.
P2: PR body, "Test plan"
- Problem: "Failure-path differential" and "CI on Linux" are still unchecked and marked PENDING. The listed local targets also leave out the two test files that fail, so the plan gave no warning of these failures.
- Suggested fix: rerun both failing test files after the fixes, record the CI result, and either complete the differential or remove that item.
P3: src/harness/lexbench/report.py:898
- Problem: the nested
timestamp(value)is the only function in the file without type hints, and #203 asks for hints on the new functions. - Suggested fix: use
def timestamp(value: str) -> float:.
P3: tests/lexbench_report_fixture.py:3
- Problem: the docstring says the scenarios "cover every report branch". The PR body correctly says they do not: evidence-rejection guards and the
--sourceand missing-template paths are not executed. - Suggested fix: align the docstring with the PR body.
What I verified
- Snapshot origin:
report.pyat commit 1 (7e5a9610) is unchanged from based894600d, and commit 2 does not touchtests/. - Full builds: I built all three scenarios on both revisions with
GOLDEN_KEEP, anddiff -rreports no differences, including the unfolded case and evidence bytes in the folded routes. - Statement-level read: I compared the old
mainwith every stage: statement order, side-effect order,public_candidate_filesinsertion order,functional_methodsmutation timing,model.jsonkey order and guard messages. I found no behavioural difference. Replacingcorrectionswith a literal[]is safe because nothing ever appended to it. - Failure-path differential: I ran 1,015 cases against both revisions, comparing exception type, message, stderr, stdout and a hash of the partial output tree. There were no differences.
- The cases were JSON and JSONL leaf mutations, key deletions, file deletions and CLI and profile errors. I replaced the digest functions with an always-equal stub so mutations could reach guards behind the hash checks.
- Coverage by scenario:
minimal875 cases (all planned mutations),macos77,linux63. The last two are random samples of about 2,000 planned mutations each, so they are partial. - The stub means digest mismatches were not compared in this run; I checked those guards by reading the code.
- Snapshot sensitivity: two temporary output mutations, one in
build_public_modeland one insafe_failure, each failed all three scenarios. - Coverage claim: a line trace of the three builds agrees with the PR body. The unexecuted lines are guards, the
--sourceand missing-template paths, and a fewcontinuearms. - Size claims:
mainis 119 lines,build_public_modelis 99, and there are 48 new stages. - Frozen bindings: neither the path nor the base SHA-256 of
report.pyappears in tracked data.reproduction/copies onlyreproduction.pyandcharts.py. - Rules: existing golden routes are unchanged, the diff adds no aliases or parallel implementation and no template engine, and the "Closes #203" scope is otherwise met. Ruff gates pass, and the 93 tests in the PR's listed targets pass locally.
CI on 33c92555
| Check | Result |
|---|---|
| Tests and static checks | fail (the two P0s above) |
| Python 3.11 | fail, 3s; I did not open its log |
| Installation and packaging | pass |
| Rendered reference and report checks | pass |
charts.py is copied byte for byte into the published report, so it keeps its implicit write encoding until #208 decides. The fixture renders charts as UTF-8 so the ASCII-locale snapshot check exercises the rest of the build.
The stderr fixture line named a home outside PLACEHOLDER_HOMES, which the public tree privacy check rejects. The snapshots move only because that evidence line, and the case data derived from it, changed; the report code did not.
There was a problem hiding this comment.
✅ Re-review complete · 202bd31
No findings in this incremental review.
|
Review round 1 fixes, all pushed to head Fixed:
|
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Reviewed head 202bd31e against base d894600d. No defects were found. All five findings from round 1 are fixed. This is a comment only, not an approval.
What I verified
- Before/after bytes. I overlaid the head's fixture, golden test and snapshots on an unchanged
d894600dcheckout and built all three scenarios on both revisions withGOLDEN_KEEP.diff -rof the kept builds (87 files, 21 MB) reports no differences, including the folded case and evidence routes.src/differs only inreport.py. - Moved code. I inlined the stages in the order
maincalls them and diffed the normalized AST statements against the oldmain.- The only differences are renames, extracted constants,
returnstatements and the closure defaults removed fromevidence_forandsafe_failure. - One order change exists:
resolve()of the source and output paths now runs beforechart_populationis built. It can only matter for a symlink loop combined with a profile missingresource_population, so it is not worth changing. - The
correctionslist was never appended to, so the literal[]is equivalent. The 39data/model.jsonkeys keep their order. - The eager
runs[...][0]arguments cannot raise a new error, because earlier stages have already indexed those rounds. - Dataclass fields and positional stage arguments map correctly.
- The only differences are renames, extracted constants,
- Failure paths. My own small differential ran 12 cases on both revisions, separate from the author's. It covered a missing
resource_population, missing profile paths, a population mismatch, a bad--source, duplicate and unknown--fixed-summary, mixed macOS and Linux cohorts, missing matrix, official and Linux inputs, and an existing output directory. Exception text, stdout, stderr and the output digest were identical. This is a sample and does not reach most of the evidence-rejection guards. - Snapshot sensitivity. Three mutations, each to a different stage, made the Lexbench snapshot tests fail: a changed model value, a dropped
safe_failureresult, and a baseline/profile run root swap. The second one failed two of the three scenarios, and the others failed all three. - PR description claims.
mainwas 1,519 lines and is now 119, with 48 new stages. The longest stage,build_public_model, is 99 lines.- A line trace of the three scenarios matches the description: the unexecuted statements are mostly
raiseguards, plusparser.error, the--sourcepath and a fewcontinuearms. - No helper or nested function lacks type hints, and no template engine was added.
- Scope and rules.
- The pre-refactor file's SHA-256 and its path appear in no bound data. Git mentions of the path are limited to the Lexbench README, the CLI and tests.
charts.pyis unchanged. The ASCII-locale workaround applies only to the fixture'srender_chartcall and is disclosed, with #208 open for the owner decision.- The only snapshot changes are three new files, and no existing route moved.
Closes #203is accurate.
- Tests and lint.
test_explicit_utf8_io,test_public_tree_privacy,test_golden_reports,test_lexbench_report_runtime,test_lexbench_cli,test_lexbench_verificationandtest_data_home: 187 passed locally on Python 3.11. Both ruff gates pass. - CI at this head. "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks" all pass.
Limits
- I did not rerun the author's 1,171-run failure differential. The PR already states that it is a sample.
- The synthetic Mermaid bytes mean the vendored digest check is not exercised by the snapshot, as the PR discloses.
Issues
Closes #203
Part of the #104 and #87 refactor series; the other functions listed in #104 stay with that issue.
Summary
src/harness/lexbench/report.py::mainwas about 1,520 lines. It is now a 119-line sequence of 48 named, typed stages in the same file: arguments and paths, certified cohort, rounds, cases and evidence, summaries, version comparison, candidates, resource cohorts, public model, then output. The longest stage other thanmainisbuild_public_modelat 99 lines, most of which is the literaldata/model.jsonlayout. No template engine was added.The code was moved mechanically from line ranges of the old file rather than retyped. Evidence error messages are unchanged, including those that quote the old variable names, because they are existing output.
Checked first: no frozen binding records this file.
git grepfinds neither its path nor its SHA-256 in any bound data, and the report'sreproduction/directory copies onlyreproduction.pyandcharts.py.Byte-identity proof
The repository had no complete synthetic build of this report, so the first commit adds one and snapshots it against the unchanged
maincode. The second commit is the refactor and does not touch the snapshots. Review fixes follow; only the commit that changes the fixture's evidence moves snapshots, and the same snapshots were checked against the unchanged code (see the test plan).tests/lexbench_report_fixture.pywrites synthetic retained evidence for three scenarios:minimal(no candidates, Chinese only),macos(four fixed candidates with a serialized 11,140-call resource matrix) andlinux(the same candidates with saved Linux profiles). A line trace of the three builds shows the only unexecuted lines in the stages are evidence-rejection guards, the--sourceand missing-template paths, and a fewcontinueandelse Nonearms.tests/test_golden_reports.py::test_lexbench_reportcompares each build withtests/golden/lexbench-{minimal,macos,linux}.json. New files undertests/golden/are the only snapshot changes, and no existing route changes.Three fixture choices need a reviewer's eye:
report.bytes_sha256to accept them. The digest check itself is not exercised by this test.data/cases,data/fixed-casesanddata/evidenceare folded into one route each before snapshotting. This keeps the three snapshots under 9 KB instead of about 285 KB. The folded route still contains every byte, but a change there names the folded route rather than the individual case.charts.pywrites SVGs with no explicit encoding, so the build crashes under an ASCII locale. It is copied byte for byte into the publishedreproduction/plot_version_summary.py, so this PR leaves it unchanged. The fixture renders charts as UTF-8 so the ASCII-locale snapshot check still covers the rest of the build. The production crash and the owner decision on the published copy are in fix(lexbench): version chart SVGs crash report builds under an ASCII locale #208.Test plan
Run locally on macOS with Python 3.11 from the shared locked environment, with
PYTHONPATHpointed at the checkout, at head202bd31e.tests/test_explicit_utf8_io.py,tests/test_public_tree_privacy.py,tests/test_golden_reports.py,tests/test_lexbench_report_runtime.py,tests/test_lexbench_cli.py,tests/test_lexbench_verification.py,tests/test_data_home.py: 187 passed. The first two files are the ones that failed CI in the previous round.7e5a9610, whosesrc/equalsmain. The three Lexbench snapshot tests pass there and on the head, anddiff -rof the kept builds (including every case and evidence byte, folded) reports no differences for all three scenarios.minimalcover its input file classes in full. 340 onlinuxand 112 onmacosare capped per class and cover only classes the earlier scenarios had not reached. Thelinuxrun was stopped by time before finishing its classes, so this is a sample, not exhaustive.ruff check --config 'include=["*.py"]' --select F,TID252 .andruff checkpass.202bd31e: "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks" pass.