Repository navigation
test(plugin): test matrices for one_commodity, check_closing, check_commodity - #1038
Merged
Merged
Conversation
…ommodity Closes the remaining Tier 2 gaps identified in the #1002 plugin testing matrix audit. Each plugin had only 2 happy-path tests in the central test file and no inline tests, leaving most code branches uncovered. one_commodity: empty input, auto-balanced posting skip, per-account independence, three-currency cascade, non-Transaction directive ignore. check_closing: empty input, `closing: false`, non-Bool metadata value, `units = None` defaulting to USD, multiple closing postings in one transaction, non-Transaction directive passthrough, unrelated metadata key not triggering emission. check_commodity: empty input, warning severity (not error), input passthrough unchanged, undeclared cost currency, undeclared currency in Balance directive, undeclared currency in Price directive (both fields), HashSet dedup of repeated undeclared usage, mixed declared/undeclared. All 275 rustledger-plugin tests pass; clippy and fmt clean; plugin-test quality lint passes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the integration test coverage in rustledger-plugin by adding matrix-style tests for three native plugins (one_commodity, check_closing, check_commodity) to close remaining coverage gaps identified in the plugin testing audit (#1002).
Changes:
- Add additional OneCommodityPlugin tests covering empty input, per-account behavior, multi-currency cascades, and non-transaction directive handling.
- Add CheckCommodityPlugin tests covering severity level, passthrough behavior, and detection of undeclared commodities across Transactions (units/cost), Balance, and Price directives (with deduplication).
- Add CheckClosingPlugin tests covering empty input,
closingmetadata value/type gating, default currency behavior whenunits=None, multiple closing postings, and non-transaction passthrough.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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-08)
What do these numbers mean?
|
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
Address Copilot inline feedback on PR #1038. The original `test_onecommodity_skips_auto_balanced_posting` used `make_transaction`, which always sets `units: Some(...)`, so the test never actually traversed the `if let Some(units) = &posting.units` skip path it claimed to cover. Rewrite the test to construct an explicit transaction with one `units = None` posting alongside an explicit-USD posting, then follow up with a different currency on the same account in a later transaction. With the skip working correctly, the later currency is the first recorded for that account → no error. If the None posting had been tracked (in any form), the follow-up would mismatch and produce an error, so this design directly probes the branch. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…d bad date Address findings from the deep PR review: - one_commodity cascade test now asserts the *pairings* (USD↔EUR and USD↔GBP), not just the count. Previously a bug that recorded EUR or GBP as the "first" currency would still produce 2 errors with wrong pairings and pass the test. - check_commodity now exercises the cost.currency=None inner skip branch — the plugin's `if let Some(ref currency) = cost.currency` guard must drop postings whose Cost has no currency, not insert a spurious empty-string into used_commodities. - check_closing now pins the increment_date None branch via a "2024-13-01" date. The branch is unreachable in practice (parser validates dates upstream), but the source defensively guards against it. - check_closing units=None test gains a NOTE explaining that the "USD" fallback is hardcoded — it does not consult `options.operating_currencies`, so users with a different operating currency get a USD balance assertion. The test pins current behavior; flagged for follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…hrough Address remaining nitpicks from the second-pass review: - one_commodity cascade test now matches the literal `"USD and EUR"` and `"USD and GBP"` substrings instead of order-insensitive contains checks. A bug that emitted `"EUR and USD"` (reversed order) or scrambled the format string would now fail. - check_closing invalid-date test now also asserts that the original transaction passes through unchanged. Previously a regression that early-returned (dropping the input) would still pass the balance-count check. The doc comment is also corrected: the branch is unreachable from parser-loaded ledgers, but reachable from any caller constructing DirectiveWrapper programmatically. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
robcohen
enabled auto-merge (squash)
May 8, 2026 20:25
robcohen
added a commit
that referenced
this pull request
May 8, 2026
* feat(ci): per-plugin mutation survival floor (closes #1003) Phase 3 of the plugin-testing-quality plan from #992. The aggregate mutation score in `mutation.yml` was permissive: a few well-tested plugins could mask many badly-tested ones. This PR adds per-plugin floor enforcement (default ≤10% survival rate) and inline PR annotations for surviving mutants. What's added - `scripts/per-plugin-mutation-report.sh`: parses `mutants.out/*.txt`, groups outcomes by source file, computes per-plugin survival rate (`missed / (caught + missed + timeout)`, excluding unviable), prints a table, and exits non-zero when any plugin exceeds MUTATION_FLOOR. Infrastructure files outside `src/native/plugins/` are reported but not enforced. - `GITHUB_ANNOTATIONS=1` on the script emits `::warning file=…,line=…` for every surviving mutant, satisfying the "PR inline comments" acceptance criterion. GitHub Actions surfaces these on the diff. - `scripts/test-per-plugin-mutation-report.sh`: 9-case self-test for the report script — covers empty, all-caught, plugin-over-floor, infrastructure-only-over-floor, MUTATION_FLOOR=0 disable, missing inputs (exit 2), GitHub annotations, utils/mod bucketing, and the exact-10% boundary. Wired into the existing `Plugin Test Quality` CI job. - `.cargo/mutants.toml`: skips `<impl NativePlugin for …>::name` and `<impl NativePlugin for …>::description` mutations. These metadata methods return fixed strings used only for registry lookup; cargo- mutants tries `""` and `"xyzzy"` replacements that survive because no behavior depends on the literal text. Filtering at config level keeps the report honest about real coverage gaps. - `.github/workflows/mutation.yml`: new `Per-plugin mutation floor check` step that runs the report script with `MUTATION_FLOOR=10` and `GITHUB_ANNOTATIONS=1`, gated on the plugin crate being in the package list. - `CONTRIBUTING.md`: documents the floor, the local invocation, and the `#[mutants::skip]` annotation pattern with a required reason. How to handle a missed mutant (when CI fails) 1. Tighten the relevant test to fail under the mutated code, OR 2. Annotate the function with `#[mutants::skip]` and a leading `// reason:` comment explaining why mutation testing isn't useful. Local validation The report script was driven through 9 synthetic scenarios via the self-test (all pass). A partial real-data run on the 3 plugins from \#1038 surfaced 4 surviving mutants on `description()` methods — addressed by the `.cargo/mutants.toml` exclusion above. The CI run on this PR validates the workflow change, but the per-plugin enforcement won't actually fire until a future PR touches `crates/rustledger- plugin/src/native/plugins/*.rs` (the `mutation.yml` trigger paths). Closes #1003 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(ci): address PR #1041 review (truncation, doc, churn, guidance) Five Copilot inline findings, all real and actionable: 1. Truncation bug in floor enforcement. `survival_pct = m * 100 / total` loses precision: 11/101 = 10.89% truncates to 10 and incorrectly passes the `-gt 10` check. Replace with cross-multiplication `m * 100 > floor * total`, which is exact integer math and strictly greater. Pinned by a new self-test case (case 10: 11 missed out of 101 total → must fail). 2. Header doc mismatch. The "Usage" section called the bare invocation "report only" — actually wrong, since `MUTATION_FLOOR` defaults to 10 and enforcement is active unless explicitly set to 0. Also referenced `::error::` annotations when the script emits `::warning::`. Both fixed. 3. Process churn in GitHub annotation emission. Each missed mutant spawned 4 sed subprocesses + an echo for parsing — 4000 fork/exec pairs on a 1000-line missed.txt. Replace with a single bash `[[ $line =~ $regex ]]` capture; in-process, deterministic, faster. 4. Annotation guidance conflict with CONTRIBUTING.md. The script's failure message recommended `#[cfg_attr(test, mutants::skip)]` but CONTRIBUTING.md documents `#[mutants::skip]` (the canonical form, since cargo-mutants reads the AST without compiling). Align the script with the docs. 5. Test-coverage gap on the truncation boundary. Case 9 covered exactly-10% but didn't cover just-over-10%, which is the case the truncation bug would silently pass. New case 10 fills that gap and would have caught the original bug. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- 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
Closes the remaining Tier 2 gaps identified in the #1002 plugin testing matrix audit. Each plugin had only 2 happy-path tests in
native_plugins_test.rsand no inline tests, leaving most code branches uncovered.This PR follows the established pattern of #1007, #1008, and #1012 — one bundled PR adding full test matrices for a small group of related plugins.
Plugins covered
one_commodity(51 LOC validator) — 5 new testsunits = None) skip, per-account independence, three-currency cascade asserting both error pairings (USD↔EUR, USD↔GBP), non-Transaction directive ignore.check_closing(78 LOC mutator) — 8 new testsclosing: false→ no emission, non-Bool metadata value (String) → no emission,units = Nonefalling back to default"USD"(with NOTE about the hardcoded fallback not respectingoperating_currencies), multiple closing postings in one transaction → multiple balances, non-Transaction passthrough, unrelated metadata key (note) not triggering emission, malformed date (2024-13-01) → defensiveincrement_date()None skip.check_commodity(75 LOC validator) — 9 new testsWarning(notError), input passthrough unchanged, undeclared cost currency (posting.cost.currency),cost.currency = Noneinner skip branch, undeclared currency inBalancedirective, undeclared currency inPricedirective (bothprice.currencyandprice.amount.currency),HashSetdedup of repeated undeclared usage, mixed declared/undeclared with only the undeclared ones warned about.Why these three
Initial gap analysis only counted tests in
tests/native_plugins_test.rs, which over-flagged plugins likevaluation(6 inline) andcurrency_accounts(6 inline) as undertested. After counting inline + central tests, exactly these three remained at the 2-test, no-inline floor.Review hardening
This PR was self-reviewed and a reviewer (Copilot) flagged that the original
test_onecommodity_skips_auto_balanced_postingusedmake_transaction(which always setsunits: Some(...)) and never actually traversed theunits = Noneskip branch. Rewritten in910e0b84to construct an explicit transaction with aunits = Noneposting and probe the skip via a follow-up currency mismatch.A subsequent deep review tightened assertions and closed remaining gaps in
53cb0b57: the cascade test now asserts the error pairings not just the count, thecost.currency = Noneskip branch is exercised, and theincrement_date()None branch is pinned.Test plan
cargo test -p rustledger-plugin— all 165 tests passcargo clippy -p rustledger-plugin --all-features --all-targets -- -D warnings— cleancargo fmt -p rustledger-plugin -- --check— cleanscripts/check-plugin-test-quality.sh— passes (no weak count assertions, no(partial)labels)🤖 Generated with Claude Code