Repository navigation
test(plugin): test matrices for generate_base_ccy_prices, split_expenses, zerosum, check_average_cost - #1012
Merged
Merged
Conversation
…ses, zerosum, check_average_cost Phase 1 of #992 plan (closes the remaining 4 of 11 Tier 1 plugins in #1002). All four plugins had only one trivial integration test each — usually with weak count assertions — and now have full matrices with strict equality checks plus property tests for the two with clean algebraic invariants. ## Coverage ### `generate_base_ccy_prices` (1 → 5 tests, +1 proptest) Plugin reads existing prices and emits derived `(C, base)` entries when chains `(C, X)` + `(X, base)` exist. Matrix: - no config → passthrough (was: lone test with weak `> 2` count) - ETH→EUR + EUR→USD → exactly one ETH→USD = 2200, count + amount + currency all asserted strictly - target price already exists → no duplicate - prices already in base currency → no derivation Proptest `prop_generate_base_ccy_prices_multiplies_chain_exactly` pins the multiplicative invariant: derived rate = `(C→X) * (X→base)` for any cents-based pair of rates. ### `split_expenses` (1 → 4 tests, +1 proptest) Plugin splits any Expenses:* posting (whose account doesn't already include a member name) into N proportional sub-postings with `__automatic__: True` metadata, plus emits Open directives for the new sub-accounts. Matrix: - no config → passthrough - 2 members, $100 → $50 each (was: weak `>= 2` posting count; now strict on amounts, currencies, metadata, and emitted Opens) - account already contains a member name → unchanged, no __automatic__ added - non-Expenses posting (Income/Assets) → unchanged Proptest `prop_split_expenses_sum_preserves_total` pins: sum(splits) = (amount/N) * N for random (amount, member_count). ### `zerosum` (1 → 4 tests) Plugin matches paired postings in zero-sum accounts within a configurable date window and moves them to a "matched" account. Matrix: - missing config → 1 error (existing test, kept) - pair within 30-day window → both halves move to matched account, none remain in zerosum - pair outside the window → unmatched, both remain in zerosum - single unmatched posting → remains in zerosum (No proptest — the matching/window/account-substitution logic is discrete enough that the example matrix is the right shape.) ### `check_average_cost` (1 → 5 tests) Plugin warns when a reducing posting's cost differs from the account's running average by more than `tolerance`. Critical constraint: only checked for accounts opened with `NONE` booking (the lot-management-by-author case from #907). Added `make_open_with_booking` helper. Matrix: - correct sale at average cost → silent - sale below average by 33% (default tolerance is 1%) → 1 warning mentioning the account and commodity - STRICT-booking account → skipped entirely (issue #907 false- positive guard) - account with `booking: None` → also skipped (only NONE-booking is checked) - custom tolerance: 40% deviation within a 50% tolerance → silent ## Verified - 124 → 143 plugin integration tests (+19 new + 2 proptests) - `scripts/check-plugin-test-quality.sh`: OK - `scripts/test-plugin-test-quality.sh`: 28/28 - `cargo clippy -p rustledger-plugin --all-features --all-targets`: clean ## Tightened from existing weak shapes Two existing tests had weak count assertions in the multi-line form that PAT_A's missing multi-line variant doesn't catch (#1011): - `test_generate_base_ccy_prices_creates_derived_price`: `assert!(price_count > 2)` → strict count + amount - `test_split_expenses_divides_by_members`: `assert!(...len() >= 2)` → strict count + amounts + metadata Both replaced by stronger assertions in the new matrices. ## #1002 progress After this PR: **all 11 Tier 1 plugins covered** (capital_gains family in #1007, transaction-emitter family in #1008, this numeric/emits family completes the set). Closes part of #1002. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-05-06)
What do these numbers mean?
|
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 99% |
| BQL Compatibility | 88% |
| 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
robcohen
added a commit
that referenced
this pull request
May 6, 2026
…tions (#1013) Closes #1011. ## What `scripts/check-plugin-test-quality.sh` had multi-line variants for shapes B (`assert_ne!`), C (`!is_empty()`), and D (`!= 0`) added in #1005. Shape A — `assert!(x.len() >= N)` / precomputed-count — only had its single-line PAT_A. So a multi-line write of the original #992 bug shape: assert!( txn_count >= 3, "forecast should expand to at least 3 transactions" ); slipped past the lint. PR #1008 caught one such instance by hand; PR #1012 caught two more. ## Fix Added `ML_PAT_A` mirroring single-line `PAT_A` with the same count-shaped LHS restriction (`COUNT_LHS`) and the negative lookbehind for `prop_assert!`/`debug_assert!` that the other multi-line patterns already use: ML_PAT_A='(?<!\w)assert!\(\s*'"$COUNT_LHS"'\s*(?:>|>=)\s*\d+' Wired into the existing `find_multiline_in_rs` call. ## Knock-on: tightened one existing test The new pattern caught a real instance in `test_check_drained_adds_balance_assertions_on_close`: assert!( balance_count > 0, "should insert balance assertions after close" ); The plugin emits exactly one balance assertion per (closed account, currency); test setup has one Close on Assets:Bank with USD only, so we expect 1. Tightened to `assert_eq!(.count(), 1, ...)`. ## Self-test Extended `scripts/test-plugin-test-quality.sh` with 4 new cases (28 → 32 total): - multi-line `assert!(\n x.len() >= 1,\n "msg"\n)` - multi-line `assert!(\n price_count >= 1\n)` (the actual #992 shape) - multi-line `assert!(\n x.count() > 0\n)` - false-positive guard: multi-line `prop_assert!(\n x.len() >= 1\n)` must NOT fire ## Verified - 143/143 plugin tests pass (one pre-existing test tightened, no new test functions) - `scripts/check-plugin-test-quality.sh`: OK (clean on current main) - `scripts/test-plugin-test-quality.sh`: 32/32 - `cargo clippy -p rustledger-plugin --all-features --all-targets`: clean 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.
test(plugin): test matrices for generate_base_ccy_prices, split_expenses, zerosum, check_average_cost
Phase 1 of #992 plan (closes the remaining 4 of 11 Tier 1 plugins
in #1002). All four plugins had only one trivial integration test
each — usually with weak count assertions — and now have full
matrices with strict equality checks plus property tests for the
two with clean algebraic invariants.
Coverage
generate_base_ccy_prices(1 → 5 tests, +1 proptest)Plugin reads existing prices and emits derived
(C, base)entrieswhen chains
(C, X)+(X, base)exist. Matrix:> 2count)Proptest
prop_generate_base_ccy_prices_multiplies_chain_exactlypins the multiplicative invariant: derived rate =
(C→X) * (X→base)for any cents-based pair of rates.
split_expenses(1 → 4 tests, +1 proptest)Plugin splits any Expenses:* posting (whose account doesn't
already include a member name) into N proportional sub-postings
with
__automatic__: Truemetadata, plus emits Open directivesfor the new sub-accounts.
Matrix:
>= 2posting count;now strict on amounts, currencies, metadata, and emitted Opens)
automatic added
Proptest
prop_split_expenses_sum_preserves_totalpins:sum(splits) = (amount/N) * N for random (amount, member_count).
zerosum(1 → 4 tests)Plugin matches paired postings in zero-sum accounts within a
configurable date window and moves them to a "matched" account.
Matrix:
none remain in zerosum
(No proptest — the matching/window/account-substitution logic is
discrete enough that the example matrix is the right shape.)
check_average_cost(1 → 5 tests)Plugin warns when a reducing posting's cost differs from the
account's running average by more than
tolerance. Criticalconstraint: only checked for accounts opened with
NONEbooking(the lot-management-by-author case from #907).
Added
make_open_with_bookinghelper. Matrix:mentioning the account and commodity
positive guard)
booking: None→ also skipped (only NONE-bookingis checked)
Verified
scripts/check-plugin-test-quality.sh: OKscripts/test-plugin-test-quality.sh: 28/28cargo clippy -p rustledger-plugin --all-features --all-targets:clean
Tightened from existing weak shapes
Two existing tests had weak count assertions in the multi-line form
that PAT_A's missing multi-line variant doesn't catch (#1011):
test_generate_base_ccy_prices_creates_derived_price:assert!(price_count > 2)→ strict count + amounttest_split_expenses_divides_by_members:assert!(...len() >= 2)→ strict count + amounts + metadata
Both replaced by stronger assertions in the new matrices.
#1002 progress
After this PR: all 11 Tier 1 plugins covered (capital_gains
family in #1007, transaction-emitter family in #1008, this
numeric/emits family completes the set).
Closes part of #1002.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]