fix(mcp,import): a reference class in the table, the refusal names the table's field, bank rules match the bank's words

The tools' table gains a third class, reference, for fields that are
identifiers by nature (18 strings: tags and serials, vendor and customer
references, payment and send references, account codes, file names, an
instrument's label, where a W-9 or W-4 is kept); free text falls from 127 to
109. The refusal names the table's own field and describes a key it does not
know as an unrecognised field, never quoting a key the caller chose. A bank
import matches its rules against the description as the bank wrote it and
journals the masked one, so a rule keyed on a nine-digit reference still
matches. A chart file's account code is a reference.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 16:13:06 -07:00
1 parent 049cf2a6b5
commit 6f68835c3f
7 files changed
+324 -39

No files matched your search

+24
View File
@@ -104,6 +104,11 @@ pub struct MaskedBankImport {
pub transactions: Vec<BankTransaction>,
/// Which cells were masked, in file order.
pub masked: Vec<MaskedCell>,
/// Each transaction's description exactly as the bank wrote it, in the
/// same order as `transactions`: for matching a categorizing rule
/// against (a rule keyed on a reference of nine digits still matches),
/// never to be kept or shown.
pub as_written: Vec<String>,
}
/// [`parse_bank_csv_with`] for a file that is to be kept: a description a
@@ -134,9 +139,11 @@ pub fn parse_bank_csv_masked(
order: Option<DateOrder>,
) -> Result<MaskedBankImport, BankCsvError> {
let mut masked = Vec::new();
let mut as_written = Vec::new();
let transactions = parse_rows(text, order)?
.into_iter()
.map(|(line, mut txn)| {
as_written.push(txn.description.clone());
let numbers = ledger_core::settings::count_printed_tins(&txn.description);
if numbers > 0 {
txn.description =
@@ -153,6 +160,7 @@ pub fn parse_bank_csv_masked(
Ok(MaskedBankImport {
transactions,
masked,
as_written,
})
}
@@ -400,6 +408,22 @@ mod tests {
// A file with none masks none.
let clean = parse_bank_csv_masked("2026-01-02,Rent,-1.00\n", None).unwrap();
assert!(clean.masked.is_empty());
assert_eq!(clean.as_written, ["Rent"]);
}
/// `as_written` is each description as the bank wrote it, in order,
/// for matching a rule against: a rule keyed on a nine-digit reference
/// still finds it, while the kept description is masked.
#[test]
fn the_bank_s_own_words_are_kept_for_matching_rules() {
let csv = "2026-01-02,ACH 000000000 payroll,-1.00\n2026-01-03,Rent,-2.00\n";
let got = parse_bank_csv_masked(csv, None).unwrap();
assert_eq!(got.as_written, ["ACH 000000000 payroll", "Rent"]);
assert_eq!(
got.transactions[0].description,
"ACH \u{2022}\u{2022}\u{2022}\u{2022}\u{2022}0000 payroll"
);
assert_eq!(got.transactions.len(), got.as_written.len());
}
#[test]
+29
View File
@@ -126,6 +126,11 @@ pub fn parse_chart_csv(text: &str) -> Result<Vec<ChartRow>, ChartCsvError> {
for (n, value) in fields.iter().enumerate() {
let looks = if n == 1 {
ledger_core::parties::has_full_tin(value)
} else if n == 0 || n == 3 {
// An account code (and its parent's) is a reference: a
// bare nine digits is a code, only the printed shapes
// read as a tax id (WB-partner-15).
ledger_core::settings::holds_printed_tin_in_reference(value)
} else {
ledger_core::settings::holds_printed_tin(value)
};
@@ -177,6 +182,30 @@ mod tests {
assert_eq!(rows[2].account_type, "revenue");
}
/// An account code is a reference: a bare nine digits is a code, a
/// printed SSN or EIN is refused, naming its row and column.
#[test]
fn a_code_may_be_nine_digits_but_not_a_printed_tax_id() {
let ok =
"code,name,type,parent_code\n123456789,Cash,asset,\n123456790,Bank,asset,123456789\n";
assert_eq!(parse_chart_csv(ok).unwrap().len(), 2);
for csv in [
"code,name,type,parent_code\n000-00-0000,Cash,asset,\n",
"code,name,type,parent_code\n1000,Cash,asset,\n1001,Bank,asset,00-0000000\n",
] {
assert!(
matches!(parse_chart_csv(csv), Err(ChartCsvError::LooksLikeTin(_))),
"{csv}"
);
}
// A name is a party-style field: any run of nine digits.
let name = "code,name,type,parent_code\n1000,Acct 123456789,asset,\n";
assert!(matches!(
parse_chart_csv(name),
Err(ChartCsvError::LooksLikeTin(_))
));
}
#[test]
fn parses_optional_tax_category_column() {
let csv = "code,name,type,parent_code,tax_category\n4000,Sales,revenue,,gross_receipts\n1000,Cash,asset,,\n";