Repository navigation
fix(report): keep journal order when --limit is given - #2123
Conversation
`--limit N` reached the most recent N with `.rev().take(n)` and wrote the result straight out, so the rows came out reversed as well as selected: the unlimited journal reads oldest-first and adding a limit silently flipped it newest-first. Taking the last N is a fair reading of `--limit`; printing them backwards is not, and `tail` does not either. `sort_by_key` is stable, so the same reversal also undid the file order of same-date transactions. That is the order booking uses (#2093), so a limited journal disagreed with the ledger about which of two same-day entries came first -- not only cosmetic. `split_off` takes the tail without reversing it. All three output formats share the selection, so all three are fixed at once, and all three were checked. The test asserts the PROPERTY -- limited output is the tail of unlimited output, unchanged -- across every limit from 1 to the entry count, rather than pinning a transcript. A transcript test passes just as happily on a reversed list with the expectation written backwards. Against the old code it fails on the same-date pair: got ["same-day B", "same-day A"], want ["same-day A", "same-day B"]. Found by variant analysis from #2115, which was this same shape -- `.rev()` over a stably sorted list, reversing the tiebreak along with the sort key -- in the booking path. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
There was a problem hiding this comment.
Pull request overview
Fixes report journal --limit N to preserve the selected entries’ original order.
Changes:
- Uses
split_offto retain chronological and same-date file order. - Adds regression coverage for all limits.
- Documents the fix in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/rustledger/tests/cli_commands_test.rs |
Verifies limited output preserves order. |
crates/rustledger/src/cmd/report_cmd/journal.rs |
Corrects limited journal selection order. |
CHANGELOG.md |
Documents the journal ordering fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
|
Self-review: checked the boundaries, since
Only |
Closes #2122.
--limit Nreached the most recent N with.rev().take(n)and wrote the result straight out, so the rows were reversed as well as selected:Taking the last N is a fair reading of
--limit— "the most recent N" is usually what you want. Printing them backwards is not, andtaildoes not either. The selection was right; the presentation was wrong.sort_by_keyis stable, so the same reversal also undid the file order of same-date transactions. That is the order booking uses (#2093), so a limited journal disagreed with the ledger about which of two same-day entries came first — which is why this is more than cosmetic.split_off(len - n)takes the tail without reversing it. All three output formats share the one selection point, so all three are fixed together; I checked text, CSV and JSON.The test asserts a property, not a transcript
It requires the limited output to be the tail of the unlimited output, unchanged, for every limit from 1 to the entry count. A test pinning literal expected output would pass just as happily on a reversed list with the expectation written backwards — that is roughly how this survived.
Verified it fails against the old code, on the tie rather than the obvious case:
Provenance
Found by variant analysis from #2115 — the same shape one layer up:
.rev()over a stably sorted list, reversing the tiebreak along with the sort key. I swept the other.rev()sites at the same time;report_cmd/mod.rs(string truncation, rev → take → rev back), the LSP edit appliers and the undo-log replay are all the correct back-to-front idiom.Independent of #2119, #2120 and #2121 — branched from
mainand touches only the report path.🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr