fix(mcp): a CPA package the build will refuse leaves no decision on record

The override decisions (exporting without an audit, with open drafts) were
journaled once only the two named refusals were past, but build_package can
still refuse for what the books say, such as a member whose capital account
is not in the chart. That left 'was exported' on record with no package, and
a new decision on every retry.

When a decision is to be recorded, the build now runs once first, in memory:
it is read-only (the books by shared reference, written nowhere), so it
changes nothing, and it is left without the stored files and the vault, which
only a failing machine can refuse. Only if it succeeds is the decision
journaled and the package built for real. The spec block says what can still
fail after a decision (the machine) and that the decision then stands, with
the reason in the access log.

Test: a package refused for an unknown capital account, with an override
reason, journals nothing, on the first try and on the retry; it fails without
the dry run (the journal grows).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 20:18:39 -07:00
1 parent b70a8ab8eb
commit 30e5fcf6da
2 files changed
+86 -9

No files matched your search

+34
View File
@@ -333,6 +333,40 @@ fn cpa_package_refuses_open_draft() {
assert!(journal.contains("the CPA wants it before the receipt comes"));
}
/// A package the build will refuse is refused before any decision is
/// journaled (tools/reports.rs INVARIANT 4): the books name a member whose
/// capital account isn't in the chart, so the build can never succeed, and
/// an override (the reason for an open draft) must not leave "was exported"
/// on record, once or on a retry, with no package. The journal does not move.
#[test]
fn a_package_the_build_refuses_journals_no_decision_even_with_a_reason() {
let settings = format!(
"{SETTINGS}[[company.members]]\nname = \"Mo\"\nshare = \"100%\"\ncapital_account = \"3999\"\n"
);
let books = Books::with("p4-cpa-refused", "USD", Some(&settings));
let mut w = books.session("p4");
chart(&mut w);
draft(&mut w, "2026-03-10", "Open", "40.00");
let mut args = json!({"as_of": "2026-03-31", "cash_accounts": ["1000"]});
args["allow_open_drafts"] = json!({"reason": "the CPA wants it before the receipt comes"});
let before = books.journal().len();
for _ in 0..2 {
let why = answer_of(&w.call("books.export_cpa_package", args.clone()))
.expect_err("the build refuses an unknown capital account");
assert!(why.contains("unknown capital account 3999"), "{why}");
assert_eq!(
books.journal().len(),
before,
"a decision was journaled for a package that was refused"
);
}
assert!(
!String::from_utf8(books.journal())
.unwrap()
.contains("decision.recorded")
);
}
/// D-50: a confirm takes the preview it was shown; without it, or after a
/// changed argument or a write by another session, it is refused with
/// `stale_preview` before anything is written.