Skip to content

test(compat): table every check beancount reports, and guard it against drift - #3054

Merged
robcohen merged 4 commits into
mainfrom
feat/upstream-check-coverage
Nov 27, 2026
Merged

robcohen merged 4 commits into
mainfrom
feat/upstream-check-coverage

Conversation

@robcohen

@robcohen robcohen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What

A coverage table for every check beancount 3.2.3 can report, with a mechanism that keeps it complete.

  • crates/rustledger/tests/fixtures/upstream-checks/enumerate.py lists the checks in the installed beancount by reading its source with ast. That covers every error-tuple construction in core/ ops/ parser/ plugins/ loader.py (keyed module.function:message template), every raise in ops/ parser/ plugins/ loader.py (option converters, plugin config), every plugin module, and every deprecated option. That is 126 ids, plus one manual row for gpg decryption, which the scan cannot see.

  • checks.toml gives each id a status, the rledger code and function, and the test or case that pins it:

    status rows
    covered 96
    deliberate deviation 2 (AVERAGE booking, {*} merging; new compatibility.md section 20)
    not applicable 24 (dead code under if False, functions nothing calls, branches the sorted pipeline cannot reach, beancount's test and tooling helpers)
    missing 5
  • upstream_checks_test.rs has four tests:

    • the table is well formed: required fields per status, the case files and named tests exist, deviation links resolve to a compatibility.md heading, and no case is orphaned;
    • every case run through rledger check: the row's code appears on exactly the row's lines;
    • every case run through bean-check: the row's message appears on exactly the row's lines;
    • the drift guard: enumerate.py's ids and the table's ids are the same set. A beancount upgrade that adds, removes or rewords a check fails it and names the check.

    "Covered" therefore means both tools report on the same line, unless the row's note says how they differ (beancount's <load>:0 against rledger's include line, or a booking error on the transaction line against one on the posting line). The missing and deviation rows are pinned the same way, so a fix that changes behavior has to update its row.

  • The two Python tests are added to python-gated-cargo-tests. They print the existing Skipping: Python beancount not available marker, which that job already fails on. The rledger half runs in every cargo test.

Why introspection rather than a hash of the scanned files: a hash goes red on any edit to those files, a docstring or a refactor included, and does not say which check changed. Keying on error sites goes red only when a check is added, removed or reworded, and the failure names it.

Why

#3044 and #3045 were checks nobody had ported. They were found by reading ops/validation.py by hand. This does that walk for every module in scope (validation, balance, pad, documents, options, grammar builder, booking, interpolation, loader, all plugins) and keeps it done.

Missing rows (left for follow-up)

  • Duplicate merge-cost spec ({*, *} is accepted silently)
  • Amount is zero (a zero-unit posting held at cost is accepted)
  • plugin "beancount.plugins.auto" (no native counterpart)
  • allow_deprecated_none_for_tags_and_links (reported as an unknown option, E7001, rather than as deprecated)
  • Cannot infer price for postings with units held at cost: a bare @ USD beside a cost is deliberately inert in rledger (fix(booking): answer a bare price sigil instead of ignoring it #1919). This one needs a maintainer decision.

The fixes for the first four are in #3057, stacked on this PR.

The case ledgers are tracked .beancount files, so they are pinned in tests/baselines/parse-error-parity.manifest (second commit). All of them are match except grammar-duplicate-merge, which stays bc-only until #3057. Allowing None for tags and link joins NOT_PARSE_ERRORS, next to the pipe-separator deprecation.

How to test

cargo test -p rustledger --test upstream_checks_test           # rledger half and table checks
RLEDGER_UPSTREAM_PYTHON=/path/to/python3-with-beancount \
  cargo test -p rustledger --test upstream_checks_test         # plus beancount half and drift guard

To see the guard fail, rename any row's id in checks.toml: the test lists the id as untracked on one side and stale on the other.

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 03:34
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 34.1ms ± 1.3ms 415.6ms ± 16.3ms 12.2x 43.2 MB / 51.0 MB
investment 51.8ms ± 0.8ms 1578.3ms ± 8.4ms 30.5x 47.3 MB / 59.0 MB
fifo 49.1ms ± 0.5ms 8219.4ms ± 105.8ms 167.5x 49.3 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 34.0ms ± 1.6ms 34.1ms ± 1.3ms +0.3% ✅ within noise 43.3 MB → 43.2 MB (-0.2%)
investment 52.3ms ± 0.7ms 51.8ms ± 0.8ms -0.9% ✅ within noise 47.3 MB → 47.3 MB (-0.0%)
fifo 48.7ms ± 0.7ms 49.1ms ± 0.5ms +0.7% ✅ within noise 49.2 MB → 49.3 MB (+0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.9ms, investment 0.5ms, fifo 0.4ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen
robcohen force-pushed the feat/upstream-check-coverage branch from 9c179fb to e602f48 Compare November 27, 2026 03:45
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 828
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

robcohen and others added 4 commits November 26, 2026 23:53
…st drift

ops/validation.py one function at a time. This does that walk for every
module and leaves a guard behind.

- crates/rustledger/tests/fixtures/upstream-checks/enumerate.py lists every
  check the installed beancount can report, from its source (ast): each
  error-tuple construction (module.function + message template), each raise
  in ops/parser/plugins/loader, each plugin module, each deprecated option.
  126 for beancount 3.2.3, plus one manual row (gpg decryption).
- checks.toml gives each a status: 96 covered, 2 deliberate deviations,
  24 not applicable (dead code, unreachable, beancount tooling), 5 missing.
- Each covered row names a small ledger in cases/. upstream_checks_test runs
  it through rledger check and bean-check and asserts the lines each tool
  reports the row's code/message on, so "covered" means the same lines, or
  the row's note says how they differ. Missing and deviation rows are pinned
  the same way, so a fix cannot leave the table stale.
- The drift guard compares enumerate.py's output with the table's ids, both
  ways, so a beancount upgrade that adds, removes or rewords a check goes
  red and names it. It introspects rather than hashing the scanned files: a
  hash goes red on any docstring edit and does not say which check changed.
- The Python half runs in the python-gated-cargo-tests job (skip marker
  already in its grep); the rledger half runs in every cargo test.
- compatibility.md gains section 20: AVERAGE booking and {*} merging, which
  beancount 3.2.3 refuses and rledger implements (ADR 0007).
- docs/reference/upstream-checks.md documents the table and how to update it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…parity manifest

The case ledgers are tracked .beancount files, so the parse-error-parity job
compares them. All match but grammar-duplicate-merge ({*, *}, a missing row,
bc-only until the follow-up fix). beancount's deprecation error for
allow_deprecated_none_for_tags_and_links joins NOT_PARSE_ERRORS beside
allow_pipe_separator's: rledger reports option errors when it loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t the Python runtime

The slim release build (no default features) reports a Python module name
as E8005, runtime not compiled in, where the default build reports E8004.
A row's code may now list alternatives (E8004|E8005); each is still an
exact assertion on the line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rface differences

#3055's corpus includes crates/rustledger/tests, so it runs the
upstream-check cases. Five hit existing classes (no disk for document roots,
a file map's own words for a load error, the LSP's E8006 for an
unsupported plugin), and one is new and OPEN: a check_closing balance is at
<check_closing>, 0 in check and in the ledger file on every other surface.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen force-pushed the feat/upstream-check-coverage branch from 8c697b4 to ba20d50 Compare November 27, 2026 05:59
@robcohen
robcohen merged commit de3813c into main Nov 27, 2026
50 of 51 checks passed
@robcohen
robcohen deleted the feat/upstream-check-coverage branch November 27, 2026 06:44
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.

1 participant