fix(core): the audit holds a close's split to under one unit once the count is trued up
BS-partner-1 statement 5 says that after a close that posts, each member's running total MUST be under one smallest unit from its exact share. The audit flagged drift only when it was greater than a unit, so exactly one unit passed. The looser bound is right only until the first true-up (statement 6, WB-partner-1): a count that still holds closes made under the older rules may carry their rounding until a cumulative close posts. A close records both facts replay needs: its rule (`MembersClosed.rule`) and whether it posted (`closing_entry`). `Ledger::member_close_trued_up` says a count has had a cumulative close that posted, at or before a given close, and `audit::check_split` flags drift of a unit or more once it has, drift beyond a unit before. Closes under the older rules are not read by the audit at all. Tests: both regimes at the edge in either direction, and a count walked through a per-close January, a non-posting February (not trued up), a posting March (trued up) and a non-posting April (still trued up). WB-ledger-16 gains invariant 8 for it. The same test file now cites WB-ledger-16 for the audit (BS-ledger-13 is retired), and audit.rs's own invariant and scenario where WB-ledger-16's numbering does not match. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5fd382450b
commit
7ac1ef8c5a
5 files changed
+180
-33
No files matched your search
@@ -3965,6 +3965,7 @@ impl Ledger {
|
||||
closed: Decimal::ZERO,
|
||||
given: vec![Decimal::ZERO; members.len()],
|
||||
order: Vec::new(),
|
||||
trued_up: false,
|
||||
};
|
||||
for p in closed {
|
||||
let Some(m) = &p.members_closed else {
|
||||
@@ -3974,6 +3975,8 @@ impl Ledger {
|
||||
break;
|
||||
}
|
||||
regime.since_seq = p.close_seq;
|
||||
regime.trued_up |= matches!(m.rule, periods::MemberRule::Cumulative { .. })
|
||||
&& p.closing_entry.is_some();
|
||||
regime.order.clone_from(&m.members);
|
||||
regime.closed += m.net;
|
||||
for ((capital, _), part) in m.members.iter().zip(&m.parts) {
|
||||
@@ -4018,6 +4021,24 @@ impl Ledger {
|
||||
Some((since_seq, split))
|
||||
}
|
||||
|
||||
/// Whether a closed members period's count has been trued up by the
|
||||
/// close or an earlier one of its count: a close under the cumulative
|
||||
/// rule that posted an entry has run the first true-up of the rounding
|
||||
/// of closes under earlier rules (WB-partner-1), so each member's
|
||||
/// running total is then strictly under one minor unit from exact
|
||||
/// (BS-partner-1 statement 5). Before that, a count that holds closes
|
||||
/// from the older rules may still be a unit or more away. `None` for a
|
||||
/// period not closed to members.
|
||||
pub fn member_close_trued_up(&self, id: PeriodId) -> Option<bool> {
|
||||
let p = self.periods.get(&id)?;
|
||||
let m = p.members_closed.as_ref()?;
|
||||
let seq = p.close_seq?;
|
||||
Some(
|
||||
self.regime_where(&m.members, |q| q.close_seq <= Some(seq))
|
||||
.trued_up,
|
||||
)
|
||||
}
|
||||
|
||||
/// The net closed by the run of cumulative members closes, with exactly
|
||||
/// these members and shares, that ends with the latest close: zero if
|
||||
/// the latest close was anything else (or there is none).
|
||||
@@ -9639,6 +9660,11 @@ pub(crate) struct Regime {
|
||||
/// count the next members close begins, when it is these members'
|
||||
/// ([`Ledger::members_regime`]). Empty when there is none.
|
||||
pub order: Vec<(AccountId, Decimal)>,
|
||||
/// Whether a close under the cumulative rule that posted an entry is
|
||||
/// among the count's closes: its true-up has run, so each member's
|
||||
/// running total is then under one minor unit from exact
|
||||
/// (BS-partner-1 statement 5).
|
||||
pub trued_up: bool,
|
||||
}
|
||||
|
||||
impl Regime {
|
||||
|
||||
Reference in new issue
Block a user