test(core): the adapter runs refused dates, amounts, periods, roles, exports, 1099 years and returns

The bookspec examples now spell the input an engine has to refuse, and the
adapter takes each through the real books:

- a date past 9999 is refused by `Store::create_entry`'s own
  `try_create_entry` (DateOutOfRange), and a line past one quadrillion by
  `add_line` (AmountOutOfRange), each on a rehearsal so a refused entry
  leaves no draft;
- a close whose period partly overlaps another creates it through
  `Store::create_period` and reads PeriodsOverlap;
- `assign_role` is `Store::assign_role`, the journaled command, so a role
  on a header is refused by `check_assign_role` (ControlAccountMismatch)
  and the chart stays as it was;
- an IIF export with an entry on a receivable and a payable account is
  refused with BS-format-10's word, which is why `export_iif` keeps its
  typed error;
- a 2027 worksheet is refused through `RuleNotKnown` as
  `unknown_1099_year`, never guessed;
- `return_tin` reads the full number from the real `ledger_vault::Vault`
  the example's `setup.vault_tins` fills, and the books' own record keeps
  only the last four.

The adapter skips sixteen examples now (three more, each for an option
wanderbooks did not pick): allow-partial-overlap, carry-the-last-amount
and nowhere. Every one of the 95 it runs passes.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-09 07:40:26 -07:00
1 parent 9c299eb768
commit 7ac1e644b2
11 files changed
+178 -14

No files matched your search

