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
@@ -1,4 +1,4 @@
|
||||
//! The audit's statements checks (plan P8; BS-ledger-13): the books,
|
||||
//! The audit's statements checks (plan P8; WB-ledger-16): the books,
|
||||
//! read as an auditor would, through a date, as a list of findings.
|
||||
//!
|
||||
//! ```text
|
||||
@@ -481,24 +481,36 @@ fn closes(ledger: &Ledger, through: NaiveDate) -> Vec<Finding> {
|
||||
continue;
|
||||
}
|
||||
if let Some((_, split)) = ledger.member_close_split(p.id) {
|
||||
out.extend(check_split(p.id, &p.name, &split, unit));
|
||||
let trued_up = ledger.member_close_trued_up(p.id).unwrap_or(false);
|
||||
out.extend(check_split(p.id, &p.name, &split, unit, trued_up));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// One close's members: each one's running total of the closes must be
|
||||
/// within a minor unit of its exact share (the cumulative rule,
|
||||
/// `kernel::apportion_cumulative`).
|
||||
/// under a minor unit from its exact share (the cumulative rule,
|
||||
/// `kernel::apportion_cumulative`; BS-partner-1 statement 5).
|
||||
///
|
||||
/// `trued_up` says the count has had a close under the cumulative rule
|
||||
/// that posted an entry ([`crate::Ledger::member_close_trued_up`]). Until
|
||||
/// then the count may still carry the rounding of closes made under the
|
||||
/// older rules, which the first such close trues up (BS-partner-1
|
||||
/// statement 6; WB-partner-1), so only a drift beyond a unit is raised.
|
||||
/// Once trued up, a drift of a unit or more is raised: the bound is strict.
|
||||
pub fn check_split(
|
||||
period: u64,
|
||||
name: &str,
|
||||
split: &[crate::periods::MemberSplit],
|
||||
unit: Decimal,
|
||||
trued_up: bool,
|
||||
) -> Vec<Finding> {
|
||||
split
|
||||
.iter()
|
||||
.filter(|m| (m.running - m.exact).abs() > unit)
|
||||
.filter(|m| {
|
||||
let drift = (m.running - m.exact).abs();
|
||||
if trued_up { drift >= unit } else { drift > unit }
|
||||
})
|
||||
.map(|m| {
|
||||
Finding::new(
|
||||
"close_split_drifts",
|
||||
@@ -670,7 +682,7 @@ fn settings_problems(problems: &[String]) -> Vec<Finding> {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scope, method and the attestation bar (BS-ledger-13; D-9)
|
||||
// Scope, method and the attestation bar (WB-ledger-16; D-9)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// What an audit covers.
|
||||
@@ -763,7 +775,7 @@ impl Effort {
|
||||
}
|
||||
|
||||
/// How an attestation was made, as the client says (self-reported: the
|
||||
/// books record the claim, never prove it; BS-ledger-13).
|
||||
/// books record the claim, never prove it; WB-ledger-16).
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
pub struct Method {
|
||||
/// The model that checked, as it names itself.
|
||||
|
||||
@@ -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