From 11314db1f73d09e12148f759db213d345683387b Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:05:48 -0700 Subject: [PATCH] fix(store): cash accounts found by name come in chart order FINDING from V-D2's reconcilable tests: cash_accounts returned the asset accounts whose names say cash in the order ChartOfAccounts::all yields them (a HashMap: "order unspecified"), so books.digest's unreconciled_accounts could list the same books' accounts in a different order from one run to the next. card_accounts, the rule beside it, already sorts by account id. The name-matched path now sorts the same way; configured codes keep the order they were configured in. No figure, membership or due date changes, only the order of the list. The earlier ignored test (cash_accounts_come_in_chart_order) now runs. This is a small fix kept in its own commit so it can be dropped without touching the tests. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-store/src/reconcilable.rs | 7 +++++-- crates/ledger-store/tests/reconcilable.rs | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ledger-store/src/reconcilable.rs b/crates/ledger-store/src/reconcilable.rs index e05fcf95..d67d1abf 100644 --- a/crates/ledger-store/src/reconcilable.rs +++ b/crates/ledger-store/src/reconcilable.rs @@ -45,7 +45,8 @@ pub fn cash_accounts(ledger: &Ledger, configured: &[String]) -> Vec { .filter_map(|c| ledger.chart().find_by_code(c).map(|a| a.id)) .collect(); } - ledger + // In chart order, as `card_accounts` is: the chart iterates in no order. + let mut found: Vec = ledger .chart() .all() .filter(|a| { @@ -55,7 +56,9 @@ pub fn cash_accounts(ledger: &Ledger, configured: &[String]) -> Vec { && CASH_WORDS.iter().any(|w| n.contains(w)) }) .map(|a| a.id) - .collect() + .collect(); + found.sort_unstable(); + found } /// The card accounts (`ledger_core::parties::card_accounts`: the diff --git a/crates/ledger-store/tests/reconcilable.rs b/crates/ledger-store/tests/reconcilable.rs index acee8330..92690af6 100644 --- a/crates/ledger-store/tests/reconcilable.rs +++ b/crates/ledger-store/tests/reconcilable.rs @@ -188,7 +188,7 @@ fn cash_accounts_are_the_assets_whose_names_say_cash() { ); } -/// FINDING (V-D2): the cash accounts found by name come out in the order +/// FINDING (V-D2; fixed by the commit that removed this test's ignore): the cash accounts found by name came out in the order /// the chart's `HashMap` yields them (`ChartOfAccounts::all` says "order /// unspecified"), not in chart order as `card_accounts` does (ascending /// account id). `books.digest`'s `unreconciled_accounts` lists accounts in @@ -198,7 +198,6 @@ fn cash_accounts_are_the_assets_whose_names_say_cash() { /// rule rather than a broken one; the expectation here is the order /// `card_accounts` already keeps. #[test] -#[ignore = "finding: cash_accounts yields name-matched accounts in HashMap order, so books.digest's unreconciled_accounts order is not stable; expected ascending account id as card_accounts keeps"] fn cash_accounts_come_in_chart_order() { let dir = test_dir("cash-order"); let mut s = Store::create(&dir, Currency::USD).unwrap();