@@ -3,8 +3,16 @@ use crate::*;
impl Books<'_> {
pub(crate) fn answer_iif(&self, q: &Query) -> Result<Value, Refusal> {
let as_of = self.q_day(q)?;
let iif = export_iif(self.l(), &self.ex.setup.cash_accounts, as_of)
.map_err(|e| engine_refusal(RuleId::new(Area::Format, 2), e))?;
let iif = export_iif(self.l(), &self.ex.setup.cash_accounts, as_of).map_err(|e| {
// An entry on more than one A/R or A/P account is BS-format-10's
// refusal; every other IIF refusal stays BS-format-2's.
match e {
ledger_import::IifError::SeveralReceivablePayableAccounts { .. } => {
Refusal::of_reason("several_receivable_payable_accounts")
}
other => engine_refusal(RuleId::new(Area::Format, 2), other),
}
})?;
match q.name.as_str() {
"iif_lines" => {
let mut lines: Vec<&str> = iif.text.split("\r\n").collect();
@@ -56,9 +64,9 @@ pub(crate) const FORMAT_QUERIES: [(&str, &str); 2] = [
),
];
/// A format query's shape, checked here; its values are checked by
/// [`FORMAT_QUERIES`]' test.
pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
/// A refused format query (BS-format-10): the appendix and the day, no
/// values.
pub(crate) fn check_format_refused(ex: &Example, x: &Expect) {
assert_eq!(
ex.appendix.as_deref(),
Some("formats"),
@@ -66,7 +74,6 @@ pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
ex.id,
x.query
);
// ledger-package reads the as_of itself: given, never defaulted.
assert!(x.as_of.is_some(), "{}: {} gives as_of", ex.id, x.query);
day(ex, x);
assert!(
@@ -75,6 +82,15 @@ pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
ex.id,
x.query
);
}
/// A format query's shape, checked here; its values are checked by
/// [`FORMAT_QUERIES`]' test.
pub(crate) fn check_format_shape(ex: &Example, x: &Expect) {
check_format_refused(ex, x);
if x.refused.is_some() {
return;
}
match (x.query.as_str(), x.values(&ex.id)) {
("iif_lines", Values::Lines(_)) => {}
("iif_changes", Values::Rows(rows)) => {
@@ -85,6 +85,7 @@ impl Books<'_> {
"party_part" => self.answer_party_part(q),
"party_totals" => self.answer_party_totals(q),
"party_tin_last4" => self.answer_party_tin_last4(q),
"return_tin" => self.answer_return_tin(q),
"project" => self.answer_project(q),
"aging" => self.answer_aging(q),
"document_dates" => self.answer_document_dates(q),
@@ -7,7 +7,13 @@ impl Books<'_> {
let l = self.l();
let sources = self.payment_accounts()?;
let r = vendor_1099_report(l, year, None, &sources, &self.party_members, Some(to))
.map_err(|e| engine_refusal(RuleId::new(Area::Tax1099, 1), e))?;
.map_err(|e| match e {
// A year whose threshold is not published is BS-1099-2's
// refusal, never a guess (the engine picks
// refuse-an-unknown-year).
LedgerError::RuleNotKnown { .. } => Refusal::of_reason("unknown_1099_year"),
other => engine_refusal(RuleId::new(Area::Tax1099, 1), other),
})?;
let _ = from;
let mut m = JsonMap::new();
for (name, vendor) in &self.payees {
@@ -41,7 +47,10 @@ impl Books<'_> {
&self.party_members,
Some(to),
)
.map_err(|e| engine_refusal(RuleId::new(Area::Tax1099, 1), e))?;
.map_err(|e| match e {
LedgerError::RuleNotKnown { .. } => Refusal::of_reason("unknown_1099_year"),
other => engine_refusal(RuleId::new(Area::Tax1099, 1), other),
})?;
let line = r.vendors.iter().find(|l| l.vendor_id == v).ok_or_else(|| {
Refusal::new(
RuleId::new(Area::Tax1099, 1),
@@ -159,6 +168,34 @@ impl Books<'_> {
Ok(json_figures([("tin_last4".to_string(), got.to_string())]))
}
/// The full TIN a return produced for `party` carries (BS-partner-8,
/// outside-the-books): read from the vault outside the books, never
/// from the books' records, which hold only the last four. A party
/// whose number the vault does not hold is refused `tin_not_held`.
pub(crate) fn return_tin(&self, party: PartyId) -> Result<String, Refusal> {
let vault = self
.vault
.as_ref()
.ok_or_else(|| Refusal::of_reason("tin_not_held"))?;
let tin = vault
.tin(party)
.map_err(|_| Refusal::of_reason("tin_not_held"))?
.ok_or_else(|| Refusal::of_reason("tin_not_held"))?;
Ok(tin.formatted())
}
pub(crate) fn answer_return_tin(&self, q: &Query) -> Result<Value, Refusal> {
let name = q.party.as_deref().ok_or_else(|| self.missing("party"))?;
let party = *self.parties.get(name).ok_or_else(|| {
Refusal::new(
RuleId::new(Area::Partner, 8),
format!("party {name:?} not in setup"),
)
})?;
let tin = self.return_tin(party)?;
Ok(json_figures([("tin".to_string(), tin)]))
}
pub(crate) fn answer_project(&self, q: &Query) -> Result<Value, Refusal> {
let name = q
.project
@@ -475,6 +512,28 @@ pub(crate) fn check_project(b: &Books<'_>, x: &Expect) {
/// Check one `party_tin_last4` expectation: the last four of the party's
/// TIN the books keep (its TIN facts', else its W-9's; `""` for none:
/// BS-partner-2).
/// Check one `return_tin` expectation: the full TIN a return produced for
/// the party carries, taken from the vault outside the books
/// (BS-partner-8's outside-the-books option).
pub(crate) fn check_return_tin(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
assert!(
x.from.is_none() && x.to.is_none() && x.as_of.is_none(),
"{}: return_tin takes no dates",
ex.id
);
let party = expect_party(b, x);
exactly(ex, x, &["tin".to_string()].into());
let got = b
.return_tin(party)
.unwrap_or_else(|r| panic!("{}: return_tin refused ({})", ex.id, r.reason));
assert_eq!(
got, x.figures(&ex.id)["tin"],
"{}: {:?}'s return TIN",
ex.id, x.party
);
}
pub(crate) fn check_party_tin_last4(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
assert!(