Repository navigation
test(returns): messy-imported-ledger suite (#1850 §6, §5) - #1853
Merged
Merged
Conversation
robcohen
force-pushed
the
feat/returns-by-group-partial
branch
from
July 23, 2026 13:12
8debb86 to
6c83db0
Compare
robcohen
force-pushed
the
feat/returns-messy-ledger-tests
branch
from
July 23, 2026 13:12
f5b16b4 to
aa666f4
Compare
robcohen
force-pushed
the
feat/returns-by-group-partial
branch
from
July 23, 2026 13:58
6c83db0 to
d115ff6
Compare
robcohen
force-pushed
the
feat/returns-messy-ledger-tests
branch
from
July 23, 2026 13:59
aa666f4 to
23bc54f
Compare
robcohen
force-pushed
the
feat/returns-by-group-partial
branch
from
July 23, 2026 14:47
d115ff6 to
c19aa6d
Compare
#1850 §6 (with §5 edge cases): a suite exercising net-units returns over the imperfect/imported ledgers this effort targets, through the SHARED scope_returns/scopes_returns composition (the exact path the CLI and the WIT component take), so it also pins real PriceDatabase price resolution. Cases (crates/rustledger-query/tests/messy_returns_test.rs): - over-sell of an empty-cost {} lot → net −5, valued at market (−600), tolerated; - missing opening buy (importer started mid-history) → short net position; - clean empty-cost {} reduction → net units valued identically; - falling prices → a real NEGATIVE money- and time-weighted rate (beangrow CRASHES here — beangrow#4 / #16; our Newton+Brent xirr returns Option<f64>); - near-total loss → defined large-negative rate, no crash; - missing intermediate price (late first price) → MWR computes from cash flows + priced terminal, TWR degrades to None (not an error) — the §5 missing-price policy; - per-scope isolation: an elided in-scope scope fails alone (UnbookedInput) while a clean scope computes, over one shared accumulation (what --by-group relies on). Also corrects the scope_returns/scopes_returns doc comments (§2), which still carried the #1849 strict-clean language — now contradicted by the net-units model: cost-basis/lot errors are tolerated, and UnbookedInput is PER-SCOPE, not a whole-ledger abort. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
…ct (review 2) Second review pass doc drift, query composition root: - scope_returns summary said "from a booked, pad-expanded stream" -> interpolated (booking not required; net units valued at market). - scope_returns/scopes_returns # Errors described UnbookedInput as firing only for an in-scope elided holding; the elided-external-leg fix also fires it for an external boundary leg (unknown cash flow), so both now name BOTH shapes. Doc-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
robcohen
force-pushed
the
feat/returns-messy-ledger-tests
branch
from
July 23, 2026 17:34
23bc54f to
f0b148a
Compare
Contributor
📊 Benchmark Results
vs main branch (2026-07-23)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an end-to-end “messy imported ledger” test suite for the returns feature (#1850 §6 + §5 edge cases), validating that net-units valuation computes robust returns even when cost-basis/lot-matching would fail, and updates scope_returns / scopes_returns docs to reflect the net-units + per-scope error isolation model.
Changes:
- Introduces
messy_returns_test.rscovering oversells/short positions, falling prices (negative returns), near-total loss, missing intermediate prices (TWR →None), and per-scope isolation ofUnbookedInput. - Updates
rustledger-queryreturns composition docs to clarify that booking/lot-matching is not required, cost-basis/lot errors are tolerated, and bothMissingPriceandUnbookedInputare per-scope in multi-scope evaluation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/rustledger-query/tests/messy_returns_test.rs | New integration-style tests exercising shared scope_returns/scopes_returns composition over imperfect ledgers, including negative-return and missing-price edge cases. |
| crates/rustledger-query/src/returns.rs | Doc comment corrections aligning the public composition helpers with the net-units valuation model and per-scope error isolation behavior. |
💡 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
19 tasks
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
Adds #1850 §6 — a messy-imported-ledger test suite proving the net-units returns capability end-to-end — plus the §5 edge cases and a §2 doc correction.
What it tests
The suite (
crates/rustledger-query/tests/messy_returns_test.rs) drives the sharedscope_returns/scopes_returnscomposition — the exact path the CLIreport returnsand the WIT componentsession.returnstake — so it also pins realPriceDatabaseprice resolution, not just the engine in isolation.{}lot{}reductionNone, not an error (§5 policy)UnbookedInput), a clean scope computes — over one shared accumulationWhere we exceed beangrow
beangrow crashes on falling prices / negative returns ("complex rate of return", beangrow#4 / #16). Our Newton+Brent
xirrreturns a genuineOption<f64>— thefalling_prices_…andnear_total_loss_…cases lock that in as a documented divergence.Also (§2 doc fix)
Corrects the
scope_returns/scopes_returnsdoc comments, which still carried the #1849 strict-clean language now contradicted by the net-units model: cost-basis/lot errors are tolerated, andUnbookedInputis per-scope, not a whole-ledger abort (thescopes_are_isolated_…test proves it).Verification
rustledger-querysuite (170 lib + 402 + the 7 new tests + others) — greenclippy@1.97.0,rustdoc -D warnings, rustfmt, typos, gitleaks — cleanRemaining #1850 increments
§7 —
docs/commands/report.mdmodel docs (the last piece).🤖 Generated with Claude Code