Repository navigation
fix(extract): write statements oldest-first, keeping the within-day order - #2526
Conversation
…rder Per input file, count the steps between consecutive transactions' dates; when more go down than up, reverse the rows, then stable-sort by the canonical booking_sort_key. A newest-first export now comes out oldest-first with each day's rows in true order, an oldest-first one is unchanged, and a tie (or a single date) keeps file order. Runs once, for every importer type, after the importer and before --existing dedup; the --balance assertion is still appended last. Closes #2319 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Codecov Report❌ Patch coverage is
📢 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 |
…heck Beancount and rledger check evaluate a balance at the start of its date, whatever line it is on, and the ordering uses the same (date, type) key, so an importer-emitted assertion dated on the last row's date is written ahead of that day's rows. Pinned by a test; verified with bean-check that both placements give identical results. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review (adversarial pass)Balance placement (concern: sorting a
So a closing figure dated on the last day fails on Cross-PR integration (applies to #2524, #2526, #2527, #2531, #2532, #2533)All six PRs were merged onto
|
# Conflicts: # CHANGELOG.md
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
# Conflicts: # CHANGELOG.md
What changed
rledger extractnow writes each statement oldest-first and keeps the export's own sequence within a day. This is option C as decided on #2319.rustledger_importer::order::chronologicalruns once per input file, right after the importer and before--existingdedup:rustledger_core::booking_sort_key, the canonical (date, directive type) order. Same date and type keep their post-reversal position.This applies to the CSV, OFX and WASM importers alike, since it runs on
ImportResult::directiveswhichever importer produced them.--balanceassertion is appended after both, so it stays last.LEDGERBALassertion is not a row. It does not vote on direction and is placed by the sort, dated the day afterDTASOF, so normally last.Documented in
docs/commands/extract.md("Output Order"), including the assumption: a newest-first export is assumed newest-first within a day too, because no time of day survives import to check. CHANGELOG says newest-first exports now come out oldest-first.Why
A newest-first export (#2319) was written backwards. A plain stable sort by date, which is what beangulp does, would fix the days but leave each day's rows newest-first. The reporter asked to keep the sequence, so the plain sort was rejected.
How tested
rustledger-importer(order::tests):extract(F) == extract(reverse(F)) == F, through the real CSV importer.chronologicalreturns the importer's directives unchanged as values, which makes the output byte-identical to before.LEDGERBAL, where the balance does not vote and lands by date.rustledgerCLI (tests/cli_commands_test.rs):--existingand--balance: stdout is oldest-first, the two skip lines are in output order, and the--balanceassertion (dated before every row) is still last.extracttakes one input file per run, so "several files each keep their own block" means separate runs appended to one ledger. The test does that, and each file's block stays separate and in import order, even when the second file is older.Shown to fail without the fix: without the reversal (plain sort), the descending test and the reversal proptest fail. With no ordering at all, 6 of the 9 order tests fail. The 3 that pass either way are the "unchanged" checks: ascending, single date, ascending-as-is.
Existing
extract_cmdtests pass unchanged. Clippy (workspace, all targets,-D warnings) and rustdoc (-D warnings) are clean for both crates.Closes #2319
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr