feat(mcp): every write call is one transaction with a request key (P15 T1, D-88, D-89)

Accounting reasoning: these are financial books reached over the internet,
where a request is retried. A write whose answer is lost and then sent again
must not post twice, a call half done must not be left looking done, and a
failed write must be on the record.

Every tool that can change the books (83 of the 140: three that only read
what is sealed and may answer with a TIN are reads) takes a required
`request_key`, added to its schema in tools/list and taken out of the
arguments before the tool runs, so no tool, preview digest or check changes.
A write without a usable key is refused in words. Write calls take turns,
and each runs as one transaction of the store: opened (or answered from the
books if its key committed: the same tool and arguments return the first
answer and write nothing; other arguments are refused as a misuse of the
key; the access log says `repeat`), then closed with its answer if it
answered ok, or rolled back and closed `failed` if it errored, failed or was
stopped by a close. Books an older version wrote take no write at all until
the owner's go-ahead (D-89): every write is refused with the upgrade remedy;
reads work as ever. `books.import_bank_csv` is one transaction like the rest.

The handbook, docs/mcp-interface.md, the claims (WB-format-8 to 12, and
WB-format-3 amended for D-89) and docs/parity.md say so. Tests that wrote to
old books through the tools now assert the refusal and write after the
upgrade; the shared wire helpers add a fresh key to every tool call (the
journal helpers leave the call frames out, as they left out nothing before),
so no other test changed. The store-level `_waits_for_<feature>` tests still
check each feature's own gate. No figure and no golden moved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 09:43:52 -07:00
1 parent 2633109d55
commit e542319e63
25 files changed
+1084 -186

No files matched your search

+24 -9
View File
@@ -71,7 +71,13 @@ fn books_toml(dir: &Path, company: &str, books_extra: &str) -> PathBuf {
impl Mcp {
fn start(dir: &TestDir, toml: &Path) -> Self {
let wire = dir.start(Some(&std::fs::read_to_string(toml).unwrap()));
Self::start_settings(dir, Some(&std::fs::read_to_string(toml).unwrap()))
}
/// [`Mcp::start`] with these settings, or none (books that take no
/// write, D-89, can't be given any).
fn start_settings(dir: &TestDir, settings: Option<&str>) -> Self {
let wire = dir.start(settings);
let mut mcp = Self {
books_dir: None,
wire,
@@ -101,8 +107,11 @@ impl Mcp {
mcp
}
/// The journal, without the frames of tool calls (D-88).
fn journal(&self) -> Vec<u8> {
std::fs::read(self.data.join("journal.jsonl")).unwrap_or_default()
common::without_call_lines(
&std::fs::read(self.data.join("journal.jsonl")).unwrap_or_default(),
)
}
/// The journal's line types, in order.
@@ -300,6 +309,12 @@ fn books_in(name: &str, p2: bool) -> Mcp {
.unwrap();
}
let toml = books_toml(&dir, "Spec Co", "financing_accounts = [\"2100\"]\n");
if p2 {
// Books that take no write (D-89): no settings, no chart.
let mut m = Mcp::start_settings(&dir, None);
m.books_dir = Some(dir);
return m;
}
let mut m = Mcp::start(&dir, &toml);
m.accounts(CHART);
m.books_dir = Some(dir);
@@ -321,6 +336,7 @@ impl Mcp {
.unwrap()
.expect("P2's books wait for the upgrade");
let mut m = Mcp::start(&dir, &dir.join("wanderbooks.toml"));
m.accounts(CHART);
m.books_dir = Some(dir);
m
}
@@ -623,18 +639,17 @@ fn set_w9_asks_for_the_w9_flags_feature_before_its_first_line() {
let w9 = json!({"party": "Harbor Design LLC", "received_on": "2026-03-02",
"entity_type": "LLC (partnership)", "tin_last4": "4321", "kept_at": "CPA portal"});
let mut m = books_in("set-w9-feature", true);
let why = m.refuse("books.set_w9", w9.clone());
assert!(why.starts_with("format_upgrade_pending:"), "{why}");
assert!(why.contains("nothing can be written"), "{why}");
assert_eq!(m.count("party.w9_set"), 0, "nothing half done");
let mut m = m.upgraded();
m.add_party("Harbor Design LLC", &["contractor"]);
m.ok("books.add_vendor", json!({"name": "Harbor Design LLC"}));
let why = m.refuse("books.set_w9", w9.clone());
assert!(
why.starts_with("format_upgrade_pending:") && why.contains("vendor_1099_decisions"),
"{why}"
);
assert_eq!(m.count("party.w9_set"), 0, "nothing half done");
let mut fresh = books("set-w9-feature-new");
fresh.add_party("Harbor Design LLC", &["contractor"]);
fresh.ok("books.add_vendor", json!({"name": "Harbor Design LLC"}));
for mut m in [m.upgraded(), fresh] {
for mut m in [m, fresh] {
let before = m.journal_types().len();
m.ok("books.set_w9", w9.clone());
let added = m.journal_types()[before..].to_vec();