test(cli,store): through the server a refusal writes nothing, a bank file is masked, a chart file refused; the store's own texts meet the check

The store's attestation notes and model names, attachment and document
texts and the unlink, withdraw and void reasons are checked before
anything is journaled, like the engine's. Two end-to-end tests changed
their words (not their data): spec_projects expects "tax id" where it
expected "TIN", documents expects "tax id" where it expected
"taxpayer", for the refusal the new check now gives first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 15:38:14 -07:00
1 parent d2384dfe7c
commit 657daf43da
7 files changed
+298 -4

No files matched your search

+1 -1
View File
@@ -677,7 +677,7 @@ fn update_party_sets_and_clears_the_contact_block() {
json!({"party": party.to_string(), "phone": "123-45-6789"}),
)
.unwrap_err();
assert!(why.contains("taxpayer"), "{why}");
assert!(why.contains("tax id"), "{why}");
let why = m
.try_call(
"books.update_party",
+1 -1
View File
@@ -482,7 +482,7 @@ fn update_project_checks_every_field_before_writing() {
),
(
json!({"project": "Harbor", "notes": "SSN 123-45-6789"}),
"TIN",
"tax id",
),
(
json!({"project": "Nowhere", "status": "paused"}),
+200
View File
@@ -0,0 +1,200 @@
//! No tax id in a tool's text, through the real server as an agent reaches it
//! (BS-partner-2, WB-partner-15; the owner's choice of 2026-11-21).
//!
//! The law: a string that looks like a tax id (nine digits standing alone, an
//! SSN's 3-2-4, an EIN's 2-7) is refused before any write tool runs, in words
//! that name the field and never the number, and the journal is byte for byte
//! what it was; an invoice number, a phone number and a reference of ten
//! digits or more are no tax id; a bank file's descriptions are kept with such
//! a number masked to its last four digits and the answer says so; a chart file
//! with one is refused, naming its row and column. The fake ids are
//! `000-00-0000` and `00-0000000`.
use common::{Books, Wire, answer_of};
use serde_json::json;
mod common;
const SSN: &str = "000-00-0000";
const EIN: &str = "00-0000000";
fn setup(w: &mut Wire) {
for (code, name, kind) in [("1000", "Bank", "asset"), ("6000", "Supplies", "expense")] {
answer_of(&w.call(
"books.add_account",
json!({"code": code, "name": name, "account_type": kind}),
))
.unwrap();
}
}
/// Free text with a tax id in it is refused by every tool that keeps text,
/// before it runs: the journal does not change by a byte.
#[test]
fn a_tax_id_in_a_tools_text_is_refused_and_nothing_is_written() {
let books = Books::new("tin-text-refused");
let mut w = books.session("test");
setup(&mut w);
let before = books.journal_raw();
for (tool, args, field) in [
(
"books.add_class",
json!({"name": format!("Rondo {SSN}")}),
"the name of books.add_class",
),
(
"books.add_project",
json!({"name": "Harbor", "notes": format!("ein {EIN}")}),
"the notes of books.add_project",
),
(
"books.draft_entry",
json!({"date": "2026-03-01", "description": format!("paid {SSN}"), "no_party_reason": "test"}),
"the description of books.draft_entry",
),
(
"books.draft_entry",
json!({"date": "2026-03-01", "description": "ok", "no_party_reason": format!("own account {EIN}")}),
"the no_party_reason of books.draft_entry",
),
// A party's own fields are strict: any run of nine digits.
(
"books.add_customer",
json!({"name": "Acme 123456789"}),
"the name of books.add_customer",
),
(
"books.add_party",
json!({"name": format!("Pat {SSN}"), "roles": ["contractor"]}),
"the name of books.add_party",
),
(
"books.set_setting",
json!({"changes": [{"key": "company.name", "value": "Acme"}], "note": format!("see {SSN}")}),
"the note of books.set_setting",
),
] {
let why = answer_of(&w.call(tool, args)).unwrap_err();
assert!(
why.starts_with(&format!("{field} looks like it holds a tax id")),
"{tool}: {why}"
);
assert!(
why.contains("books.set_tin") && why.contains("W-9"),
"{why}"
);
assert!(
!why.contains("0000") && !why.contains("123456789"),
"never the number: {why}"
);
assert_eq!(
books.journal_raw(),
before,
"{tool}: a refusal writes nothing"
);
}
}
/// What is no tax id is kept: an invoice number, a phone number, a long
/// reference, an amount and a date.
#[test]
fn a_reference_is_no_tax_id() {
let books = Books::new("tin-text-kept");
let mut w = books.session("test");
setup(&mut w);
let out = answer_of(&w.call(
"books.draft_entry",
json!({"date": "2026-03-01",
"description": "inv 2026-11-0042, call 801-555-0142, ref 1234567890, $1,234,567.89",
"no_party_reason": "test"}),
))
.unwrap();
assert!(out["entry_id"].is_u64(), "{out}");
}
/// A bank file is kept whole with a nine-digit reference masked to its last
/// four digits; the answer says how many and where; the journal never holds
/// the number.
#[test]
fn a_bank_file_is_masked_not_refused() {
let books = Books::new("tin-bank-masked");
let mut w = books.session("test");
setup(&mut w);
let csv = format!(
"Date,Description,Amount\n2026-01-02,ACH {SSN} payroll,-12.50\n2026-01-03,CHECK 1234567890,-3.25\n2026-01-04,\"WIRE 000000000 and {EIN}\",-40.00\n"
);
let up = w.upload(csv.as_bytes(), "bank.csv", "text/csv", "import");
let out = answer_of(&w.call(
"books.import_bank_csv",
json!({"upload_id": up, "bank_account_code": "1000", "default_offset_code": "6000"}),
))
.unwrap();
assert_eq!(out["count"], 3, "{out}");
assert_eq!(out["masked_count"], 3, "{out}");
assert_eq!(
out["masked"],
json!([
{"row": 2, "column": "Description", "numbers": 1},
{"row": 4, "column": "Description", "numbers": 2},
])
);
let note = out["masked_note"].as_str().unwrap();
assert!(
note.starts_with("3 values in the Description column read as a tax id"),
"{note}"
);
assert!(
note.contains("lines 2, 4") && note.contains("books.set_tin"),
"{note}"
);
let descriptions: Vec<&str> = out["imported"]
.as_array()
.unwrap()
.iter()
.map(|t| t["description"].as_str().unwrap())
.collect();
assert_eq!(
descriptions,
[
"ACH \u{2022}\u{2022}\u{2022}-\u{2022}\u{2022}-0000 payroll",
"CHECK 1234567890",
"WIRE \u{2022}\u{2022}\u{2022}\u{2022}\u{2022}0000 and \u{2022}\u{2022}-\u{2022}\u{2022}\u{2022}0000",
]
);
let journal = String::from_utf8(books.journal_raw()).unwrap();
for needle in [SSN, EIN, "000000000"] {
for line in journal.lines().filter(|l| l.contains(needle)) {
let kind = serde_json::from_str::<serde_json::Value>(line).unwrap()["type"].clone();
// The line that makes the books holds zeros of its own (a hash).
assert_eq!(
kind, "store.created",
"the journal holds a tax id in a {kind} line"
);
}
}
assert!(
journal.contains("Bank import \u{2014} ACH \u{2022}"),
"the drafts are kept masked"
);
}
/// A chart file is typed by a person: a cell that looks like a tax id
/// refuses it whole, naming its row and column, and nothing is imported.
#[test]
fn a_chart_file_with_a_tax_id_is_refused_naming_its_row_and_column() {
let books = Books::new("tin-chart-refused");
let mut w = books.session("test");
let csv =
format!("code,name,type,parent_code\n1000,Cash,asset,\n1010,Payroll {SSN},asset,1000\n");
let up = w.upload(csv.as_bytes(), "chart.csv", "text/csv", "import");
let before = books.journal_raw();
let why = answer_of(&w.call("books.import_chart_csv", json!({"upload_id": up}))).unwrap_err();
assert!(
why.starts_with("the name cell of row 3 looks like it holds a tax id"),
"{why}"
);
assert!(!why.contains("0000"), "never the number: {why}");
assert_eq!(books.journal_raw(), before, "nothing was imported");
let chart = answer_of(&w.call("books.chart", json!({}))).unwrap();
assert!(!chart.to_string().contains("Payroll"), "{chart}");
}
+17
View File
@@ -372,6 +372,20 @@ pub struct Claim {
}
impl Claim {
/// The words a claim keeps (the note, the model's name) hold no tax id
/// (BS-partner-2): checked before anything is journaled.
fn check(&self) -> Result<(), StoreError> {
for (field, text) in [
("the note", self.note.as_deref()),
("the model", self.method.model.as_deref()),
] {
if let Some(t) = text {
ledger_core::LedgerError::free_text(field, t)?;
}
}
Ok(())
}
fn into_attestation(self, what: Attested) -> Attestation {
Attestation {
seq: 0,
@@ -731,6 +745,7 @@ impl Store {
date: NaiveDate,
claim: Claim,
) -> Result<Attestation, StoreError> {
claim.check()?;
self.ensure_feature(crate::format::AUDITS)?;
let entry = self
.ledger
@@ -775,6 +790,7 @@ impl Store {
/// Record that an entry was reviewed whole (`entry.reviewed`).
pub fn review_entry(&mut self, entry_id: u64, claim: Claim) -> Result<Attestation, StoreError> {
claim.check()?;
self.ensure_feature(crate::format::AUDITS)?;
let entry = self
.ledger
@@ -817,6 +833,7 @@ impl Store {
period_id: u64,
claim: Claim,
) -> Result<(Attestation, AuditRun), StoreError> {
claim.check()?;
self.ensure_feature(crate::format::AUDITS)?;
let run = self.run_for_period(period_id)?;
let a = self.journal_attestation(
+71
View File
@@ -301,6 +301,77 @@ fn stale_head_period_attestation_refused() {
s.verify().unwrap();
}
/// BS-partner-2 (WB-partner-15): the store's own texts (a file's name and
/// description, the reasons for unlinking, withdrawing and voiding, an
/// attestation's note, an entry's description) meet the one free-text check
/// before anything is journaled, whoever calls.
#[test]
fn the_store_refuses_text_that_looks_like_a_tax_id_and_journals_nothing() {
use ledger_core::LedgerError;
let dir = test_dir("tin-text");
let (mut s, fx) = books(&dir, None);
let tin = "000-00-0000";
let refused = |r: Result<(), StoreError>, what: &str| match r {
Err(StoreError::Ledger(LedgerError::FreeTextHoldsTin(why))) => {
assert!(!why.contains("0000"), "{what}: never the number: {why}");
}
other => panic!("{what}: expected a refusal for the tax id, got {other:?}"),
};
let (att, _, _) = s
.attach_receipt(Some(fx.entry), "r.txt", "text/plain", b"paper 40.00", None)
.unwrap();
let head = s.head();
refused(
s.attach_receipt(
None,
"s.txt",
"text/plain",
b"other",
Some(&format!("paid {tin}")),
)
.map(drop),
"a description",
);
refused(
s.attach_receipt(None, &format!("w9 {tin}.txt"), "text/plain", b"other", None)
.map(drop),
"a file name",
);
refused(
s.file_document(
"tax",
"t.txt",
"text/plain",
b"doc",
Some(&format!("ein {tin}")),
)
.map(drop),
"a document's description",
);
refused(
s.unlink_receipt(att, &format!("dup {tin}")).map(drop),
"an unlink reason",
);
refused(
s.withdraw_attachment(att, &format!("dup {tin}")),
"a withdraw reason",
);
refused(
s.create_entry(d(2, 1), &format!("x {tin}")).map(drop),
"an entry description",
);
refused(
s.reverse_entry(fx.entry, d(2, 1), &format!("x {tin}"))
.map(drop),
"a reversal",
);
let mut c = claim("high");
c.note = Some(format!("see {tin}"));
refused(s.review_entry(fx.entry, c).map(drop), "an attestation note");
assert_eq!(s.head(), head, "a refusal journals nothing");
s.verify().unwrap();
}
/// The integrity table: each code seeded alone.
#[test]
fn integrity_detects_each_seeded_defect() {
+7 -2
View File
@@ -368,13 +368,18 @@ warning, and never the number.
`Ledger::check_no_party_reason`; `ledger-mcp` `text_fields`,
`books.import_bank_csv`, `books.import_chart_csv`; `ledger-import`
`parse_bank_csv_masked`, `parse_chart_csv`; `ledger-store`
`integrity_findings`. **Checked:** `ledger-core` `tests/free_text_tin.rs`
`integrity_findings`, `Store::attach_receipt`, `Store::file_document`,
`Store::unlink_receipt`, `Store::withdraw_attachment`, `Store::review_entry`.
**Checked:** `ledger-core` `tests/free_text_tin.rs`
(every grouping with every separator is found, nine digits alone, the
allow-list passes, each command refuses, a replay never does);
`ledger-mcp` the unit tests in `text_fields.rs` (every string a write tool
takes is classed) and `a_call_with_a_tax_id_in_free_text_is_refused_unrun_and_writes_nothing`;
`ledger-import` the unit tests in `bank_csv.rs` and `chart_csv.rs`;
`ledger-store` `tests/audit.rs`.
`ledger-store` `tests/audit.rs` (the store's own texts, and a journal line
an earlier version took opens and is named by the audit); `ledger-cli`
`tests/tin_in_text.rs` (through the real server: a refusal writes nothing,
a reference is kept, a bank file is masked, a chart file is refused).
## B-35 A party's part of an entry, and a party's totals
+1
View File
@@ -99,6 +99,7 @@ that would fail if it broke:
| A file with full TINs is never written to a path (handed over instead, D-29), and never filed into the books: every file the server read or wrote with TINs (from any session, after a restart, out of a CPA package), by every filing tool | `mcp_journeys.rs` `tin_bearing_files_are_refused_when_given_back_to_be_filed`; `spec_vault.rs` `a_package_is_handed_over_and_never_written`; `tin_files.rs` (tests) `a_tin_bearing_file_is_refused_from_every_session_and_after_a_restart`; unit test `a_recorded_tin_file_is_refused_by_every_reader_of_the_registry` |
| Text filed into the books is refused when it holds a TIN the vault keeps (nine digits, 3-2-4 by hyphen, space or dot, 2-7 by hyphen or space, anywhere) or a stand-alone printed SSN or EIN (123-45-6789, 12-3456789), and only then: a bank export (routing numbers, long references, a date next to an amount) and a longer number holding an SSN shape go in; a locked vault leaves the printed shapes (BS-partner-2) | `tin_files.rs` (tests) `text_with_a_vault_tin_or_a_printed_one_is_refused_and_a_bank_export_is_not`; unit tests `text_holding_a_vault_tin_is_refused_in_every_rendering`, `a_printed_ssn_or_ein_is_refused`, `a_longer_number_holding_a_tin_shape_passes`, `an_ordinary_bank_export_passes`, `binary_bytes_are_not_scanned` |
| Filing is no TIN oracle: text with more than two TIN-shaped numbers ending in a known TIN's last four (the books' TIN and W-9 facts, then the vault's own) is refused before the vault is opened, byte for byte alike whether one is the vault's TIN or none is, the vault open or locked, by every filing tool; one or two such numbers are compared against the vault, one number written many ways counts once, and other last fours never count (BS-partner-2) | `tin_files.rs` (tests) `text_probing_for_a_tin_is_refused_alike_by_every_filing_tool`; unit tests `text_probing_for_a_tin_is_refused_alike_whether_or_not_it_holds_it` (the vault never opened for a probe), `one_or_two_candidates_are_compared_against_the_vault` |
| Free text (a memo, note, reason, description, reference, a class, project or period name, a receipt's words) is refused when it looks like a tax id (nine digits alone, 3-2-4, 2-7, any dash, dot or space, in any Unicode form) and an invoice number, a phone number, a reference of ten digits or more, an amount and a date pass; a party's own fields stay strict; the refusal names the field, says where a tax id goes and never repeats it; every string of every write tool is classed in one table and a new one fails the build; a bank file is kept with the number masked to its last four and the answer says how many and where; a chart file is refused naming row and column; a journal line an earlier version took replays and the audit names it (WB-partner-15) | `tests/free_text_tin.rs` (ledger-core: every grouping, every separator, the allow-list, each command, replay); `text_fields.rs` unit tests `every_string_a_write_tool_takes_is_in_the_table`, `the_table_names_only_strings_the_tools_take`; `server_tests.rs` `a_call_with_a_tax_id_in_free_text_is_refused_unrun_and_writes_nothing`; `bank_csv.rs` and `chart_csv.rs` unit tests; `ledger-store` `tests/audit.rs` `the_store_refuses_text_that_looks_like_a_tax_id_and_journals_nothing`, `integrity_detects_each_seeded_defect`; `ledger-cli` `tests/tin_in_text.rs` |
| The connect text fits its budgets, its lead stands alone, it states the receipt rule enforced (exact threshold in the base currency, required and exempt accounts, reversals) and the parties rule in force, and the company name can't break it (control and format characters) | `handbook.rs` `instructions_budget`, `a_typical_company_gets_the_whole_connect_text`, `the_company_name_is_one_plain_line`; `receipt_policy.rs` `the_rule_told_is_the_rule_enforced`, `a_long_or_odd_account_list_stays_short_and_plain`; a new session is told the settings in force: `a_new_session_is_told_the_settings_in_force` |
| No text the agent is given (whole tool JSON, resources, connect text, handbook, every error template and refusal) points at files, git, GitHub, repo docs, flags or helper commands; descriptions fit 700 characters (listed exceptions, P5; and what git itself said of a failed backup, which `books.backup` passes on to the human as git said it, its paths hidden) | `tool_text_lint`, `tool_descriptions_fit_700_characters`; `ledger-core` `an_unknown_year_threshold_is_never_guessed` |
| Every tool is annotated (openWorldHint false on all but `books.back_up_now`), and the read-only hint is true in behaviour (journal, every file of the books' folder but what every call writes by design: the access log, `ops/` (the viewer's side channel for `books.show`, which is not the books), the books' own backup and the files handed over; the database's rows and the vault unchanged) | `annotations_complete`; `spec_mcp.rs` `read_only_tools_change_nothing` (checked on every call in `Mcp::tool`) |