Skip to content

fix(validate): report an invalid account name in a custom directive's values - #2890

Merged
robcohen merged 1 commit into
mainfrom
fix/custom-account-names
Nov 7, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/custom-account-names

Conversation

@robcohen

@robcohen robcohen commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What changed

An account value in a custom directive is now checked as an account name, as beancount 3.2.3 checks every account token:

Input bean-check 3.2.3 Before Now
custom "budget" AAssets:A "x" 10 USD TRUE Invalid account name: AAssets:A no error E1005
same with A-ssets:A, Assets0:A Invalid account name no error E1005
custom "x" Assets:A Foo:Bar Bar:Baz two errors, in order no error two E1005, in order
custom "x" Foo:Bar plus kk: Bar:Baz value, then metadata metadata only (#2813) value, then metadata
option "name_assets" "Actifs" + custom "x" Actifs:A Assets:B Assets:B only no error Assets:B only
custom "x" Assets:A, custom "x" "Foo:Bar" no error no error no error

How it works:

  • custom values: push_invalid_custom_accounts sends a custom directive's account values through push_invalid_accounts. That is now the one check for an account read from a value: the canonical validate_account_name with the ledger's configured account_types, so root prefixes are never string-matched. Account-valued metadata (compat(parser): metadata shapes beancount rejects that rledger accepts (True/true, invalid account roots, indented lines under option/plugin/include, posting filename/lineno) #2813) goes through it too.
  • pad: a pad stopped at an unopened target, so an invalid or unopened source behind it went unreported. Both accounts are now checked, as bean-check reports both (Invalid account name / unknown account for each).
  • Matrix guard: the stray-character matrix excludes the rows beancount rejects with Invalid account name, on the grounds that rledger reports them at load time. test_validate_reports_every_account_name_row_the_stray_char_matrix_excludes now checks that claim: it replays every excluded row outside option (1,760 rows) and asserts each one is a parse error or an E1005.
    • The excluded option rows are invalid option names, which the loader reports.
    • The test can fail: with the custom check removed it fails on the 19 custom rows, and the 19 pad rows also failed before the pad fix.
    • Its cases() copy is drift-guarded by the TSV's case count, like the parser's.
  • Cache: WASM CACHE_VERSION 79, because Ledger's cached error list changes. The loader cache archives parsed directives, which do not move, so it stays at 60 (LOADER_CACHE_VERSION_PIN 60).

Why

Issue #2809. This matches beancount; no deviation is introduced.

How to test

cargo test -p rustledger-validate --all-features --test validation_integration_test custom pad stray_char

Verification

  • Probes against full bean-check 3.2.3 output: 10 custom shapes and 3 pad shapes. The errors match on all of them except two, both outside this PR:
  • Corpus: all diagnostics (parse and validation) on all 1,113 ledgers, current origin/main release build vs this branch. Exactly 6 files differ: ParserEntryTypes.Pad, ParserComplete.NoEmptyLines (each in-tree and in the compat corpus), and beancount-blog-examples chapter-{2,3}_src_balance. Each gains E1001 Pad source account ... was never opened, which bean-check reports as Invalid reference to unknown account for that source.
  • Baselines: STRICT_BASELINE=1 corpus and CST baselines pass. Parser output is unchanged, so no baseline rows move.
  • Formatting: validation-only, so no formatter path is affected.
  • Checks:
    • cargo test --workspace --all-features --no-fail-fast passes, except rustledger::integration_test, which writes fixed-name files under the shared TMPDIR and collided with another lane's run. It passes with a private TMPDIR.
    • After merging origin/main (refactor: the source-text query surfaces answer by the file-based rule #2889), -p rustledger-validate -p rustledger-wasm -p rustledger -p rustledger-lsp were rerun and pass.
    • cargo clippy --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps and cargo fmt --check pass.

Closes #2809

🤖 Generated with Claude Code

… values

Beancount checks every account token against the configured roots, so
`custom "budget" AAssets:A "x" 10 USD TRUE` (or `A-ssets:A`, `Assets0:A`,
`Foo:Bar`) is `Invalid account name` there; rledger loaded it clean. The
account values of a `custom` directive now go through the same check as
account-valued metadata: `push_invalid_accounts` (the canonical
`validate_account_name` with the ledger's `account_types`), one E1005 per
value, in the order written, before the directive's metadata as in
bean-check.

A `pad` checked its source account only after its target was open, so an
invalid (or unopened) source behind an unopened target was hidden. Both
are now checked, as bean-check reports both.

A validator test replays the stray-character matrix's excluded
(account-name) rows and asserts each outside `option` is a parse error
or an E1005, so the matrix's exclusion is held up rather than assumed;
it fails without this fix (19 custom rows).

WASM CACHE_VERSION 79: its cached error lists change. The loader cache
archives parsed directives, which did not move.

Closes #2809

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 7, 2026 16:38
@codecov

codecov Bot commented Nov 7, 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

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 39.4ms ± 1.2ms 562.9ms ± 4.6ms 14.3x 42.1 MB / 51.0 MB
investment 60.7ms ± 1.2ms 2132.7ms ± 21.5ms 35.1x 58.8 MB / 59.0 MB
fifo 59.0ms ± 3.5ms 11635.9ms ± 25.1ms 197.2x 54.8 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 39.0ms ± 0.5ms 39.4ms ± 1.2ms +1.0% ✅ within noise 42.9 MB → 42.1 MB (-1.9%)
investment 61.0ms ± 0.8ms 60.7ms ± 1.2ms -0.5% ✅ within noise 58.9 MB → 58.8 MB (-0.2%)
fifo 58.1ms ± 0.4ms 59.0ms ± 3.5ms +1.6% ✅ within noise 54.8 MB → 54.8 MB (-0.1%)

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

github-actions Bot commented Nov 7, 2026

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 826
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 8913ef1 into main Nov 7, 2026
56 of 57 checks passed
@robcohen
robcohen deleted the fix/custom-account-names branch November 7, 2026 18:21
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(validate): invalid account names in a custom directive are not reported

1 participant