Repository navigation
fix(booking,validate): lot-label on reduction + balance currency + dedup oversell (#1666, #1668) - #1669
Merged
Conversation
…p oversell (#1666, #1668) #1666 — reducing a labeled cost lot dropped the matched lot's label (single-lot path set label: None while the multi-lot path preserved it), so the reduction didn't net against its augmenting lot and left a phantom unlabeled negative lot in the holdings view. Carry the matched lot's label onto the reduction posting (as the date already was). rustledger-booking/src/book.rs. #1668 #2 — a balance asserted in a currency the account doesn't allow only got a confusing 'Balance failed ... got 0 EUR'. Add a dedicated 'Invalid currency ... for Balance directive' diagnostic (E-code CurrencyNotAllowed) in validate_balance_early, mirroring the transaction currency check; only when the account constrains its currencies. #1668 #1 — an oversell reported 'Not enough units' twice via the FFI: booking (inside load_source) reports it WITH transaction context, and the #1663 validation session re-derived it context-free (its reduce-check is a standalone-validation safety net). Drop the session's copy when a load error already conveys it. The CLI never doubled (it partitions booking-failed txns out before late validation). #1668 #3 — investigated, no change: rustledger already flags duplicate open across includes (E1002 on the CLI), and #1663 made the FFI load path validate too, so it is caught there as well; the report reflects the pre-#1663 non-validating load. Tests: booking reduction-label netting; balance wrong-currency (+ unconstrained no-false-positive); FFI parity oversell-single-error. 94 validate + 106 booking + 19 FFI parity pass; clippy -D warnings + fmt clean. Closes #1666 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-07-01)
What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes several booking/validation parity issues discovered via differential testing against beancount, improving lot identity correctness, diagnostics, and FFI error reporting consistency.
Changes:
- Booking: preserve matched lot
labelwhen generating single-lot reduction postings to avoid phantom unlabeled negative lots (#1666). - Validate: add an early diagnostic for
balancedirectives asserting a currency not allowed by the account’s currency constraints (#1668). - FFI: de-duplicate oversell/reduction errors so
loadreports “Not enough units” exactly once, plus add parity coverage (#1668).
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-validate/src/validators/balance.rs | Adds early balance-currency constraint check and emits CurrencyNotAllowed. |
| crates/rustledger-validate/src/lib.rs | Adds unit tests covering wrong-currency balance and unconstrained accounts. |
| crates/rustledger-booking/src/book.rs | Carries matched lot label on single-lot reductions; adds regression test. |
| crates/rustledger-ffi-component/src/convert.rs | Filters out validation-session reduction errors that duplicate booking errors in load. |
| crates/rustledger-ffi-component-tests/tests/parity.rs | Adds parity test ensuring oversell error is reported exactly once via load. |
| crates/rustledger-plugin/tests/fixtures/sample_stub/Cargo.lock | Fixture lockfile bump for rustledger-plugin-types version. |
| crates/rustledger-importer/tests/fixtures/sample_stub/Cargo.lock | Fixture lockfile bump for rustledger-plugin-types version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Merged
robcohen
added a commit
that referenced
this pull request
Jul 1, 2026
Minor (breaking-FFI) release: WIT contract rustledger:ledger 3.2.0 — the component now imports host.decrypt so encrypted ledgers are decrypted by the embedder (#1667/#1670); embedders must provide the import and regenerate bindings. Also carries the booking/validate diagnostics fixes (#1666, #1668 via #1669): lot-label preserved on reductions, dedicated balance-currency diagnostic, deduped oversell error. Workspace 0.18.0 -> 0.19.0; packages/mcp-server bumped to match. Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
Fixes surfaced by differential-testing rustfava against beancount.
#1666 — reduction drops the matched lot's label (holdings bug) — Closes #1666
Reducing a labeled cost lot emitted the reduction with
label: null, so it didn't share lot identity with its augmenting lot and left a phantom unlabeled negative lot in the holdings view (aggregates stayed correct). Root cause: the single-lot reduction path inbook.rssetlabel: None, while the multi-lot path already preserved it. Fix carries the matched lot's label (as the date already was).Before:
10 X {lot-a}+10 X {lot-b}+-5 X {no label}— After:10 X {lot-a}+5 X {lot-b}✓ (matches beancount).#1668 #2 — balance directive currency not validated
balance Assets:Cash 100 EURon a USD account only gave a confusingBalance failed … got 0 EUR. Added a dedicatedInvalid currency EUR for Balance directive on Assets:Cash (account holds USD)diagnostic invalidate_balance_early, mirroring the transaction currency check — only when the account constrains its currencies (empty = any).#1668 #1 — duplicate "Not enough units" on oversell (FFI)
An oversell reported the error twice via the FFI: booking (inside
load_source) reports it with transaction context, and the #1663 validation session re-derives it context-free (its reduce-check is a standalone-validation safety net). Now the session's copy is dropped when a load error already conveys it. The CLI never doubled — it partitions booking-failed txns out before late validation; this was FFI-only.#1668 #3 — duplicate
openacross includes — investigated, no change neededDoes not reproduce: the CLI already flags it (
E1002 Account … already open, reproduced), and #1663 made the FFIloadpath validate (it now runs the fullValidationSession, includingvalidate_open), soloadcatches it too. The report reflects the pre-#1663 non-validatingload. Safe to close as resolved in v0.18.0.Tests
test_reduction_carries_matched_lot_label).load.-D warnings+ fmt clean.🤖 Generated with Claude Code