Repository navigation
feat(ffi)!: load reports balance failures + balance diff on directives (#1663, WIT 3.1.0) - #1664
Merged
Merged
Conversation
… directives (#1663) WIT rustledger:ledger 3.0.0 -> 3.1.0 (adds balance-dir.diff); API_VERSION -> 3.1. Part 1 (correctness): load/load-file did not run semantic validation, so balance-assertion failures were reported only by validate. Embedders that load via load (rustfava) saw a failing balance as errors: [] — a silent correctness failure, the user told their books reconcile when they don't. load/load-file now run the same ValidationSession as validate (shared semantic_validation_errors), matching beancount's loader.load_file. query/clamp stay validation-free. Part 2 (UX): balance-dir gains diff: option<amount> = computed - asserted in the asserted currency (zero = exact match, non-zero = failed), so UIs render per-assertion pass/fail without re-deriving. The Late balance validator records its OWN computed actual (new BalanceActual + ValidationSession::balance_actuals in rustledger-validate) — no re-derivation, so load/validate cannot diverge from the check. convert stamps each balance directive's diff. Tests: the repro's failing balance appears in load's errors AND its directive carries diff = -1004 USD. 92 validate + 18 FFI parity tests pass; clippy -D warnings clean. Closes #1663 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-01)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Component-Model FFI load surface to match validate semantics for balance assertions, and exposes per-balance computed vs asserted deltas to improve downstream UX (e.g., rustfava) without re-summing the ledger.
Changes:
- Run
rustledger-validate::ValidationSessionduring FFIload/load-fileto surface Late-phase semantic validation errors (including balance assertion failures). - Record Late-phase balance “actuals” (
computed − asserted) inrustledger-validateand stamp them ontobalance-dir.diffin the WIT output. - Bump WIT package version
rustledger:ledgerfrom3.0.0to3.1.0and add parity coverage for the new behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-validate/src/validators/balance.rs | Records per-balance computed diff during Late balance validation. |
| crates/rustledger-validate/src/lib.rs | Adds BalanceActual + ValidationSession::balance_actuals() and stores results in LedgerState. |
| crates/rustledger-ffi-component/wit/world.wit | Bumps WIT package version and adds balance-dir.diff. |
| crates/rustledger-ffi-component/src/lib.rs | Updates reported API version to 3.1 and documents the breaking change. |
| crates/rustledger-ffi-component/src/convert.rs | Runs semantic validation during load and attaches computed balance diffs onto returned directives. |
| crates/rustledger-ffi-component-tests/tests/parity.rs | Adds a regression/parity test ensuring load surfaces balance failures and emits diff. |
💡 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 |
This was referenced Jul 1, 2026
Merged
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.
Closes #1663. Breaking WIT change:
rustledger:ledger3.0.0 → 3.1.0 — rustfava must regenerate bindings.Part 1 —
load/load-filenow report balance-assertion failures (correctness)load/load_fileran only parse + booking; semantic checks (balance assertions are a Late check) lived only invalidate. So an embedder that loads viaload(rustfava) goterrors: []for a failingbalance— a silent correctness failure. Nowload/load_filerun the sameValidationSessionasvalidate(sharedsemantic_validation_errorshelper), matching beancount'sloader.load_file.query/clampstay validation-free (they operate on an already-loaded ledger).Part 2 —
balance-dir.diff(UX)balance-dirgainsdiff: option<amount>= computed − asserted in the asserted currency (zero = matched exactly, non-zero = failed;noneif not checked). UIs can render per-assertion pass/fail without re-deriving the balance.Crucially, the value comes from the validator's own computed
actual—rustledger-validaterecordsBalanceActualduring the Late balance check (exposed viaValidationSession::balance_actuals()), andconvertstamps it. No re-derivation, so this can't drift from the check (the recurring lesson from #1648/#1656/@@).Tests
balance Assets:Cash 999 USDwhen it's really-5 USD) surfaces the failing balance inload'serrorsand the directive carriesdiff = -1004 USD.rustledger-validate+ 18 FFI parity tests pass; clippy-D warnings+ fmt clean. The WIT 3.1.0 record change broke none of the 16 existing parity tests.Release note
This is a breaking FFI/WIT change (3.1.0) — it'll want a 0.18.0 release, and rustfava must regenerate its component bindings to pick up
balance-dir.diffand theload-reports-balances behavior.🤖 Generated with Claude Code