Repository navigation
test(plugin): proptests for implicit_prices, sell_gains, coherent_cost, check_average_cost (closes #1004) - #1042
Merged
Conversation
…t, check_average_cost (closes #1004) Phase 4 of the plugin-testing-quality plan from #992. Each numeric plugin now has at least one property test pinning its core algebraic invariant — the kind of bug that example tests routinely miss because the input space is too large. Plugins covered (4 new proptests, joining 5 existing): - `implicit_prices`: per-unit price round-trips through the `@@` total form. For any (units N, per-unit P), input `N C @@ (N*P) Q` → emitted Price `C @ P Q` exactly. This is the EXACT regression test for the #992 bug, where `@@` total was emitted as a per-unit price (off by factor of N). - `sell_gains`: warning emitted iff `(sale_price - cost_per) * |units|` is non-zero AND no Income/Expenses posting is present. Sweeps gain, loss, and zero-gain (sale at cost) cases via independent cost/sale cent generators, plus a boolean for the gain-account's presence. - `coherent_cost`: error count equals `|currencies_with_cost ∩ currencies_with_price_only|`. Generators produce up to 8 postings with currency_id ∈ 0..4 and posting kind ∈ {cost-only, price-only, cost+price}. The reference computation in the test mirrors the plugin's classification, catching any drift. - `check_average_cost`: selling at the exact weighted-mean cost basis produces no warning. Generators sweep 1..=5 buys at varied (units, price) tuples. The test computes the expected mean using `rust_decimal` (same crate as the plugin), so any precision loss is identical on both sides — a rounding bug or off-by-one in the running totals would surface as an unexpected warning. Total tests in `native_plugins_test`: 167 → 171. All proptests run 64 cases per CI run (default). Clippy clean (uninlined-format-args), fmt clean. Closes #1004 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds property-based tests to rustledger-plugin’s native plugin test suite to pin key algebraic invariants for numeric plugins that previously lacked proptest coverage (Phase 4 of the plugin-testing-quality plan; closes #1004).
Changes:
- Added a proptest for
implicit_pricesto ensure@@total-price annotations emit the correct per-unit Price (regression coverage for #992). - Added a proptest for
coherent_costto ensure the number of emitted errors matches the set-intersection invariant of currencies used with cost vs price-only. - Added a proptest for
sell_gains(warning iff non-zero gain and no Income posting) and forcheck_average_cost(sell at computed weighted mean produces no warnings).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-05-08)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 74% |
| Full AST Match | 99% |
| Total Files | 786 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
…e arithmetic comment) Two Copilot inline findings, both real: 1. The implicit_prices proptest's doc comment claimed both `@` and `@@` forms were tested, but the test only constructed `@@` (via `make_transaction_with_cost_and_price_total`). The inline cost-stub comment also misnamed it "per-unit annotation" when `is_total: true` was set. Restructured to use `make_txn_with_price_annotation` with a generated `is_total` bool, exercising both forms in the same proptest (renamed: `prop_implicit_prices_emits_per_unit_for_both_annotation_forms`). The `@@` case remains the EXACT regression for #992; the `@` case pins the trivial-but-mutable identity path. 2. The check_average_cost proptest's comment described the mean computation as "sum cost in cents, then divide by total units, then divide by 100" — but the code uses `Decimal::new(price_cents, 2)`, which already represents the price in dollars (scale 2 ⇒ value = cents/100). There's no separate `/ 100` step. Rewrote the comment to accurately describe what the code does. Co-Authored-By: Claude Opus 4.7 (1M context) <[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.
Summary
Phase 4 of the plugin-testing-quality plan (#992). Adds property tests covering algebraic invariants for the four numeric plugins listed in #1004 that lacked any proptest coverage. The fifth plugin in the issue (
unrealized) already had a proptest from #1007.Properties pinned
implicit_pricesN C @@ (N*P) Q→ emitted Price =C @ P Qexactlysell_gainscoherent_costcheck_average_costFor
check_average_costthe test computes the expected mean usingrust_decimal(same crate as the plugin) so any precision loss is identical on both sides — a real bug, not a precision artifact, would be required to fail.Test count
native_plugins_test: 167 → 171 (4 new proptests, each 64 cases per run)proptest::collection::vecfor posting-list inputs andDecimal::new(cents, 2)for prices to keep arithmetic well insiderust_decimalprecision.Test plan
cargo test -p rustledger-plugin— all 171 tests pass (proptests + examples)cargo clippy -p rustledger-plugin --all-features --all-targets -- -D warnings— clean (after fixing twouninlined_format_argslints)cargo fmt -p rustledger-plugin -- --check— cleanCloses #1004
🤖 Generated with Claude Code