Merge branch 't3/refuse-tax-ids-in-free-text': free text refuses a tax id's shapes; references take nine digits; bank files mask (WB-partner-15)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
e7d5e4b8cd
36 files changed
+4353
-113
No files matched your search
@@ -133,6 +133,9 @@ pub(crate) const STOPPED: &str = "stopped";
|
||||
pub(crate) const STOPPED_BY_CLOSE: &str = "stopped_by_close";
|
||||
/// A file's bytes or text came as an argument (D-46).
|
||||
pub(crate) const INLINE_FILE: &str = "inline_file";
|
||||
/// A call refused unrun because a string in it looks like a tax id
|
||||
/// (text_fields.rs).
|
||||
pub(crate) const TIN_IN_TEXT: &str = "tin_in_text";
|
||||
|
||||
/// What a refused call is told when its record couldn't be kept, or a
|
||||
/// call that ran is told instead of its answer (INVARIANT 3).
|
||||
|
||||
@@ -1588,6 +1588,8 @@ mod next_steps;
|
||||
mod projects;
|
||||
#[path = "tools/prompts.rs"]
|
||||
mod prompts;
|
||||
#[path = "text_fields.rs"]
|
||||
mod text_fields;
|
||||
pub use kept::SettingKeyOut;
|
||||
|
||||
// The tool groups: one file each (plan/served.md 8.2 U0a). A unit adds a
|
||||
@@ -1934,6 +1936,15 @@ impl ServerHandler for BooksServer {
|
||||
}
|
||||
calls::key_problem(request_key.as_ref())
|
||||
.map(|why| (calls::MISSING_KEY, Ok(tool_error(why))))
|
||||
})
|
||||
// A string that looks like a tax id isn't run, whatever it was for:
|
||||
// the vault is where one goes (text_fields.rs INVARIANT 5).
|
||||
.or_else(|| {
|
||||
if !calls::writes(&request.name) {
|
||||
return None;
|
||||
}
|
||||
text_fields::refusal(&request.name, request.arguments.as_ref())
|
||||
.map(|why| (access::TIN_IN_TEXT, Ok(tool_error(why))))
|
||||
});
|
||||
if let Some((code, answer)) = refusal {
|
||||
call.digested(refused_digest(request.arguments.clone()).await);
|
||||
|
||||
@@ -1702,3 +1702,59 @@ fn the_envelope_keeps_what_a_tool_said_and_carries_a_refusal_guard() {
|
||||
assert_eq!(g["code"], "approval_required");
|
||||
assert_eq!(g["remedy_tool"], "books.approve_entry");
|
||||
}
|
||||
|
||||
/// text_fields.rs INVARIANT 5 (WB-format-10): a call with a string that
|
||||
/// looks like a tax id is refused before it runs, in words that name the
|
||||
/// field and never repeat the number; the books are as they were and the
|
||||
/// access record says why. A reference that is no tax id goes on to the tool.
|
||||
#[test]
|
||||
fn a_call_with_a_tax_id_in_free_text_is_refused_unrun_and_writes_nothing() {
|
||||
rt().block_on(async {
|
||||
let s = session("tin-text").await;
|
||||
let (server, books) = logged("tin-text");
|
||||
let key = "key-0123456789";
|
||||
let add = |name: &str| {
|
||||
tool_call(
|
||||
"books.add_class",
|
||||
serde_json::json!({"name": name, "request_key": key}),
|
||||
)
|
||||
};
|
||||
let (refusal, text) = answer(
|
||||
server
|
||||
.call_tool(add("Rondo 000-00-0000"), context(&s.peer, Some(ALL)))
|
||||
.await,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(refusal, "{text}");
|
||||
assert!(
|
||||
text.starts_with("the name of books.add_class looks like it holds a tax id"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("books.set_tin") && text.contains("W-9"), "{text}");
|
||||
assert!(!text.contains("000"), "never the number: {text}");
|
||||
// A preview is refused too: its text would be shown to a person.
|
||||
let draft = tool_call(
|
||||
"books.draft_entry",
|
||||
serde_json::json!({"date": "2026-11-21", "description": "pay 00-0000000", "request_key": key}),
|
||||
);
|
||||
let (refusal, text) =
|
||||
answer(server.call_tool(draft, context(&s.peer, Some(ALL))).await).unwrap();
|
||||
assert!(refusal && text.contains("the description of books.draft_entry"), "{text}");
|
||||
// Nothing was made: no class, no entry.
|
||||
let projects = tool_call("books.projects", serde_json::json!({}));
|
||||
let (refusal, text) =
|
||||
answer(server.call_tool(projects, context(&s.peer, Some(ALL))).await).unwrap();
|
||||
assert!(!refusal && !text.contains("Rondo"), "{text}");
|
||||
// A reference that is no tax id is not refused for being one.
|
||||
let (_, text) = answer(
|
||||
server
|
||||
.call_tool(add("Rondo 2026-11-0042"), context(&s.peer, Some(ALL)))
|
||||
.await,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!text.contains("looks like it holds a tax id"), "{text}");
|
||||
let log = records(&books);
|
||||
assert_eq!(log[0], ("books.add_class".into(), refused("tin_in_text"), true));
|
||||
assert_eq!(log[1], ("books.draft_entry".into(), refused("tin_in_text"), true));
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -371,7 +371,7 @@ impl BooksServer {
|
||||
#[tool(
|
||||
name = "books.import_chart_csv",
|
||||
title = "Import a chart of accounts",
|
||||
description = "Import a chart of accounts from CSV (header: code,name,type,parent_code,tax_category; the last is optional), as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Types: asset, liability, equity, revenue, expense. Parents must come before children. Fails on the first bad row; nothing is half-imported. A revenue or expense row without a tax_category is listed in warnings, or, under policy.require_tax_category = refuse, refuses the file.",
|
||||
description = "Import a chart of accounts from CSV (header: code,name,type,parent_code,tax_category; the last is optional), as upload_id: upload it with books.begin_upload purpose import and `wanderbooks upload` (a file never passes through you). Types: asset, liability, equity, revenue, expense. Parents must come before children. Fails on the first bad row, a cell that looks like a tax id included (it names the row and column); nothing is half-imported. A revenue or expense row without a tax_category is listed in warnings, or, under policy.require_tax_category = refuse, refuses the file.",
|
||||
annotations(
|
||||
read_only_hint = false,
|
||||
destructive_hint = false,
|
||||
|
||||
@@ -474,10 +474,10 @@ impl BooksServer {
|
||||
"due_date, or terms, or the customer's default terms, or invoicing.default_terms",
|
||||
)?;
|
||||
if let Some(r) = &p.customer_ref {
|
||||
ledger_core::parties::check_text("the customer reference", r)?;
|
||||
ledger_core::parties::check_reference_note("the customer reference", r)?;
|
||||
}
|
||||
if let Some(m) = &p.memo {
|
||||
ledger_core::parties::check_text("the memo", m)?;
|
||||
ledger_core::parties::check_note("the memo", m)?;
|
||||
}
|
||||
let settings = self.settings();
|
||||
let fields = arap::InvoiceFields {
|
||||
@@ -616,10 +616,10 @@ impl BooksServer {
|
||||
);
|
||||
}
|
||||
if let Some(m) = &p.memo {
|
||||
ledger_core::parties::check_text("the memo", m)?;
|
||||
ledger_core::parties::check_note("the memo", m)?;
|
||||
}
|
||||
if let Some(r) = &p.duplicate_reason {
|
||||
ledger_core::parties::check_text("the duplicate reason", r)?;
|
||||
ledger_core::parties::check_note("the duplicate reason", r)?;
|
||||
}
|
||||
// The file is taken before anything is written: an upload is used
|
||||
// up only by the call that files it (files.rs INVARIANT 1).
|
||||
|
||||
@@ -709,7 +709,7 @@ impl BooksServer {
|
||||
#[tool(
|
||||
name = "books.import_bank_csv",
|
||||
title = "Import a bank CSV as drafts",
|
||||
description = "Import a bank or card CSV (Date, Description, Amount; or Date, Description, money out, money in) as one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other. Give the CSV as upload_id (books.begin_upload purpose import; a file never passes through you). Ambiguous slash dates need date_order. Review with books.digest, then post. Also file the export (books.file_document category import_source) and pass source_attachment_id. Details in books.handbook section files-in-out.",
|
||||
description = "Import a bank or card CSV (Date, Description, Amount; or Date, Description, money out, money in) as one DRAFT entry per transaction, all or none: the bank account on one side, a categorized offset on the other. Give the CSV as upload_id (books.begin_upload purpose import; a file never passes through you). Ambiguous slash dates need date_order. A description holding a number that reads as a tax id is kept masked to its last four digits (masked_count, masked). Review with books.digest, then post. Also file the export (books.file_document category import_source) and pass source_attachment_id. Details in books.handbook section files-in-out.",
|
||||
annotations(
|
||||
read_only_hint = false,
|
||||
destructive_hint = false,
|
||||
@@ -732,7 +732,14 @@ impl BooksServer {
|
||||
}
|
||||
};
|
||||
let (csv, claim) = self.csv_given(&p.upload_id)?;
|
||||
let txns = ledger_import::parse_bank_csv_with(&csv, order).map_err(|e| e.to_string())?;
|
||||
// A description a bank wrote is not typed by a person: a number in
|
||||
// it that reads as a tax id is kept masked to its last four digits
|
||||
// and named in the answer, never a reason to refuse the file.
|
||||
let ledger_import::MaskedBankImport {
|
||||
transactions: txns,
|
||||
masked,
|
||||
as_written,
|
||||
} = ledger_import::parse_bank_csv_masked(&csv, order).map_err(|e| e.to_string())?;
|
||||
let mut store = self.lock()?;
|
||||
let bank = store
|
||||
.ledger()
|
||||
@@ -788,8 +795,10 @@ impl BooksServer {
|
||||
// can't become a draft (a date in a closed period, say) refuses the
|
||||
// file instead of leaving the ones before it behind.
|
||||
let mut scratch = store.ledger().clone();
|
||||
for txn in &txns {
|
||||
let (offset_id, _) = offset_for(&txn.description);
|
||||
for (txn, written) in txns.iter().zip(&as_written) {
|
||||
// A rule reads the bank's own words, a nine-digit reference
|
||||
// in them included; what is kept is the masked text.
|
||||
let (offset_id, _) = offset_for(written);
|
||||
let amount = Money::new(txn.amount.abs(), base);
|
||||
let (bank_side, offset_side) = if txn.amount > Decimal::ZERO {
|
||||
(Side::Debit, Side::Credit)
|
||||
@@ -806,8 +815,8 @@ impl BooksServer {
|
||||
// Rehearsed whole: the upload is used up as the writing begins.
|
||||
files::filed(claim);
|
||||
let mut imported = Vec::new();
|
||||
for txn in txns {
|
||||
let (offset_id, offset_code) = offset_for(&txn.description);
|
||||
for (txn, written) in txns.into_iter().zip(&as_written) {
|
||||
let (offset_id, offset_code) = offset_for(written);
|
||||
let amount = Money::new(txn.amount.abs(), store.ledger().base_currency());
|
||||
let entry_id = store
|
||||
.create_entry(txn.date, &format!("Bank import — {}", txn.description))
|
||||
@@ -838,11 +847,34 @@ impl BooksServer {
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
let count = imported.len();
|
||||
let masked_count: usize = masked
|
||||
.iter()
|
||||
.fold(0, |n: usize, m| n.saturating_add(m.numbers));
|
||||
let masked_note = (masked_count > 0).then(|| {
|
||||
let lines: Vec<String> = masked.iter().map(|m| m.line.to_string()).collect();
|
||||
format!(
|
||||
"{masked_count} value{} in the Description column read as a tax id (nine digits standing alone, or an SSN's or an EIN's shape) and {} kept masked to the last four digits, on line{} {}. A bank's description is not typed by a person and often carries a nine-digit reference, so the file was not refused; a tax id is stored only with books.set_tin or a W-9 (books.set_w9)",
|
||||
if masked_count == 1 { "" } else { "s" },
|
||||
if masked_count == 1 { "was" } else { "were" },
|
||||
if lines.len() == 1 { "" } else { "s" },
|
||||
lines.join(", ")
|
||||
)
|
||||
});
|
||||
Ok(Json(ImportBankCsvOut {
|
||||
imported,
|
||||
count,
|
||||
source_attachment_id: p.source_attachment_id,
|
||||
source_linked: link_source,
|
||||
masked_count,
|
||||
masked: masked
|
||||
.into_iter()
|
||||
.map(|m| MaskedCellOut {
|
||||
row: m.line,
|
||||
column: m.column.to_string(),
|
||||
numbers: m.numbers,
|
||||
})
|
||||
.collect(),
|
||||
masked_note,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,7 +1550,7 @@ impl BooksServer {
|
||||
if r.trim().is_empty() {
|
||||
return Err("say why the entry has no counterparty".into());
|
||||
}
|
||||
ledger_core::parties::check_text("reason", r)?;
|
||||
ledger_core::parties::check_note("the reason", r)?;
|
||||
store
|
||||
.set_entry_party(p.entry_id, None)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
@@ -1368,6 +1368,29 @@ pub struct ImportBankCsvOut {
|
||||
/// True when this call linked it to the account (false when it already
|
||||
/// was, or none was given).
|
||||
pub source_linked: bool,
|
||||
/// How many descriptions held a number that reads as a tax id (nine
|
||||
/// digits standing alone, an SSN's or an EIN's shape) and were kept
|
||||
/// masked to its last four digits: a bank's description is not typed by
|
||||
/// a person and often carries a nine-digit reference, so the file is
|
||||
/// not refused for one (BS-partner-2).
|
||||
pub masked_count: usize,
|
||||
/// Which descriptions were masked, by the file's line.
|
||||
pub masked: Vec<MaskedCellOut>,
|
||||
/// What masking did, in words; present when `masked_count` is above
|
||||
/// zero.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub masked_note: Option<String>,
|
||||
}
|
||||
|
||||
/// One description of a bank file that was kept masked.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
pub struct MaskedCellOut {
|
||||
/// The file's line (the first line is 1).
|
||||
pub row: u64,
|
||||
/// The column: "Description".
|
||||
pub column: String,
|
||||
/// How many numbers in the cell were masked.
|
||||
pub numbers: usize,
|
||||
}
|
||||
|
||||
/// Parameters for `books.import_chart_csv`. No other argument is taken: a
|
||||
|
||||
Reference in new issue
Block a user