Skip to content

chore(baselines): regenerate for corpus drift, and cover {{total}} reductions end to end - #2339

Merged
robcohen merged 2 commits into
mainfrom
fix/corpus-baselines-and-booking-fixtures
Sep 17, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/corpus-baselines-and-booking-fixtures

Conversation

@robcohen

Copy link
Copy Markdown
Member

Closes #2307. Closes #2328.

Two pieces of corpus work that share the same scripts.

Baseline drift (#2307)

The nightly drift check has reported two moved manifest entries since 2026-09-14:

entry why
apyb-financeiro/financeiro_2026-08.beancount new upstream, no parser-output coverage at all since it appeared
apyb-financeiro/financeiro_main.beancount contents changed upstream, so a different output hash is expected

The diff is one added line and one changed line. A third would have meant our own parser output shifted on files nobody touched, which is what this baseline exists to catch.

The fetch reported 3 repository clone failures (under its abort threshold). Before regenerating I checked that every path in the manifest was still present on disk — zero missing — because a partial corpus silently drops baselines for the files it failed to clone, and the script's MIN_CORPUS_SIZE=100 floor is far too coarse to notice. 735 entries in, 736 out, 736 files on disk.

financeiro_main.beancount's change was confirmed independently by comparing the recorded source hash against sha256sum: 1782cc57… → 465d1740….

tests/baselines/cst-corpus.manifest is deliberately untouched — regen-corpus-baselines.sh does not write it, since that baseline belongs to the parallel CST parser of #1262.

Missing coverage (#2328)

Both rules landed with unit tests in their own crate and nothing exercising them through a loaded ledger or the executor. The entire repository held one {{total}} reduction fixture, and it runs under option "booking_method" "NONE", which skips reduction matching — so nothing covered a total-cost reduction that actually matches a lot.

Booking, end to end through parse → book → validate:

  • booking_total_cost_reduction.beancount — the total names its lot (two lots at 40.00 and 60.00; selling {{60.00 USD}} takes the dear one, not the lot FIFO would pick), a full-precision round trip through 100.00/3, and covering a short, where the reduction has positive units and units.abs() is what makes it match.
  • booking_total_cost_reduction_wrong_total.beancount — two lots at 50.00 do not cost 90.00 together.

The first test asserts the booked posting carries 60.00 and the dear lot's 2026-01-02 acquisition date, not merely "no errors": the date drives the short/long split in report capgains, and a wrong lot with a right cost passes a weaker assertion.

BQL, through the executor: date_arithmetic_test.rs pins the behaviors measured against beanquery 0.2.0 while #2324 was written, both deliberate divergences from it, a leap-day span, the aggregate max(date) - min(date) shape, and that date - date still agrees with date_diff.

Verification

  • Both fixtures checked against Python beancount 3.2.3: it accepts the first, leaving 1 W {40.00 USD, 2026-01-01} in Assets:Pick with the other two accounts empty, and rejects the second with No position matches.
  • Both loader tests then run against sabotaged fixtures — naming the cheap lot, and correcting the wrong total — and both fail there, so the assertions bind rather than decorate.
  • cargo test -p rustledger-parser --test corpus_baseline passes against the regenerated manifest; loader and query suites pass; clippy and fmt clean at 1.98.1.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

robcohen and others added 2 commits September 17, 2026 11:58
Two manifest entries moved upstream and the nightly drift check has been
reporting it since 2026-09-14 (#2307):

- `apyb-financeiro/financeiro_2026-08.beancount` is new and had no
  parser-output coverage at all since it appeared upstream;
- `apyb-financeiro/financeiro_main.beancount` changed content upstream, so a
  different output hash is expected. Confirmed by comparing the recorded source
  hash against `sha256sum` before regenerating: 1782cc57... became 465d1740....

Nothing else moved: one added line, one changed line, which is what a
corpus-only drift should look like. A third changed line would have meant our
own parser output shifted on files nobody touched.

The fetch reported 3 repository clone failures (under its abort threshold), so
before regenerating I checked that every path in the manifest was still present
on disk -- zero missing. A partial corpus would otherwise drop baselines for the
files it failed to clone, which the script's MIN_CORPUS_SIZE=100 floor is too
coarse to catch. 735 entries in, 736 out, 736 files on disk.

`tests/baselines/cst-corpus.manifest` is deliberately untouched:
`regen-corpus-baselines.sh` does not write it, since that baseline belongs to
the parallel CST parser of #1262.

`cargo test -p rustledger-parser --test corpus_baseline` passes against the
regenerated manifest.

Closes #2307

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Both rules landed with unit tests inside their own crate and nothing that
exercised them through a loaded ledger or the executor. The whole repository
held one `{{total}}` reduction fixture, and it runs under
`option "booking_method" "NONE"`, which skips reduction matching entirely --
so no corpus, parity or compatibility test covered a total-cost reduction that
actually matches a lot (#2328).

Booking, through parse -> book -> validate:

- `booking_total_cost_reduction.beancount` holds the three shapes that must
  book: the total NAMES its lot (two lots at 40.00 and 60.00, selling
  `{{60.00 USD}}` takes the dear one, which is not the lot FIFO would pick), a
  full-precision round trip through 100.00/3, and covering a short, where the
  reduction has positive units and `units.abs()` is what makes it match.
- `booking_total_cost_reduction_wrong_total.beancount` holds the shape that
  must not: two lots at 50.00 do not cost 90.00 together.

The first test asserts the booked posting carries 60.00 AND the dear lot's
2026-01-02 acquisition date, rather than just "no errors" -- the date drives
the short/long split in capgains, and a wrong lot with a right cost would pass
a weaker assertion.

BQL, through the executor: `date_arithmetic_test.rs` pins the behaviors
measured against beanquery 0.2.0 while #2324 was written, both deliberate
divergences from it, the leap-day span, the aggregate `max(date) - min(date)`
shape, and that `date - date` still agrees with `date_diff`.

Both fixtures were checked against Python beancount 3.2.3, which accepts the
first (leaving `1 W {40.00 USD, 2026-01-01}` in Assets:Pick, the other two
accounts empty) and rejects the second with "No position matches". Both new
loader tests were then run against sabotaged fixtures -- naming the cheap lot,
and correcting the wrong total -- and both fail there, so the assertions bind.

Closes #2328

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner September 17, 2026 12:04
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 43.9ms ± 0.7ms 726.5ms ± 9.0ms 16.6x 51.0 MB / 50.1 MB
investment 66.0ms ± 0.5ms 2758.8ms ± 52.7ms 41.8x 54.8 MB / 58.1 MB
fifo 63.3ms ± 0.4ms 15899.6ms ± 56.4ms 251.1x 57.0 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 43.3ms ± 0.4ms 43.9ms ± 0.7ms +1.4% ✅ within noise 51.0 MB → 51.0 MB (+0.1%)
investment 66.4ms ± 0.4ms 66.0ms ± 0.5ms -0.6% ✅ within noise 57.0 MB → 54.8 MB (-3.8%)
fifo 65.0ms ± 1.6ms 63.3ms ± 0.4ms -2.6% ✅ within noise 57.1 MB → 57.0 MB (-0.2%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.3ms, investment 0.3ms, fifo 0.7ms), 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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 99% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 813
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
robcohen merged commit 17ced00 into main Sep 17, 2026
59 checks passed
@robcohen
robcohen deleted the fix/corpus-baselines-and-booking-fixtures branch September 17, 2026 12:56
robcohen added a commit that referenced this pull request Oct 8, 2026
…2487)

* chore(baselines): add the four corpus files upstream added (#2473)

A fresh fetch of the compatibility corpus adds four files with no
parser-output baseline. Regenerated with the procedure the drift issue
names (fetch-compat-test-files.sh, then regen-corpus-baselines.sh). The
manifest diff is exactly four added lines and nothing else: no changed
output hash on any existing entry, no removals.

Each new file was checked against Python beancount 3:
- double-entry-generator cib_debit and ibkr, vrischmann fortuneo-bourse:
  both engines accept the ledger with no errors, and every posting
  (date, flag, payee, narration, account, position, price, tags, links)
  agrees between rledger query and bean-query.
- vrischmann ccm-courant is an importer output fixture using the root
  "Actifs" with no name_assets option and one-posting transactions. Both
  engines reject it; the postings still agree. beancount reports
  "Invalid account name" for each posting, rledger reports E1001 (never
  opened), E3001 and E3004 for the same lines.

cst-corpus.manifest is left alone, as in #2339: the regen script does
not write it.

Closes #2473

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

* chore(corpus): drop three repositories that no longer exist

Review follow-up for #2473. tarioch/beancern,
LaunchPlatform/beancount-extract and iocoop/beancount return 404 and
contributed no corpus files (no manifest entry under their
directories). Failing to clone on every run, they kept
`.fetch-failures` at 3, and corpus-baseline-drift.py drops the whole
"removed" group whenever any clone failed, so the weekly drift report
could never say that upstream deleted a file.

With them gone a fresh fetch records 0 failures, the corpus is the
same 740 files, and `corpus-baseline-drift.py --dry-run` still reports
no drift.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

[Testing]: {{total}} reductions have no corpus or parity coverage Parser corpus baseline has drifted

1 participant