merge: the traceability gate (X-J; reviewed, re-checked twice, fixes applied)

Every claim in docs/spec/claims/ now has to be backed. A yes or partly
claim names where the engine enforces it and what checks it, and every
name resolves strictly: a Rust item by its whole path (a method on its
own type), a test by its #[test], a Kani harness by its #[kani::proof],
a Lean theorem in the list bookspec audits, a path that exists. Every
kernel function has a harness and a bridge property that call it, and a
law whose rules its own SOURCE cites; the fourteen that cannot are listed
with why, and the seven it cannot check for a law are pinned.

The gate found what the claims got wrong: B-22 claimed partial
enforcement of a rule the engine does not enforce (now no); WB-prepaid-2
claimed K-U5's rounding before it landed (now partly); two rules cited
retired ids as live; nineteen names had moved or never existed. The
reviews found three ways a wrong name could still pass, then two more;
all closed, with probes that a made-up name of each kind fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-08 23:14:01 -07:00
commit 90e62e20b3
23 files changed
+3393 -36

No files matched your search

@@ -96,3 +96,4 @@ mod rules_md;
mod run;
mod source_refs;
mod sources;
mod traceability;
File diff suppressed because it is too large. Load diff
@@ -1,4 +1,42 @@
//! U8 bridge properties: control and aging (kernel sweep).
//!
//! Empty in U0: the unit adds its `Decimal`-vs-integer properties here,
//! beside `main.rs` and the other units.
//! `kernel::running_bounds` and `kernel::bounds_kept` at `i64` cents (what
//! Kani proves, law 34) against the same on `Decimal` (what the engine
//! runs), on random documents.
use super::{arb_cents, dec};
use ledger_core::kernel;
use proptest::prelude::*;
proptest! {
#![proptest_config(ProptestConfig::with_cases(1000))]
/// The same running balances are within bounds, or leave them at the
/// same step, at both types.
#[test]
fn running_bounds_agree(
total in arb_cents(),
deltas in prop::collection::vec(arb_cents(), 0..7),
) {
let wide: Vec<_> = deltas.iter().map(|&c| dec(c)).collect();
prop_assert_eq!(
kernel::running_bounds(total, &deltas),
kernel::running_bounds(dec(total), &wide)
);
}
/// The same step keeps (or breaks) a document's bounds at both types.
#[test]
fn bounds_kept_agree(
total in arb_cents(),
before in prop::collection::vec(arb_cents(), 0..7),
after in prop::collection::vec(arb_cents(), 0..7),
) {
let wide_before: Vec<_> = before.iter().map(|&c| dec(c)).collect();
let wide_after: Vec<_> = after.iter().map(|&c| dec(c)).collect();
prop_assert_eq!(
kernel::bounds_kept(total, &before, &after),
kernel::bounds_kept(dec(total), &wide_before, &wide_after)
);
}
}
@@ -0,0 +1,199 @@
//! Entries bridge properties: the small amount-generic pieces the
//! statement of cash flows builds on.
//!
//! `kernel::take`, `entry_movements` and `flows_of` at `i64` cents (what
//! Kani proves, law 10) against the same on `Decimal` (what the engine
//! runs), on random lines.
use super::{arb_cents, dec};
use ledger_core::Side;
use ledger_core::kernel::{self, Flow};
use proptest::prelude::*;
fn arb_flow() -> impl Strategy<Value = Flow> {
prop_oneof![
Just(Flow::Cash),
Just(Flow::Operating),
Just(Flow::Investing),
Just(Flow::Financing),
]
}
fn arb_side() -> impl Strategy<Value = Side> {
prop_oneof![Just(Side::Debit), Just(Side::Credit)]
}
fn arb_flow_lines() -> impl Strategy<Value = Vec<(Flow, Side, i64)>> {
prop::collection::vec((arb_flow(), arb_side(), arb_cents()), 0..6)
}
fn to_dec(lines: &[(Flow, Side, i64)]) -> Vec<(Flow, Side, rust_decimal::Decimal)> {
lines.iter().map(|&(f, s, a)| (f, s, dec(a))).collect()
}
fn arb_direction() -> impl Strategy<Value = kernel::Direction> {
prop_oneof![
Just(kernel::Direction::Paid),
Just(kernel::Direction::Received),
Just(kernel::Direction::Neither),
]
}
/// Cents, plus the `i64` range's edges: [`arb_cents`] is bounded to ±2^40
/// (what a journal line may carry), so it never reaches the negation that
/// overflows, and the refusal path would go untested.
fn arb_edge_cents() -> impl Strategy<Value = i64> {
prop_oneof![arb_cents(), Just(i64::MIN), Just(i64::MAX)]
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(1000))]
/// `kernel::take` takes the same part of a movement at both types.
#[test]
fn take_agrees(remaining in arb_cents(), movement in arb_cents()) {
prop_assert_eq!(
kernel::take(remaining, movement).map(dec),
kernel::take(dec(remaining), dec(movement))
);
}
/// `kernel::entry_movements` nets the cash and each section the same.
#[test]
fn entry_movements_agree(lines in arb_flow_lines()) {
let i = kernel::entry_movements(&lines)
.map(|(cash, moved)| (dec(cash), moved.map(dec)));
let d = kernel::entry_movements(&to_dec(&lines));
prop_assert_eq!(i, d);
}
/// `kernel::flows_of` splits the cash the same, and refuses the same
/// lines that do not net to zero.
#[test]
fn flows_of_agree(
cash in arb_cents(),
moved in (arb_cents(), arb_cents(), arb_cents())
.prop_map(|(a, b, c)| [a, b, c]),
) {
let i = kernel::flows_of(cash, moved);
let d = kernel::flows_of(dec(cash), moved.map(dec));
prop_assert_eq!(
i.map(|f| (dec(f.cash), f.flows.map(dec), f.noncash.map(dec))),
d.map(|f| (f.cash, f.flows, f.noncash))
);
}
/// `kernel::catch_ups` gives every suffix's catch-up at both types.
#[test]
fn catch_ups_agree(
pairs in prop::collection::vec((arb_cents(), arb_cents()), 0..6),
) {
let scheduled: Vec<i64> = pairs.iter().map(|&(s, _)| s).collect();
let posted: Vec<i64> = pairs.iter().map(|&(_, p)| p).collect();
let mut i = vec![0i64; scheduled.len()];
let mut d = vec![dec(0); scheduled.len()];
let ri = kernel::catch_ups(&scheduled, &posted, &mut i);
let rd = kernel::catch_ups(
&scheduled.iter().map(|&c| dec(c)).collect::<Vec<_>>(),
&posted.iter().map(|&c| dec(c)).collect::<Vec<_>>(),
&mut d,
);
prop_assert_eq!(ri, rd);
prop_assert_eq!(i.into_iter().map(dec).collect::<Vec<_>>(), d);
}
/// `kernel::unrecovered_cost` is the same shortfall at both types.
#[test]
fn unrecovered_cost_agree(revenue in arb_cents(), expenses in arb_cents()) {
prop_assert_eq!(
kernel::unrecovered_cost(revenue, expenses).map(dec),
kernel::unrecovered_cost(dec(revenue), dec(expenses))
);
}
/// `kernel::Direction::of` classifies the same sign at both types, and
/// each case keeps its meaning (law 23).
#[test]
fn direction_of_agrees(cents in arb_cents()) {
let i = kernel::Direction::of(cents);
let d = kernel::Direction::of(dec(cents));
prop_assert_eq!(i, d);
if cents > 0 {
prop_assert_eq!(i, kernel::Direction::Paid);
} else if cents < 0 {
prop_assert_eq!(i, kernel::Direction::Received);
} else {
prop_assert_eq!(i, kernel::Direction::Neither);
}
}
/// `kernel::reverse_target` is the exact opposite at both types, and
/// `i64` refuses its range's edge (`i64::MIN`, which no negation can
/// hold): the edge strategy reaches that arm, and Decimal, which can
/// hold the negation, answers the opposite (law 24). The refusal is
/// the integer proof model's bound, not the law's.
#[test]
fn reverse_target_agrees(
amount in arb_edge_cents(),
cash in arb_edge_cents(),
in_kind in arb_edge_cents(),
direction in arb_direction(),
) {
let t = kernel::PartyTarget {
amount,
direction,
cash,
in_kind,
};
let d = kernel::PartyTarget {
amount: dec(amount),
direction,
cash: dec(cash),
in_kind: dec(in_kind),
};
let as_dec = |r: kernel::PartyTarget<i64>| kernel::PartyTarget {
amount: dec(r.amount),
direction: r.direction,
cash: dec(r.cash),
in_kind: dec(r.in_kind),
};
match kernel::reverse_target(t) {
Some(r) => prop_assert_eq!(Some(as_dec(r)), kernel::reverse_target(d)),
None => {
prop_assert!(
amount == i64::MIN || cash == i64::MIN || in_kind == i64::MIN,
"reverse_target refused an in-range target"
);
prop_assert_eq!(
kernel::reverse_target(d),
Some(kernel::PartyTarget {
amount: -dec(amount),
direction: direction.flip(),
cash: -dec(cash),
in_kind: -dec(in_kind),
})
);
}
}
}
/// `kernel::part_weight` is the same weight at i32, i64 and i128, and
/// `None` exactly for a part no calendar month has (laws 26-28).
#[test]
fn part_weight_agrees(month_days in 0u32..=40, days in 0u32..=40) {
let part = kernel::MonthPart { days, month_days };
let w32: Option<i32> = kernel::part_weight(part);
let w64: Option<i64> = kernel::part_weight(part);
let w128: Option<i128> = kernel::part_weight(part);
prop_assert_eq!(w64, w32.map(i64::from));
prop_assert_eq!(w128, w64.map(i128::from));
if part.is_valid() {
prop_assert_eq!(
w64,
Some(i64::from(days) * i64::from(kernel::MONTH_L / month_days))
);
} else {
prop_assert_eq!(w64, None);
}
}
}
@@ -9,6 +9,7 @@
// One file per kernel-sweep unit; the properties above stay here.
mod allocate;
mod control;
mod entries;
mod fx;
mod payroll;
mod ratio;