Skip to content

test: add golden route-hash snapshots for report tracks - #119

Merged
lanyue-llk merged 6 commits into
mainfrom
refactor/golden-report-snapshots
Oct 30, 2026
Merged

lanyue-llk merged 6 commits into
mainfrom
refactor/golden-report-snapshots

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds golden route-hash snapshots so a refactor that changes rendered report output fails make test. This is step 0 of the refactor roadmap (#87); the later cleanup PRs rely on it to prove they change no output.

Issues

How it works

  • tests/test_golden_reports.py builds the synthetic example of each report track and compares every output file with tests/golden/<build>.json, which maps route → SHA-256. The JSON files are hash bindings, not generated reports (92 KB total).
  • tests/golden_snapshots.py normalizes machine-specific bytes before hashing:
    • the temporary build directory becomes <build-root>;
    • Browser Use and Trajectory Replay bind attempts.jsonl / results.json by SHA-256, and those files name absolute evidence paths, so their digests become <path-bearing-input-sha256>.
  • Every build pins the report builder identity (harness.reporting.versions.software_identity). Reports record the git revision and source hash, which change with every commit; without the pin, any refactor would rewrite every snapshot.
  • The Web Fetch build pins the clock (utc_now, monotonic, perf_counter) and the recorded host (platform, hostname, Python version), because run IDs, timestamps, timings and the execution manifest come from them. The runner's runtime_source_sha256 (a hash of every Web Fetch module) is replaced with <source-sha256>.
  • UPDATE_GOLDEN=1 rewrites the snapshots. On a mismatch the failure lists changed, added and removed routes. Only hashes are stored, so it cannot print the old text; GOLDEN_KEEP=<dir> keeps the normalized build for diff -r against another revision. CONTRIBUTING.md documents both.

Coverage

Build Builder reused
Browser Use (pass, fail) tests/browser_use/test_report.py::build_browser_use_fixture
Trajectory Replay (pass, fail) tests/trajectory_replay/test_webarena_report.py::build_replay_fixture
Public WebArena replay tests/public_webarena_fixture.py::write_report_fixture + stage_report
Web Search harness.web_search.example
WCXB tests/wcxb_fixture.py::create_report_inputs + generate_wcxb
WebMainBench sample tests/test_webmainbench_report.py::sample_report_inputs (extracted from an inline test body; the test is unchanged)
WebMainBench full tests/test_webmainbench_full_report.py::render_full_report
Web Fetch run_evaluation with FixtureProvider + build_report, English and Chinese

Not covered: LexBench (harness/lexbench/report.py). Its main() needs a full saved-profile evidence tree and no test builds one. A builder belongs with the renderer split in #104.

The issue's optional "record which translation keys were hit" is left for #99, where it is used.

Test plan

  • Ten builds pass, and rerunning (including with -n 4) gives identical bytes.
  • With the dead-code removal for Remove dead code, retired compatibility shims and duplicated example files #92 applied on top (a different HEAD and source hash), all ten snapshots still pass.
  • Negative control: changing one rendered label (P50 ms → P50 (ms) in the Web Search report) fails exactly web-search: index.html (and the manifest that binds it).
  • Rebased on chore(release): prepare 0.4.0 and finish benchmark consolidation #118 (0.4.0). The snapshot caught chore(release): prepare 0.4.0 and finish benchmark consolidation #118's Web Search dataset-page change; the refresh is a separate commit.
  • No host path, hostname, platform string or local Python version remains in any normalized build.
  • Touched test modules pass: test_webmainbench_report, test_webmainbench_full_report, browser_use/test_report, trajectory_replay/test_webarena_report, test_wcxb_report_languages.
  • ruff check (E, F, B, I, UP) is clean on the new files, and make lint-check passes.
  • Snapshots generated in the locked environment (uv run --frozen --all-extras) match a second environment byte for byte.
  • make test-python locally: 18,798 passed. 14 failures also fail on unmodified main in this macOS setup (Node-based Markdown converter, CI-gate and local-data tests); 2 failed only under -n 8 load and pass on rerun.
  • CI on Linux reproduced the WCXB, WebMainBench and public WebArena digests on the first push; the remaining builds only differed in the builder identity, which is now pinned.

🤖 Generated with Claude Code

@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 · 718d8cc

This review found 1 issue(s), including 1 blocking issue(s).

Comment thread tests/golden_snapshots.py Resolved
lanyue-llk and others added 5 commits October 30, 2026 19:03
Build each report track's synthetic example and compare every route with a
committed SHA-256, so refactors that change rendered output fail the suite.
Machine-specific bytes (build paths, digests of path-bearing evidence, clock
and host identity) are normalized or pinned before hashing.

Refs #88.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reports record the builder's git revision and source hash, which change with
every commit. Pin them so the snapshots only track rendered content.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The runner records a hash of every Web Fetch module in its manifest, so the
snapshot changed with any source edit. Replace it with a token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reused GOLDEN_KEEP directory kept routes from earlier builds, so diff -r
could hide a removed route.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lanyue-llk
lanyue-llk force-pushed the refactor/golden-report-snapshots branch from 103735c to 2bd3201 Compare October 30, 2026 12:04

@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 · 2bd3201

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.

Not mergeable yet: CI is red on the current head (2bd3201). Tests and static checks fails in test_wcxb_report; the other nine snapshots and the rest of the suite pass.

The WCXB snapshot depends on the platform. tests/golden/wcxb.json was generated on macOS and cannot match on Linux (details inline). That also makes this line of the test plan inaccurate: "CI on Linux reproduced the WCXB … digests on the first push". It does not reproduce on the current head.

Everything else looks right:

  • The builder-identity pin covers both callers of software_identity (reporting/versions.py and web_fetch/runner.py), so commit-dependent bytes can't leak into the snapshots.
  • The clock and host pins for Web Fetch are scoped by monkeypatch.
  • Extracting sample_report_inputs leaves the existing test's behaviour unchanged.
  • I reproduced 10/10 passing locally on macOS (Python 3.11.16, zlib 1.2.12), which is consistent with the diagnosis below.

After the fix, please include the Linux CI run in the test plan as proof that the snapshots are portable.

Comment thread tests/test_golden_reports.py Resolved
The WCXB source hash covers the fixture's gzipped pages, and the reproduce
and review pages render it, so the WCXB snapshot failed on Linux CI. Two
platform-dependent parts of those bytes:

- gzip.compress delegates to zlib, which writes the build platform into the
  header OS byte (19 on macOS, 3 on Linux); GzipFile always writes 255.
- Deflate output differs between zlib builds such as zlib-ng; stored
  (level 0) blocks do not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lanyue-llk
lanyue-llk force-pushed the refactor/golden-report-snapshots branch from c03d844 to b7ac360 Compare October 30, 2026 12:32

@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 · b7ac360

No findings in this review.

@lanyue-llk
lanyue-llk merged commit 8b8aa30 into main Oct 30, 2026
6 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/golden-report-snapshots branch October 30, 2026 12:43
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.

Add golden route-hash snapshots for every report track

1 participant