test(core): the adapter's refused hand entries go through a real Store, and payroll is its own source

A hand entry the example says is refused when posted at once was made on a
clone of the Ledger and the receipt-gate error hand-built from
`evidence::requirement`, as `Store::post_entry_checked` builds it: the
adapter, not the engine, produced the refusal. A store journals a draft the
moment it is made, so the entry is now made, lined and posted on a rehearsal:
the books replayed from their journal into a Store of their own (the journal
and blobs copied, opened as any store is), and posted through
`post_entry_checked` under a policy, `post_entry` otherwise. The refusal is the
engine's own (ReceiptRequired included) and the example's books keep nothing.

A payroll run or tax remittance is exempt by its own source, so the engine's
"a payroll ..." sentence now reads as bookspec's new `payroll_posting`, not
`document_entry`. A draft reversal, which wanderbooks has no path for, is
returned as an unsupported-operation error (reported as "another refusal"), not
a panic that takes the harness down with it.

The claims for B-43 name the new example, entry-only-a-draft-can-be-posted-or-
discarded (a posted entry or a discarded draft is no draft), and the rehearsal.
Needs bookspec's x-h1c commits (payroll_posting, the new example, the
25.00 threshold example); the pin moves when they land.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-09 04:23:10 -07:00
1 parent d889f2e7fb
commit 56461c1bb6
4 files changed
+100 -33

No files matched your search

@@ -216,6 +216,50 @@ pub(crate) fn new_schedule(
}
}
/// A store of the books as they stood (see [`Books::rehearsal`]), and the
/// directory it lives in, which goes with it.
pub(crate) struct Rehearsal {
store: Store,
_dir: tempfile::TempDir,
}
impl std::ops::Deref for Rehearsal {
type Target = Store;
fn deref(&self) -> &Store {
&self.store
}
}
impl std::ops::DerefMut for Rehearsal {
fn deref_mut(&mut self) -> &mut Store {
&mut self.store
}
}
/// Copy the directory `from` to `to`, the entries `keep` names (by file
/// name) only, subdirectories whole.
fn copy_tree(
from: &std::path::Path,
to: &std::path::Path,
keep: &dyn Fn(&str) -> bool,
) -> std::io::Result<()> {
std::fs::create_dir_all(to)?;
for entry in std::fs::read_dir(from)? {
let entry = entry?;
let name = entry.file_name();
if !keep(&name.to_string_lossy()) {
continue;
}
let target = to.join(&name);
if entry.file_type()?.is_dir() {
copy_tree(&entry.path(), &target, &|_| true)?;
} else {
std::fs::copy(entry.path(), target)?;
}
}
Ok(())
}
impl<'a> Books<'a> {
/// The books an example sets up, before any event: its shape checked,
/// its accounts, fixed assets, schedules, parties, members, payees,
@@ -559,6 +603,27 @@ impl<'a> Books<'a> {
/// The entry event `event` (counting from 1) posted: an event applied
/// already, that posted exactly one.
/// The books as they stand, replayed from their journal into a store of
/// their own (a copy of the journal and the blobs, opened as any store
/// is), for a step the books must refuse without keeping a trace: a store
/// journals a draft the moment it is made, so a refused entry is made on
/// this and dropped with it. The directory lives as long as the store.
pub(crate) fn rehearsal(&self, what: &str) -> Rehearsal {
let from = self._dir.path().join("books");
let dir = tempfile::tempdir().unwrap();
let to = dir.path().join("books");
// The journal is the books; the database is derived, and the lock is
// this process's own.
copy_tree(&from, &to, &|name| {
name != ledger_store::store::LOCK_FILE
&& !ledger_store::store::is_database_file(name)
&& !name.contains(".db-")
})
.unwrap_or_else(|e| panic!("{what}: copying the books for a rehearsal: {e}"));
let store = took(Store::open(&to), &format!("{what}: the rehearsal"));
Rehearsal { store, _dir: dir }
}
pub(crate) fn entry_of(&self, event: usize, what: &str) -> EntryId {
assert!(
event >= 1 && event <= self.posted.len(),