fix(core,mcp,store): a phone number is kept and a ZIP+4 is kept; only a tax id's printed shapes are refused in a phone

A telephone is ten digits or more, so the strict reading of a party's fields
(any run of nine digits) refused every phone number: the bill-to snapshot's
check, new with the free-text change, refused `503-555-0100` and failed the
window's invoice test. The party's own phone (since D-55) and the tool's
bill-to phone had always been refused the same way; only 7-digit test
numbers hid it.

A phone field (a party's, a bill-to's, the seller's) is now its own class,
read as a reference is: refuse the printed SSN 3-2-4 and EIN 2-7 and nothing
else, since a nine-digit national number is ordinary. A postal address
keeps the strict reading except a ZIP+4 (`98101-1234`, five and four, nine
digits), a postal code. The formation state's entity number is a
registration number (a Washington UBI is nine digits) and is read as a
reference. The tools' table, the engine, and the audit's keys agree; the
audit reads `phone` and `fax` as a phone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 20:50:23 -07:00
1 parent 1dbca94bd2
commit c206652abe
12 files changed
+725 -52

No files matched your search

+44
View File
@@ -717,6 +717,50 @@ pub fn check_text(field: &str, text: &str) -> Result<(), String> {
Ok(())
}
/// [`has_full_tin`] for a postal address: the same strict reading, except
/// that a ZIP+4 (five digits, a hyphen, four digits, standing alone:
/// `98101-1234`) is a postal code, not a tax id, though it is nine digits.
pub fn has_full_tin_in_address(text: &str) -> bool {
let chars: Vec<char> = text.chars().collect();
let runs = if REPLAYING.with(std::cell::Cell::get) {
journaled_tin_runs(&chars)
} else {
full_tin_runs(&chars)
};
runs.iter().any(|&(first, last)| {
let run = &chars[first..=last];
let zip_plus_4 = run.len() == 10
&& run[5] == '-'
&& run
.iter()
.enumerate()
.all(|(i, c)| i == 5 || c.is_ascii_digit());
!zip_plus_4
})
}
/// [`check_text`] for a postal address: a ZIP+4 is allowed
/// ([`has_full_tin_in_address`]); every other run of nine digits is refused.
pub fn check_address(field: &str, text: &str) -> Result<(), String> {
if has_full_tin_in_address(text) {
return Err(format!(
"{field} looks like it holds a full taxpayer identification number; \
the books keep only its last four digits (the full number belongs in the vault)"
));
}
// The length and control-character bounds are the other text's.
check_note_form(field, text)
}
/// Check a telephone or fax number: not a tax id's printed shapes (an SSN's
/// 3-2-4, an EIN's 2-7: [`crate::settings::check_phone_text`]); every other
/// number is a phone's, whatever its digits or grouping. At most 500
/// characters, no control characters except newline.
pub fn check_phone(field: &str, text: &str) -> Result<(), String> {
crate::settings::check_phone_text(field, text)?;
check_note_form(field, text)
}
/// Check a free text field: no tax id's shape (a nine-digit number standing
/// alone, an SSN's 3-2-4, an EIN's 2-7: [`crate::settings::check_free_text`]),
/// at most 500 characters, no control characters except newline. For a