Repository navigation
fix(plugin)!: noduplicates compares every directive type, as beancount's does - #2616
Merged
Merged
Conversation
…t's does The native `noduplicates` compared only transactions, so a repeated open, close, commodity, pad, balance, note, document, event, query or custom passed where bean-check reports it. It now compares every type but price on the fields beancount hashes, metadata excluded, by an exact byte key (`fingerprint::structural_key`) rather than a 64-bit digest. Like beancount, a transaction's postings are a multiset, and a total price or booked total cost is compared as the per-unit number it stands for when that number multiplies back to it exactly. Comparing against beancount's own plugin under the Python compat layer found that the layer read prices, events and queries under the wrong wire fields: every price was Amount(None, None), and returning any such entry failed the whole plugin. Fixed, with `@@` presented per unit and an untouched price returned as written. WASM CACHE_VERSION 38 -> 39: `Ledger` archives plugin errors. Closes #2599 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…plicates Beancount's parser writes `0 X @@ 10 USD` as `0 X @ 0 USD`, so its noduplicates takes the two postings for one (bean-check reports the duplicate), and the Python compat layer already presents the price that way. The native key left a zero-unit total price as written, so the pair passed. Review round 1. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Member
Author
Review rounds (#2599)
Merge note: #2611 also bumps the WASM |
…directives # Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
…directives # Conflicts: # CHANGELOG.md
…directives # Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
…directives # Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
noduplicatescompares every directive type, as beancount's does. The native plugin compared only transactions, so a repeatedopen,close,commodity,pad,balance,note,document,event,queryorcustompassed where bean-check reportsDuplicate entry. It now compares every type butprice(beancount allows repeated prices too).The semantics follow beancount's
compare.hash_entries(entries, exclude_meta=True), read from beancount 3's source (stable_hash_namedtuple):diff_amountignored, as in beancount)plus the date. As in beancount, lists are compared without regard to order (beancount sorts the element hashes): tags and links (sets), an
open's currencies, acustom's values, and a transaction's postings. Numbers keep their scale (10 USDis not10.00 USD).Two consequences on transactions that beancount already has:
2 HOOL @@ 10 USDis2 HOOL @ 5 USD(beancount's parser rewrites@@per unit before plugins run), and a booked{{10 USD}}on 2 units is{5 USD}. The per-unit number uses Python's division scale (10.00 / 2is5.00).The key is now an exact byte stream (
fingerprint::structural_key), not a 64-bit digest, so two different directives can never collide.Each duplicate is reported at the later copy, naming it:
Duplicate entry: 2024-01-04 note Assets:Bank "hello"(transactions keepDuplicate entry: 2024-01-02 "Lunch").Deliberate divergences (documented in
docs/reference/plugins.mdand thestructural_keydoc):event "a" "b"and aquery "a" "b"on one date are duplicates there;3 HOOL @@ 10 USDa duplicate of3 HOOL @ 3.333333333333333333333333333 USD, two transactions whose totals differ;str(None)equals a payee written"None").Python compat layer: prices, events and queries
Comparing against beancount's real
noduplicates.pyunder the compat layer (#2592) found that the layer read three wire fields under the wrong names, so no Python plugin could run on a ledger with a single@price, event or query:Amount(None, None);description(the host sendsvalue), a query's string fromquery_string(the host sendsquery);serialization error: failed to parse entries.A plugin now sees a price as beancount presents it, a per-unit
Amount(@@divided by the units, zero units giving zero, as beancount's parser does), and a price it leaves alone goes back exactly as written,@@total included. A price the plugin replaces goes back as the per-unit price it holds.Cache
WASM
CACHE_VERSION38 -> 39:Ledgerruns the regular plugins and archives their errors, so a v38 blob of a ledger with a repeatednotewould serve no error. The loader cache archives parsed directives only, unchanged.API
rustledger_ops::dedup::StructuralDuplicate::narrationis replaced bysummary;fingerprint::structural_keyis new. Under### Breakingin the CHANGELOG, sincerledger checknow fails on ledgers it passed.How tested
@@vs@, total vs per-unit cost, payee""vs none, account vs string custom values, event vs query). bean-check vs native: identical on all but the three documented divergences (event vs query; the two inexact@@/{{}}cases) and one interpolation-scale case (2.5 HOOL @@ 10 USDvs2.5 HOOL @ 4 USD: rledger interpolates the first cash leg as-10and the second as-10.0, beancount both as-10.0; a pre-existing interpolation difference, not this plugin's).plugin "beancount.plugins.noduplicates": bean-check finds 302 duplicates in 56 files, and native agrees on all but 3 files, each explained by a pre-existing difference elsewhere: two lima lexer-error fixtures (beancount drops a transaction with a bad posting line, rledger keeps its good postings),tests_lots(rledger books{{9.00 GBP}}on10.00units at0.90, beancount at0.9, so one more pair matches), and the oklink export (rledger does not parse its*-masked account names, 16k parse errors).noduplicates.py(copied from the beancount 3 wheel, not committed) run by rledger on the same 60 ledgers agrees with bean-check except for the compat layer'sCostSpecshape (see follow-ups); before the compat fix every ledger with an event, query or price failed with a serialization error.git apply -R, tests kept):plugin_conformance::noduplicates_compares_every_directive_type: a ledger with a copy of every type and near-copies; native reports exactly bean-check's 12 lines, and beancount's plugin logic in the compat layer reports the same lines. Failed: the reported lines did not match.plugin_conformance::python_compat_reads_events_queries_and_prices: a plugin seesevent location=Paris; query cash=SELECT account; price 5.00 USD; price 4 USD; price 3.333333333333333333333333333 USD, and the postings come back identical to the ledger without the plugin (JSON, to the digit). Failed (serialization error).native_plugins_test:test_noduplicates_reordered_postings_are_duplicates,test_noduplicates_total_price_is_its_per_unit_price,test_noduplicates_compares_non_transaction_directives(three tests that asserted the old behavior, flipped to bean-check's answers). All three failed.rustledger-opsunit tests for every type, metadata, dates, sets vs multisets, custom value types, open/balance fields,@@, booked total cost. These use the new API, so without the fix they do not compile.cargo testforrustledger-ops(132 lib),rustledger-plugin(all suites),rustledger-wasm(153), andplugin_conformance+python_plugin_wasiwithRLEDGER_REQUIRE_PYTHON_WASI=1; workspaceclippy --all-features --all-targets -D warnings; release-config clippy (--no-default-features --features mimalloc,ag-rledger);cargo doc -D warningsfor the changed crates.Follow-ups (not in this PR)
CostSpec(number_per, number_total, ...)where beancount presentsCost(number, ...), so beancount's plugin under rledger does not take2 X {{10 USD}}and2 X {5 USD}for duplicates as bean-check does.rust_decimal's scale (9.00 / 10.00is0.90), beancount at Python's (0.9).Closes #2599
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr