merge: P6, the evidence pipeline (branch P6, checkpoint ce366408)
The last of the paused branches, from its "not for merge" checkpoint:
extraction in ledger-import (text, pages, page images; capped, caught),
journaled as attachment.text_extracted; dedup by hash with
books.find_attachment and books.consolidate_duplicates; annotations and
books.set_entry_settles; the company record categories; the two fuzz
targets; feature attachment_text. Nineteen files conflicted with the
four P4b merges, resolved as plan 8.0.2 says: P6 retakes schema 18 (it
had taken 16, which S4.3 holds; S5 holds 17); the tool table is 129 and
the destructive count 31; both sides' appends kept with their seams
restored; one B-27 paragraph naming every feature; in the old-books
fixture P6's hand-written reimbursement is entry 7 (its ids collided
with S4.3's invoice); the replay fuzzer's list gains S7's
invoice.written_off; S4.3's issued-PDF test expects the extraction
record P6 journals right after a filing.
One integration defect between S7 and P6, found by the arap property
test and fixed here: under P6's dedup, a write-off whose evidence bytes
were filed already (the same collection letter for a second write-off of
the same invoice) was refused only after its entry had been journaled,
at the final link to the invoice ("already linked"). The write-off now
resolves the dedup before anything is journaled and keeps a link the
record already has to the invoice instead of refusing it; an explicit
existing_attachment_id already on an entry is still refused (S7's
one-receipt-once rule). P6's gate never ran before the pause; it runs on
main after this merge, and its ledger-store -> ledger-import dependency
is the open review point (plan 8.0.1).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
commit
2ad192bbcd
70 files changed
+4618
-384
No files matched your search
@@ -349,6 +349,12 @@ pub struct Ledger {
|
||||
/// Conventions, decisions, open items and approvals
|
||||
/// ([`crate::conventions`]).
|
||||
conventions: crate::conventions::Conventions,
|
||||
/// The facts recorded about each filed file ([`crate::evidence`],
|
||||
/// `attachment.annotated`), by attachment id.
|
||||
annotations: std::collections::BTreeMap<u64, crate::evidence::Annotation>,
|
||||
/// What each entry settles (`entry.settles`, plan P6): the one record
|
||||
/// a member-paid entry's "reimbursed" is derived from (IZ-18).
|
||||
entry_settles: std::collections::BTreeMap<EntryId, Vec<EntryId>>,
|
||||
}
|
||||
|
||||
impl Ledger {
|
||||
@@ -403,6 +409,8 @@ impl Ledger {
|
||||
entry_no_party: HashMap::new(),
|
||||
settings: crate::settings::Settings::default(),
|
||||
conventions: crate::conventions::Conventions::default(),
|
||||
annotations: std::collections::BTreeMap::new(),
|
||||
entry_settles: std::collections::BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,6 +824,8 @@ impl Ledger {
|
||||
),
|
||||
("settings", self.settings == other.settings),
|
||||
("conventions", self.conventions == other.conventions),
|
||||
("annotations", self.annotations == other.annotations),
|
||||
("entry_settles", self.entry_settles == other.entry_settles),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|(_, same)| !same)
|
||||
@@ -8334,6 +8344,101 @@ impl Ledger {
|
||||
&self.conventions
|
||||
}
|
||||
|
||||
/// The facts recorded about the books' files, by attachment id
|
||||
/// (`attachment.annotated`, plan P6 step 5).
|
||||
pub fn annotations(&self) -> impl Iterator<Item = &crate::evidence::Annotation> {
|
||||
self.annotations.values()
|
||||
}
|
||||
|
||||
/// The facts recorded about one file, if any.
|
||||
pub fn annotation(&self, attachment_id: u64) -> Option<&crate::evidence::Annotation> {
|
||||
self.annotations.get(&attachment_id)
|
||||
}
|
||||
|
||||
/// The next receipt number: one past the highest one annotated, or 1
|
||||
/// when none is (plan P6 step 5: engine numbers run from the max).
|
||||
pub fn next_receipt_number(&self) -> u32 {
|
||||
self.annotations
|
||||
.values()
|
||||
.filter_map(|a| a.fields.receipt_number)
|
||||
.max()
|
||||
.map_or(1, |n| n.saturating_add(1))
|
||||
}
|
||||
|
||||
/// Record what a human read off a file, replacing an earlier
|
||||
/// annotation of it (plan P6 step 5; INVARIANTS 1 and 2 of
|
||||
/// [`crate::evidence`]).
|
||||
pub fn annotate_attachment(
|
||||
&mut self,
|
||||
annotation: crate::evidence::Annotation,
|
||||
) -> Result<(), LedgerError> {
|
||||
let annotation = annotation.checked()?;
|
||||
self.annotations
|
||||
.insert(annotation.attachment_id, annotation);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`Self::annotate_attachment`] as journaled (`attachment.annotated`),
|
||||
/// for replay only (rules.md B-28).
|
||||
pub fn replay_annotate_attachment(
|
||||
&mut self,
|
||||
annotation: crate::evidence::Annotation,
|
||||
) -> Result<(), LedgerError> {
|
||||
self.annotate_attachment(annotation)
|
||||
}
|
||||
|
||||
/// The entries `entry` records settling (`entry.settles`, plan P6).
|
||||
pub fn entry_settles(&self, entry: EntryId) -> &[EntryId] {
|
||||
self.entry_settles.get(&entry).map_or(&[], Vec::as_slice)
|
||||
}
|
||||
|
||||
/// Whether any entry records settling `entry`: the one way a
|
||||
/// member-paid entry reads as reimbursed (IZ-18: no FIFO guess).
|
||||
pub fn settles_entry(&self, entry: EntryId) -> bool {
|
||||
self.entry_settles.values().any(|s| s.contains(&entry))
|
||||
}
|
||||
|
||||
/// Record which entries `entry` settles (a reimbursement naming what
|
||||
/// it pays back, plan P6 step 5). INVARIANT 3: every entry exists,
|
||||
/// none is `entry` itself, none is named twice.
|
||||
pub fn set_entry_settles(
|
||||
&mut self,
|
||||
entry: EntryId,
|
||||
settles: Vec<EntryId>,
|
||||
) -> Result<(), LedgerError> {
|
||||
if !self.entries.contains_key(&entry) {
|
||||
return Err(LedgerError::UnknownEntry(entry));
|
||||
}
|
||||
let mut seen = std::collections::BTreeSet::new();
|
||||
for s in &settles {
|
||||
if *s == entry {
|
||||
return Err(LedgerError::InvalidEvidence(
|
||||
"an entry doesn't settle itself".into(),
|
||||
));
|
||||
}
|
||||
if !self.entries.contains_key(s) {
|
||||
return Err(LedgerError::UnknownEntry(*s));
|
||||
}
|
||||
if !seen.insert(*s) {
|
||||
return Err(LedgerError::InvalidEvidence(format!(
|
||||
"entry {s} is settled twice by entry {entry}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
self.entry_settles.insert(entry, settles);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`Self::set_entry_settles`] as journaled (`entry.settles`), for
|
||||
/// replay only (rules.md B-28).
|
||||
pub fn replay_set_entry_settles(
|
||||
&mut self,
|
||||
entry: EntryId,
|
||||
settles: Vec<EntryId>,
|
||||
) -> Result<(), LedgerError> {
|
||||
self.set_entry_settles(entry, settles)
|
||||
}
|
||||
|
||||
/// Check a convention before it is journaled: its id, text and
|
||||
/// structure (crate::conventions::check_new), and that every account a
|
||||
/// posting template or approval rule names is in the chart (a
|
||||
|
||||
Reference in new issue
Block a user