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>
82 lines
3.8 KiB
Rust
82 lines
3.8 KiB
Rust
use crate::*;
|
|
|
|
impl Books<'_> {
|
|
/// Where the entry event `q.entry` made stands (BS-entry-5), read from
|
|
/// the engine's own books: a draft's state (with its note when it awaits
|
|
/// evidence), posted (a posted entry has no state of its own), or gone
|
|
/// (a discarded draft leaves the ledger).
|
|
pub(crate) fn answer_draft_state(&self, q: &Query) -> Result<Value, Refusal> {
|
|
let n = q.entry.ok_or_else(|| self.missing("entry"))?;
|
|
let id = self.entry_or_refuse(n)?;
|
|
let mut m = JsonMap::new();
|
|
let state = match self.l().get_entry(id) {
|
|
None => "discarded",
|
|
Some(e) if e.status() == EntryStatus::Posted => "posted",
|
|
Some(e) => match e.draft_state() {
|
|
ledger_core::DraftState::Building => "building",
|
|
ledger_core::DraftState::AwaitingEvidence { note } => {
|
|
m.insert("note".to_string(), Value::String(note.clone()));
|
|
"awaiting_evidence"
|
|
}
|
|
},
|
|
};
|
|
m.insert("state".to_string(), Value::String(state.to_string()));
|
|
Ok(Value::Object(m))
|
|
}
|
|
|
|
/// The engine's one decision whether the entry event `q.entry` made
|
|
/// needs evidence (`ledger_core::evidence::requirement`, BS-entry-5): the
|
|
/// decision as the engine gives it, its reason or exemption read into
|
|
/// the examples' closed words.
|
|
pub(crate) fn answer_evidence(&self, q: &Query) -> Result<Value, Refusal> {
|
|
use ledger_core::evidence::{Requirement, requirement};
|
|
let n = q.entry.ok_or_else(|| self.missing("entry"))?;
|
|
let id = self.entry_or_refuse(n)?;
|
|
let entry = self
|
|
.l()
|
|
.get_entry(id)
|
|
.ok_or_else(|| self.missing("entry"))?;
|
|
let (decision, because) = match requirement(self.l(), entry, self.l().settings()) {
|
|
Requirement::Required { .. } => ("required", "policy"),
|
|
Requirement::Exempt { source } => (
|
|
"exempt",
|
|
// The engine words the source of an exemption in sentences;
|
|
// the examples' words are the closed list of BS-entry-5.
|
|
match source {
|
|
s if s.starts_with("the receipt policy") => "policy",
|
|
s if s.starts_with("a reversal") => "reversal",
|
|
s if s.starts_with("a period's closing entry") => "closing_entry",
|
|
s if s.starts_with("a schedule month's posting") => "schedule_posting",
|
|
s if s.starts_with("a depreciation run") => "depreciation_run",
|
|
s if s.starts_with("an asset's disposal") => "asset_disposal",
|
|
// A payroll command's posting (a run, or the tax
|
|
// remittance) is its own source, not a document's.
|
|
s if s.starts_with("a payroll") => "payroll_posting",
|
|
s if s.starts_with("a document's entry") => "document_entry",
|
|
other => {
|
|
return Err(engine_refusal(
|
|
RuleId::new(Area::Entry, 5),
|
|
format!("an exemption with no word in the examples: {other}"),
|
|
));
|
|
}
|
|
},
|
|
),
|
|
};
|
|
Ok(json_figures([
|
|
("decision".to_string(), decision.to_string()),
|
|
("because".to_string(), because.to_string()),
|
|
]))
|
|
}
|
|
}
|
|
|
|
/// Check a `draft_state` expectation: the state, and the note when the draft
|
|
/// awaits evidence, and nothing else.
|
|
pub(crate) fn check_draft_state(b: &Books<'_>, x: &Expect) {
|
|
check_figures(b, x, b.answer_draft_state(&x.query()));
|
|
}
|
|
|
|
/// Check an `evidence` expectation: the decision and why, both given.
|
|
pub(crate) fn check_evidence(b: &Books<'_>, x: &Expect) {
|
|
check_figures(b, x, b.answer_evidence(&x.query()));
|
|
}
|