merge: the adapter runs settlements, recoveries, invoice numbers and vendor references; a fee above the cash is its own refusal (X-H1b's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for the options it picked: 80 run, 80 passed, 11 for options it did not pick. The settlement refusal that read a fee above the cash out of one half of an error message's 'or' is now a typed refusal (LedgerError::FeeAboveCash), checked before the kernel's settle at the same point, so no refusal's order changes; the remaining message names only what is left (an amount too large, a negative fee). BS-arap-10's pick is ignore-case-spaces-and-hyphens, as plan P4b S4 decided and the engine always did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
81bc16c386
11 files changed
+377
-23
No files matched your search
@@ -749,9 +749,24 @@ pub enum LedgerError {
|
||||
#[error("{0}")]
|
||||
InvalidFee(String),
|
||||
|
||||
/// A settlement's figures can't be exact: the cash and discounts
|
||||
/// don't cover the applications, or the fee leaves a negative deposit
|
||||
/// (BS-arap-6 INVARIANT 1).
|
||||
/// A processor's fee is above the cash it was withheld from: a
|
||||
/// processor cannot keep more than it was paid (BS-arap-6). A fee equal
|
||||
/// to the cash is [`LedgerError::InvalidSettlement`]: the deposit would
|
||||
/// be nothing.
|
||||
#[error(
|
||||
"the processor's fee of {fee} is above the cash of {cash}: a processor can't keep more than it was paid"
|
||||
)]
|
||||
FeeAboveCash {
|
||||
/// The fee asked for.
|
||||
fee: Decimal,
|
||||
/// The settlement's cash, summed over its applications.
|
||||
cash: Decimal,
|
||||
},
|
||||
|
||||
/// A settlement's figures can't be exact (BS-arap-6 INVARIANT 1): an
|
||||
/// amount too large to add, a negative fee, or a fee that leaves
|
||||
/// nothing to deposit; a fee above the cash is
|
||||
/// [`LedgerError::FeeAboveCash`].
|
||||
#[error("{0}")]
|
||||
InvalidSettlement(String),
|
||||
|
||||
|
||||
@@ -6703,9 +6703,22 @@ impl Ledger {
|
||||
discounts.push(app.discount);
|
||||
}
|
||||
let fee_amount = params.fee.as_ref().map_or(Decimal::ZERO, |f| f.amount);
|
||||
// A fee above the cash is its own refusal; the kernel would also
|
||||
// answer `None` for it, with no way to say which of its refusals it
|
||||
// was. A sum that overflows is left to the kernel (too large).
|
||||
if let Some(total_cash) = cash
|
||||
.iter()
|
||||
.try_fold(Decimal::ZERO, |sum, c| sum.checked_add(*c))
|
||||
&& fee_amount > total_cash
|
||||
{
|
||||
return Err(LedgerError::FeeAboveCash {
|
||||
fee: fee_amount,
|
||||
cash: total_cash,
|
||||
});
|
||||
}
|
||||
let settlement = kernel::settle(&cash, &discounts, fee_amount).ok_or_else(|| {
|
||||
LedgerError::InvalidSettlement(
|
||||
"the cash and discounts don't cover the applications exactly, or the fee is above the cash"
|
||||
"the settlement's figures aren't exact: an amount is too large, or the fee is negative"
|
||||
.into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
Reference in new issue
Block a user