fix(core): a legacy close's drift before its true-up is the rule's, not one unit
Before a count is trued up, check_split flagged any drift beyond one unit. BS-partner-1 statement 6 allows a legacy last-absorbs close more than that with four or more members, so the audit raised a false finding on legitimate legacy books. The rule does not state an audit bound; this bound is DERIVED from statement 6's per-member facts, and the derivation is in check_split's spec block: with n members and unit u, each member but the last was rounded to within u/2, and the last absorbed the sum of those roundings, so |e_last| <= (n-1)*u/2. Floored at u (statement 6's allowance for each run break and each per-close close), the pre-true-up bound is B(n) = max(u, (n-1)*u/2): 1.5 units with four members, 2 with five. A drift of exactly B(n) is legitimate and not flagged; past it is. After the true-up, statement 5's strict bound still holds: a drift of a unit or more is flagged. WB-ledger-16 invariant 8 now states B(n) and marks it derived. Tests: a_legacy_last_absorbs_close_drifts_by_member_count_before_its_true_up (BS-partner-1 statement 6 before the true-up, statement 5 after it; WB-ledger-16 invariant 8): four- and five-member closes at their largest legitimate drift are not flagged, one unit past it they are, and after the true-up the strict >= unit bound holds. Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
5b1596f977
commit
02087ef3fb
3 files changed
+117
-10
No files matched your search
@@ -189,7 +189,7 @@ pub const CODES: &[CodeRow] = &[
|
||||
CodeRow {
|
||||
code: "close_split_drifts",
|
||||
severity: Severity::Failure,
|
||||
predicate: "a member's running share of the closes is more than a minor unit from its exact share",
|
||||
predicate: "a member's running share of the closes drifts past the bound its regime allows from its exact share",
|
||||
},
|
||||
CodeRow {
|
||||
code: "schedule_behind",
|
||||
@@ -501,8 +501,33 @@ fn closes(ledger: &Ledger, through: NaiveDate) -> Vec<Finding> {
|
||||
/// 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.
|
||||
/// statement 6; WB-partner-1).
|
||||
///
|
||||
/// ```text
|
||||
/// SOURCE: BS-partner-1 statement 5 (after a close that posts, a member's
|
||||
/// total MUST be under one smallest unit from their exact share);
|
||||
/// BS-partner-1 statement 6 (the rounding left by an earlier rule
|
||||
/// is trued up by the first close that posts: a last-absorbs close
|
||||
/// rounded each member but the last to within half a unit, and
|
||||
/// the last absorbed up to half a unit for each of the others --
|
||||
/// a unit with three members, more with four or more); WB-ledger-16
|
||||
/// invariant 8.
|
||||
/// DERIVED: the rule states those per-member facts; it does not state an
|
||||
/// audit bound. The pre-true-up bound below is derived from them:
|
||||
/// with n members and unit u under last-absorbs, member i (not last)
|
||||
/// carries rounding e_i with |e_i| <= u/2, and the last member's part
|
||||
/// is the remainder, so e_last = -(e_1 + ... + e_{n-1}) and
|
||||
/// |e_last| <= (n-1) * u/2. The largest drift any member of one such
|
||||
/// close may legitimately carry is therefore (n-1)*u/2: u with three
|
||||
/// members, 3u/2 with four, 2u with five. Statement 6 also allows
|
||||
/// under u per member for each break in an earlier run and for each
|
||||
/// per-close close, so the allowance is floored at u:
|
||||
/// B(n) = max(u, (n-1)*u/2). A drift past B(n) is raised; a drift of
|
||||
/// exactly B(n) is legitimate (every non-last tie rounding the same
|
||||
/// way reaches it), so the pre-true-up test is strict (> B(n)).
|
||||
/// Once trued up, statement 5's bound is strict the other way: a
|
||||
/// drift of a unit or more is raised (>= u).
|
||||
/// ```
|
||||
pub fn check_split(
|
||||
period: u64,
|
||||
name: &str,
|
||||
@@ -510,11 +535,22 @@ pub fn check_split(
|
||||
unit: Decimal,
|
||||
trued_up: bool,
|
||||
) -> Vec<Finding> {
|
||||
// B(n) as derived above: (n-1)*u/2, floored at u. `unit` is a power
|
||||
// of ten and n is small, so the product and the halving are exact.
|
||||
let legacy_bound = {
|
||||
let others = Decimal::new(split.len().saturating_sub(1) as i64, 0);
|
||||
let last = others * unit / Decimal::new(2, 0);
|
||||
if last > unit { last } else { unit }
|
||||
};
|
||||
split
|
||||
.iter()
|
||||
.filter(|m| {
|
||||
let drift = (m.running - m.exact).abs();
|
||||
if trued_up { drift >= unit } else { drift > unit }
|
||||
if trued_up {
|
||||
drift >= unit
|
||||
} else {
|
||||
drift > legacy_bound
|
||||
}
|
||||
})
|
||||
.map(|m| {
|
||||
Finding::new(
|
||||
|
||||
Reference in new issue
Block a user