refactor: rule references cite bookspec ids
Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5. Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
7a177a3cfc
commit
489360f598
221 files changed
+1706
-1580
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! The audit's journal and the integrity checks (plan P8; rules.md B-45):
|
||||
//! The audit's journal and the integrity checks (plan P8; BS-ledger-13):
|
||||
//! `audit.run`, `receipt.attested`, `entry.reviewed` and `period.attested`,
|
||||
//! what "the current head" means, and the findings only the store can see.
|
||||
//!
|
||||
@@ -7,7 +7,7 @@
|
||||
//! head, so the same books give the same run once, and an
|
||||
//! attestation rests on a head that has not moved.
|
||||
//! SOURCE: IRS Pub. 583 (records); Rev. Proc. 98-25 §5.01 (the audit
|
||||
//! trail); docs/spec/rules.md B-45; DECISION D-9 (the bar), D-53
|
||||
//! trail); BS-ledger-13; DECISION D-9 (the bar), D-53
|
||||
//! (an audit is a run, not a job), IZ-1k (the head).
|
||||
//! INVARIANTS:
|
||||
//! 1. The figure head is the seq of the last journal line that bears on
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! what, and which entry it belongs to.
|
||||
//! SOURCE: plan/served.md P5 step 4 (the only way to "read the journal");
|
||||
//! docs/receipt-store.md (the lines and their payloads);
|
||||
//! docs/spec/rules.md B-26 (no output holds a full TIN).
|
||||
//! BS-partner-2 (no output holds a full TIN).
|
||||
//! INVARIANTS:
|
||||
//! 1. Every line type the store writes has a sentence (test: every
|
||||
//! `format::EVENT_TYPES` entry).
|
||||
|
||||
@@ -36,7 +36,7 @@ pub enum StoreError {
|
||||
AssetDepreciationPosted(u64),
|
||||
|
||||
/// The receipt policy covers the entry and it has no receipt (plan P4,
|
||||
/// I-5; rules.md B-43): refused before anything is journaled.
|
||||
/// I-5; BS-entry-5): refused before anything is journaled.
|
||||
#[error(
|
||||
"entry {} needs a receipt before it posts: {} ({}); attach one with books.attach_receipt",
|
||||
.0.entry_id, .0.reason, .0.policy
|
||||
@@ -69,7 +69,7 @@ pub enum StoreError {
|
||||
/// though the lines after it are the newer version's to check. When
|
||||
/// nothing checks it (it is the last line, or the next has no `prev`
|
||||
/// this version can read), it is either newer or damaged, and the
|
||||
/// message says so (rules.md B-27).
|
||||
/// message says so (BS-format-1).
|
||||
#[error("{}", newer_journal_text(*seq, event_type, need, *verified))]
|
||||
NewerJournal {
|
||||
/// The first line this version can't read.
|
||||
@@ -152,7 +152,7 @@ pub enum StoreError {
|
||||
#[error("store not found at {0}")]
|
||||
NotFound(String),
|
||||
|
||||
/// A write-off with no evidence (rules.md B-41 INVARIANT 1): a bad
|
||||
/// A write-off with no evidence (BS-arap-5 INVARIANT 1): a bad
|
||||
/// debt is deducted on evidence that it is worthless (Treas. Reg.
|
||||
/// §1.166-2), so the books take the write-off only with its file.
|
||||
#[error(
|
||||
@@ -162,8 +162,8 @@ pub enum StoreError {
|
||||
)]
|
||||
WriteOffNeedsEvidence,
|
||||
|
||||
/// An audit or an attestation the books refuse (plan P8; rules.md
|
||||
/// B-45): a stale head, an entry not posted, a receipt not on the
|
||||
/// An audit or an attestation the books refuse (plan P8;
|
||||
/// BS-ledger-13): a stale head, an entry not posted, a receipt not on the
|
||||
/// entry. The words say what to do.
|
||||
#[error("{0}")]
|
||||
AuditRefused(String),
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! GOAL: every event round-trips: decode(encode(x)) == x, and every line
|
||||
//! written before decisions were kept reads as it always meant.
|
||||
//! SOURCE: plan/served.md 5.2, 5.5 (a legacy null is undetermined);
|
||||
//! rules.md B-27 (an older reader says "newer", never "corrupt").
|
||||
//! BS-format-1 (an older reader says "newer", never "corrupt").
|
||||
//! INVARIANTS:
|
||||
//! 1. vendor.1099_set {vendor_id, form_1099: "nec"|"misc"|
|
||||
//! "not_reportable"|null, reason_kind?, reason?, effective?,
|
||||
@@ -22,7 +22,7 @@
|
||||
//! 4. instrument.added {instrument_id, kind, label, last4?,
|
||||
//! owner_party_id?, account_id}; entry.instrument_set {entry_id,
|
||||
//! instrument_id|null}. Optional keys are left out when absent.
|
||||
//! 5. Decoding checks shape only (rules.md B-28): what a command checks
|
||||
//! 5. Decoding checks shape only (BS-entry-4): what a command checks
|
||||
//! (limits, the chart) stays with the command.
|
||||
//! ```
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//! checks ([`crate::journal::read_journal_and_format`], and
|
||||
//! [`crate::Snapshot`] line by line).
|
||||
//!
|
||||
//! What every format shares is frozen (rules.md B-27): a line is the
|
||||
//! What every format shares is frozen (BS-format-1): a line is the
|
||||
//! envelope `{seq, ts, type, payload, prev}` and nothing beside it, and
|
||||
//! its hash is the SHA-256 of its canonical JSON (keys sorted, no
|
||||
//! whitespace). A newer format adds its fields inside `payload`. So this
|
||||
@@ -27,7 +27,7 @@
|
||||
//! The other way round, books an older version wrote are in an older
|
||||
//! format: this version reads them as they are, and writes nothing that
|
||||
//! needs a format or feature they haven't declared until the owner says
|
||||
//! go (the format upgrade, rules.md B-27, plan/served.md 3.9, D-39:
|
||||
//! go (the format upgrade, BS-format-1, plan/served.md 3.9, D-39:
|
||||
//! [`JournalFormat::upgrade`], [`current`]). New books declare this
|
||||
//! version's whole format as they are created.
|
||||
|
||||
@@ -43,7 +43,7 @@ pub const SUPPORTED_JOURNAL_FORMAT: u32 = 2;
|
||||
/// unknown), or a field or value on an event type it knows (which it
|
||||
/// would misread silently). The books declare it (`journal.format_set`)
|
||||
/// before their first such line, so the older version stops there instead
|
||||
/// (rules.md B-27). Every one is declared at once: by new books as they
|
||||
/// (BS-format-1). Every one is declared at once: by new books as they
|
||||
/// are created, and by older books at their format upgrade ([`current`]);
|
||||
/// until then a write that needs one is refused.
|
||||
pub const KNOWN_FEATURES: &[&str] = &[
|
||||
@@ -72,7 +72,7 @@ pub const KNOWN_FEATURES: &[&str] = &[
|
||||
/// Feature: `period.closed` closes to members with `"rounding":
|
||||
/// "cumulative_since"` and `since_seq`, the count of members closes
|
||||
/// starting at the first since the members or shares last changed (P3
|
||||
/// defect 17, rules.md B-13). An older version would call the rounding
|
||||
/// defect 17, BS-partner-1). An older version would call the rounding
|
||||
/// unknown, or (before the format gate) replay the close under the run
|
||||
/// rule, which can split it differently.
|
||||
pub const MEMBERS_CUMULATIVE: &str = "members_cumulative";
|
||||
@@ -136,14 +136,14 @@ pub const DISPOSAL_BEFORE_SERVICE: &str = "disposal_before_service";
|
||||
|
||||
/// Feature: an `asset.depreciation_posted` whose amount is not its month's
|
||||
/// own depreciation: earlier months skipped or reversed caught up in it, or
|
||||
/// a final month left over past the life (P3's run rule, B-15). An earlier
|
||||
/// a final month left over past the life (P3's run rule, BS-asset-1). An earlier
|
||||
/// version reads every run as its month's own: it would show the caught-up
|
||||
/// months as not yet run, and running them post their depreciation twice
|
||||
/// (P3 review, 2026-10-21).
|
||||
pub const DEPRECIATION_CATCH_UP: &str = "depreciation_catch_up";
|
||||
|
||||
/// The feature `party.creditor_set` lines need: a party named the
|
||||
/// creditor of a liability (rules.md B-35, P3 defect 24).
|
||||
/// creditor of a liability (BS-partner-3, P3 defect 24).
|
||||
pub const PARTY_CREDITORS: &str = "party_creditors";
|
||||
|
||||
/// Payment methods (`instrument.added`) and the entries tagged with one
|
||||
@@ -171,7 +171,7 @@ pub const SCHEDULE_CONVENTION: &str = "schedule_convention";
|
||||
/// with the value at contribution and the §704(c) method (P3, defect 13).
|
||||
pub const ASSET_BASIS: &str = "asset_basis";
|
||||
|
||||
/// Feature: projects (rules.md B-37): `project.set`, a new event type (a
|
||||
/// Feature: projects (BS-statement-5): `project.set`, a new event type (a
|
||||
/// class's project facts); `attachment.linked` to the subject kind
|
||||
/// `project` (an older version would call it corrupt); and
|
||||
/// `decision.recorded` with `projects` (an older version would drop them
|
||||
@@ -179,7 +179,7 @@ pub const ASSET_BASIS: &str = "asset_basis";
|
||||
pub const PROJECTS: &str = "projects";
|
||||
|
||||
/// Feature: an `invoice.created` or `bill.created` line naming its project
|
||||
/// (`class_id`, rules.md B-37 item 8). An older version would restore the
|
||||
/// (`class_id`, BS-statement-5 item 8). An older version would restore the
|
||||
/// document without its lines' projects, silently. Its own feature, not
|
||||
/// `projects`': books that consented to projects before it existed must
|
||||
/// consent again before a document names one.
|
||||
@@ -187,7 +187,7 @@ pub const DOCUMENT_LINE_PROJECTS: &str = "document_line_projects";
|
||||
|
||||
/// Feature: an `invoice.payment_received` or `bill.paid` accepted only
|
||||
/// because an earlier payment on its document was reversed (plan P4b S1,
|
||||
/// D-45; rules.md B-38): this version reads a document's figures from the
|
||||
/// D-45; BS-arap-2): this version reads a document's figures from the
|
||||
/// ledger lines that stand, so a reversed payment no longer counts and the
|
||||
/// right one is taken. An older version adds every payment event to the
|
||||
/// document's paid amount, standing or not: it would replay the new
|
||||
@@ -211,7 +211,7 @@ pub const DOCUMENTS_V2: &str = "documents_v2";
|
||||
/// payment pays back), and `attachment.withdrawn` carrying `duplicate_of`.
|
||||
/// An older version doesn't know those event types, or would withdraw a
|
||||
/// duplicate without saying what it duplicates; it stops at the
|
||||
/// declaration instead (rules.md B-27, B-44).
|
||||
/// declaration instead (BS-format-1, BS-ledger-12).
|
||||
pub const ATTACHMENT_TEXT: &str = "attachment_text";
|
||||
|
||||
/// Feature: `drafts_v2` (plan P4, D-52): `entry.draft_state_set` (a draft
|
||||
@@ -220,7 +220,7 @@ pub const ATTACHMENT_TEXT: &str = "attachment_text";
|
||||
/// event types: it would refuse them as unknown, or, replaying around
|
||||
/// them, keep a discarded draft that blocks a period's close and call a
|
||||
/// waiting draft one being built; it stops at the declaration instead
|
||||
/// (rules.md B-27, B-43).
|
||||
/// (BS-format-1, BS-entry-5).
|
||||
pub const DRAFTS_V2: &str = "drafts_v2";
|
||||
|
||||
/// Feature: `source_revisions` (plan P5): `convention.source_revised`,
|
||||
@@ -229,7 +229,7 @@ pub const DRAFTS_V2: &str = "drafts_v2";
|
||||
/// leaving its text as it was. An older version doesn't know those event
|
||||
/// types: it would refuse them as unknown, or, replaying around them,
|
||||
/// show the old source as the decision's authority; it stops at the
|
||||
/// declaration instead (rules.md B-27).
|
||||
/// declaration instead (BS-format-1).
|
||||
pub const SOURCE_REVISIONS: &str = "source_revisions";
|
||||
|
||||
/// Feature: `audits` (plan P8): `audit.run` (a programme of checks run
|
||||
@@ -240,7 +240,7 @@ pub const SOURCE_REVISIONS: &str = "source_revisions";
|
||||
/// waits for an audit (`policy.cpa_package_requires_audit`). An older
|
||||
/// version doesn't know those event types or settings; it stops at the
|
||||
/// declaration instead of dropping the claims a handoff rests on
|
||||
/// (rules.md B-27, B-45).
|
||||
/// (BS-format-1, BS-ledger-13).
|
||||
pub const AUDITS: &str = "audits";
|
||||
|
||||
/// The line type that declares the journal format.
|
||||
@@ -364,7 +364,7 @@ impl JournalFormat {
|
||||
/// ```text
|
||||
/// GOAL: an older wanderbooks never misreads newer books, and never
|
||||
/// calls them corrupt.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate).
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
|
||||
/// INVARIANTS:
|
||||
/// 1. Only lines that parsed, chained and kept their seq reach the
|
||||
/// gate: damage stays JournalCorrupt.
|
||||
@@ -496,8 +496,8 @@ impl JournalFormat {
|
||||
}
|
||||
}
|
||||
|
||||
/// The format upgrade books in this format wait for, if any (rules.md
|
||||
/// B-27, plan/served.md 3.9, D-39).
|
||||
/// The format upgrade books in this format wait for, if any (
|
||||
/// BS-format-1, plan/served.md 3.9, D-39).
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books an older version wrote are never moved to a newer
|
||||
@@ -587,7 +587,7 @@ fn declared_knowing(line: &JournalLine, known: &[&str]) -> Result<JournalFormat,
|
||||
/// The refusal for a line of a type this version knows that holds a
|
||||
/// value only a newer version writes: a setting key, a convention kind
|
||||
/// (`need` says which). Never "corrupt": the books are fine, this reader
|
||||
/// is old (rules.md B-27).
|
||||
/// is old (BS-format-1).
|
||||
pub(crate) fn newer_content(line: &JournalLine, need: String) -> StoreError {
|
||||
newer(line, need)
|
||||
}
|
||||
@@ -598,7 +598,7 @@ pub(crate) fn unknown_type(line: &JournalLine) -> StoreError {
|
||||
}
|
||||
|
||||
/// The gate for one line as read: a line with a key beside the envelope's
|
||||
/// is newer (rules.md B-27: this version never drops a key it can't
|
||||
/// is newer (BS-format-1: this version never drops a key it can't
|
||||
/// read), and any other goes to `admit` (JournalFormat::admit).
|
||||
pub(crate) fn gate(
|
||||
read: &ReadLine,
|
||||
@@ -634,7 +634,7 @@ fn newer(line: &JournalLine, need: String) -> StoreError {
|
||||
/// ```text
|
||||
/// GOAL: damage is never reported as books from a newer wanderbooks, and
|
||||
/// books from a newer wanderbooks never as damage.
|
||||
/// SOURCE: rules.md B-27 (the envelope and its hash are frozen across
|
||||
/// SOURCE: BS-format-1 (the envelope and its hash are frozen across
|
||||
/// formats); docs/receipt-store.md "Line format" (a line's hash is
|
||||
/// checked only by the next line's prev).
|
||||
/// INVARIANTS:
|
||||
@@ -848,7 +848,7 @@ mod tests {
|
||||
/// The version the live books run (every feature through `projects`)
|
||||
/// stops at a declaration of `document_line_projects` as newer, never
|
||||
/// restoring an invoice or bill without its lines' projects; and books
|
||||
/// that declared `projects` alone still wait for it (B-27, D-39).
|
||||
/// that declared `projects` alone still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn document_line_projects_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENT_LINE_PROJECTS));
|
||||
@@ -887,7 +887,7 @@ mod tests {
|
||||
/// `document_line_projects`) stops at a declaration of
|
||||
/// `document_standing` as newer, never adding a payment taken after a
|
||||
/// reversal on top of the reversed one; and books that declared every
|
||||
/// earlier feature still wait for it (B-27, D-39).
|
||||
/// earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn document_standing_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENT_STANDING));
|
||||
@@ -921,7 +921,7 @@ mod tests {
|
||||
/// The version before P6 (every feature through `documents_v2`) stops
|
||||
/// at a declaration of `attachment_text` as newer, never dropping a
|
||||
/// file's extraction, annotations or settlements; and books that
|
||||
/// declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn attachment_text_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&ATTACHMENT_TEXT));
|
||||
@@ -956,7 +956,7 @@ mod tests {
|
||||
/// `document_standing`) stops at a declaration of `documents_v2` as
|
||||
/// newer, never restoring a party's email or default terms as absent
|
||||
/// (or a document without its numbers, once S4.3 writes them); books
|
||||
/// that declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// that declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn documents_v2_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DOCUMENTS_V2));
|
||||
@@ -991,7 +991,7 @@ mod tests {
|
||||
/// stops at a declaration of `drafts_v2` as newer, never keeping a
|
||||
/// discarded draft or calling a waiting one a draft being built; and
|
||||
/// books that declared every earlier feature still wait for it
|
||||
/// (B-27, D-39).
|
||||
/// (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn drafts_v2_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&DRAFTS_V2));
|
||||
@@ -1024,7 +1024,7 @@ mod tests {
|
||||
|
||||
/// The version before P5 (every feature through `drafts_v2`) stops at a
|
||||
/// declaration of `source_revisions` as newer, and books that declared
|
||||
/// every earlier feature still wait for it (B-27, D-39).
|
||||
/// every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn source_revisions_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&SOURCE_REVISIONS));
|
||||
@@ -1057,7 +1057,7 @@ mod tests {
|
||||
|
||||
/// The version before P8 stops at a declaration of `audits` as newer,
|
||||
/// never dropping an attestation a handoff rests on; books that
|
||||
/// declared every earlier feature still wait for it (B-27, D-39).
|
||||
/// declared every earlier feature still wait for it (BS-format-1, D-39).
|
||||
#[test]
|
||||
fn audits_is_its_own_feature() {
|
||||
assert!(KNOWN_FEATURES.contains(&AUDITS));
|
||||
@@ -1221,7 +1221,7 @@ mod tests {
|
||||
/// A format newer than this version reads is newer whatever shape the
|
||||
/// rest of its declaration takes, and however large its number: a
|
||||
/// newer format may define its features differently, so they are
|
||||
/// judged only for a format this version reads (rules.md B-27).
|
||||
/// judged only for a format this version reads (BS-format-1).
|
||||
#[test]
|
||||
fn a_newer_format_is_newer_whatever_its_features_look_like() {
|
||||
let mut f = JournalFormat::default();
|
||||
|
||||
@@ -71,7 +71,7 @@ fn sort_value(v: &Value) -> Value {
|
||||
}
|
||||
|
||||
/// The keys of a journal line, the same in every journal format
|
||||
/// (rules.md B-27): a newer format adds its fields inside `payload`, never
|
||||
/// (BS-format-1): a newer format adds its fields inside `payload`, never
|
||||
/// beside it, and a line's hash is always the SHA-256 of its canonical
|
||||
/// JSON ([`canonical_json`]), whatever the format.
|
||||
pub const ENVELOPE_KEYS: [&str; 5] = ["payload", "prev", "seq", "ts", "type"];
|
||||
@@ -84,7 +84,7 @@ impl JournalLine {
|
||||
/// hash chain covers) is a fixed point.
|
||||
/// SOURCE: R-2 (no floats in money paths); found by fuzz_journal_line
|
||||
/// (2026-10-13): a float payload re-canonicalized differently;
|
||||
/// rules.md B-27 (the envelope is frozen).
|
||||
/// BS-format-1 (the envelope is frozen).
|
||||
/// INVARIANTS:
|
||||
/// 1. NEVER accepts a floating-point number anywhere in the line:
|
||||
/// amounts are decimal strings and ids are integers.
|
||||
@@ -267,7 +267,7 @@ pub fn read_and_verify_journal(path: &Path) -> Result<Vec<JournalLine>, StoreErr
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books read whole and verified, or refused with the reason.
|
||||
/// SOURCE: docs/receipt-store.md "Line format"; rules.md B-27.
|
||||
/// SOURCE: docs/receipt-store.md "Line format"; BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. Line by line, in order: parse, seq, chain, then the format gate.
|
||||
/// 2. Damage before the first line this version can't read is
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! INVARIANTS:
|
||||
//! 1. A payload missing a field, or with a field of the wrong type, is
|
||||
//! JournalCorrupt; optional fields may be absent or null.
|
||||
//! 2. Decoding checks shape only (rules.md B-28): what a command checks
|
||||
//! 2. Decoding checks shape only (BS-entry-4): what a command checks
|
||||
//! (limits, the chart) stays with the command.
|
||||
//! ```
|
||||
|
||||
@@ -301,7 +301,7 @@ pub fn decision_recorded_of(p: &Value) -> Result<(u64, NewDecision), StoreError>
|
||||
|
||||
/// `project.set {id, name, status, kind?, description?, party_id?,
|
||||
/// started_on?, ended_on?, links?, notes?}`: a class's whole project
|
||||
/// record (rules.md B-37; journal feature `projects`). Every optional key
|
||||
/// record (BS-statement-5; journal feature `projects`). Every optional key
|
||||
/// is left out when empty, so the payload is canonical.
|
||||
pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value {
|
||||
let mut o = Map::new();
|
||||
@@ -322,7 +322,7 @@ pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value {
|
||||
|
||||
/// Read a `project.set`: `(id, name, facts)`. A missing or mistyped key is
|
||||
/// corrupt; a status or kind this version doesn't know is newer (a newer
|
||||
/// version wrote it, rules.md B-27).
|
||||
/// version wrote it, BS-format-1).
|
||||
pub fn project_set_of(
|
||||
line: &crate::journal::JournalLine,
|
||||
) -> Result<(ClassId, String, ProjectFacts), StoreError> {
|
||||
@@ -463,7 +463,7 @@ pub fn invoice_sent(invoice: u64, s: &Sent) -> Value {
|
||||
}
|
||||
|
||||
/// Read an `invoice.sent`: `(invoice, send)`. A channel or kind this
|
||||
/// version doesn't know is newer, never corrupt (rules.md B-27).
|
||||
/// version doesn't know is newer, never corrupt (BS-format-1).
|
||||
pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> {
|
||||
const E: &str = "invoice.sent";
|
||||
let p = &line.payload;
|
||||
@@ -487,7 +487,7 @@ pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> {
|
||||
))
|
||||
}
|
||||
|
||||
/// A bad-debt write-off as journaled (plan P4b S7; rules.md B-41):
|
||||
/// A bad-debt write-off as journaled (plan P4b S7; BS-arap-5):
|
||||
/// `invoice.written_off {invoice_id, entry_id, date, amount, reason}`.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct WrittenOff {
|
||||
@@ -557,7 +557,7 @@ pub fn text_extracted(
|
||||
|
||||
/// Read an `attachment.text_extracted`: `(attachment_id, text_sha256,
|
||||
/// extractor, version, pages, status)`. A status this version doesn't know
|
||||
/// is newer (B-27: never "corrupt" for newer).
|
||||
/// is newer (BS-format-1: never "corrupt" for newer).
|
||||
pub fn text_extracted_of(line: &crate::journal::JournalLine) -> Result<TextExtracted, StoreError> {
|
||||
const E: &str = "attachment.text_extracted";
|
||||
let p = &line.payload;
|
||||
@@ -624,7 +624,7 @@ pub fn annotated(a: &Annotation) -> Value {
|
||||
|
||||
/// Read an `attachment.annotated`. A field this version doesn't know, or a
|
||||
/// mistyped one, is judged by its kind: unknown is newer (a later version
|
||||
/// wrote it, B-27), mistyped is corrupt.
|
||||
/// wrote it, BS-format-1), mistyped is corrupt.
|
||||
pub fn annotated_of(line: &crate::journal::JournalLine) -> Result<Annotation, StoreError> {
|
||||
const E: &str = "attachment.annotated";
|
||||
let p = &line.payload;
|
||||
@@ -704,7 +704,7 @@ pub fn draft_state_set(id: u64, state: &DraftState) -> Value {
|
||||
}
|
||||
|
||||
/// Read an `entry.draft_state_set`: `(draft, state)`. A state this
|
||||
/// version doesn't know is newer, never corrupt (rules.md B-27).
|
||||
/// version doesn't know is newer, never corrupt (BS-format-1).
|
||||
pub fn draft_state_set_of(line: &JournalLine) -> Result<(u64, DraftState), StoreError> {
|
||||
const E: &str = "entry.draft_state_set";
|
||||
let p = &line.payload;
|
||||
@@ -748,7 +748,7 @@ pub fn method_json(m: &ledger_core::audit::Method) -> Value {
|
||||
}
|
||||
|
||||
/// Read a method. A key or an effort this version doesn't know is newer
|
||||
/// when a line is at hand (B-27), else corrupt.
|
||||
/// when a line is at hand (BS-format-1), else corrupt.
|
||||
fn method_of(
|
||||
line: Option<&crate::journal::JournalLine>,
|
||||
m: &Value,
|
||||
|
||||
@@ -78,7 +78,7 @@ pub enum ViewerTarget {
|
||||
/// Account code.
|
||||
code: String,
|
||||
/// First date, YYYY-MM-DD. `books.show` always sends both dates,
|
||||
/// resolved (rules.md B-30); `None` only from an earlier writer,
|
||||
/// resolved (BS-period-3); `None` only from an earlier writer,
|
||||
/// which the viewer resolves by the same rule.
|
||||
start: Option<String>,
|
||||
/// Last date, YYYY-MM-DD (see `start`).
|
||||
@@ -91,7 +91,7 @@ pub enum ViewerTarget {
|
||||
/// ar_aging, ap_aging, fixed_asset_register.
|
||||
report: String,
|
||||
/// First date, YYYY-MM-DD. `books.show` always sends both dates,
|
||||
/// resolved (rules.md B-30); `None` only from an earlier writer,
|
||||
/// resolved (BS-period-3); `None` only from an earlier writer,
|
||||
/// which the viewer resolves by the same rule.
|
||||
start: Option<String>,
|
||||
/// Last date, YYYY-MM-DD (see `start`): the as-of day of a report
|
||||
|
||||
@@ -388,7 +388,7 @@ ALTER TABLE asset_depreciation_v13 RENAME TO asset_depreciation;
|
||||
"#,
|
||||
r#"
|
||||
-- v15: a document keeps no figure of its own (plan P4b S1, D-45; rules.md
|
||||
-- B-38): what an invoice or bill has been paid, and its status, are read
|
||||
-- BS-arap-2): what an invoice or bill has been paid, and its status, are read
|
||||
-- from the ledger lines tagged with it, as of any date, and a reversed
|
||||
-- payment no longer counts. The columns that summed its payment events
|
||||
-- (and so went on counting a reversed one) go.
|
||||
|
||||
@@ -72,7 +72,7 @@ pub const LEGACY_DB_FILE: &str = "wanderbooks.db";
|
||||
/// open (plan/served.md 3.9: before consent, the way back is always
|
||||
/// there), however far this version's projection has moved.
|
||||
/// SOURCE: plan/served.md 3.9, the lead's decision (2026-10-21: each
|
||||
/// schema in a file of its own); rules.md B-27.
|
||||
/// schema in a file of its own); BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. A version opens or creates only its own schema's file (or the
|
||||
/// legacy file when that already holds its schema); a missing one is
|
||||
@@ -506,7 +506,7 @@ struct AttachRequest<'a> {
|
||||
description: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// The evidence a bad-debt write-off files (plan P4b S7; rules.md B-41
|
||||
/// The evidence a bad-debt write-off files (plan P4b S7; BS-arap-5
|
||||
/// INVARIANT 1): the file that shows the debt is worthless — collection
|
||||
/// correspondence, a bankruptcy notice (Treas. Reg. §1.166-2). Given as
|
||||
/// bytes to file in the same call, or as an attachment already in the
|
||||
@@ -909,7 +909,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: books that tell every reader which format they are in.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate).
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the format is newer than SUPPORTED_JOURNAL_FORMAT, or 0:
|
||||
/// SHOULD refuse (FormatRefused), journaling nothing
|
||||
@@ -969,7 +969,7 @@ impl Store {
|
||||
/// instead of misreading a line it thinks it knows, and books
|
||||
/// move past what their owner's older version reads only when
|
||||
/// the owner says so.
|
||||
/// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate), 3.9 and
|
||||
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate), 3.9 and
|
||||
/// D-39 (the format upgrade).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the books declared it: SHOULD pass.
|
||||
@@ -1001,7 +1001,7 @@ impl Store {
|
||||
/// GOAL: older books move to this version's format at once, on the
|
||||
/// record, exactly once.
|
||||
/// SOURCE: plan/served.md 3.9 ("Format changes are the server's
|
||||
/// gate"); D-39; rules.md B-27.
|
||||
/// gate"); D-39; BS-format-1.
|
||||
/// INVARIANTS:
|
||||
/// 1. One journal line declares the whole format: the format moves
|
||||
/// exactly once, never feature by feature.
|
||||
@@ -1072,7 +1072,7 @@ impl Store {
|
||||
self.ensure_features(&needed)?;
|
||||
self.ensure_format()?;
|
||||
// invoicing.first_number is settable only while no numbered invoice
|
||||
// exists (A-2, rules.md B-40): the series has begun, and a number is
|
||||
// exists (A-2, BS-arap-4): the series has begun, and a number is
|
||||
// never reused or renumbered. Changing or clearing it is refused
|
||||
// before anything is journaled.
|
||||
if changes.iter().any(|c| c.key == "invoicing.first_number")
|
||||
@@ -1356,7 +1356,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: an account created with the line of the return it maps to.
|
||||
/// SOURCE: rules.md B-32 (policy.require_tax_category).
|
||||
/// SOURCE: BS-ledger-11 (policy.require_tax_category).
|
||||
/// INVARIANTS:
|
||||
/// 1. Rehearsed whole first: a refusal (of the account, or of its
|
||||
/// category) journals nothing.
|
||||
@@ -1512,7 +1512,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a draft that is finished and waiting on its receipt says so,
|
||||
/// durably, and replays the same.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-43; plan P4.
|
||||
/// SOURCE: BS-format-1, BS-entry-5; plan P4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (unknown or posted entry, a note the
|
||||
/// books won't keep): SHOULD refuse, journaling nothing.
|
||||
@@ -1543,7 +1543,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a draft that will never post can go, so it stops holding its
|
||||
/// period open, and the journal still says why.
|
||||
/// SOURCE: docs/spec/rules.md B-8, B-43; plan P4.
|
||||
/// SOURCE: BS-ledger-4, BS-entry-5; plan P4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the entry is unknown or posted, or the reason is empty or
|
||||
/// breaks the books' text rule: SHOULD refuse, journaling
|
||||
@@ -1584,7 +1584,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// [`Self::post_entry`] behind the evidence gate (plan P4, I-5, D-47;
|
||||
/// rules.md B-43): refuses, journaling nothing, a draft that
|
||||
/// BS-entry-5): refuses, journaling nothing, a draft that
|
||||
/// [`ledger_core::evidence::requirement`] says needs evidence while it
|
||||
/// has no receipt filed on it or linked to it. This is the path the
|
||||
/// server posts a hand-made draft by; [`Self::post_entry`] stays the
|
||||
@@ -1594,7 +1594,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: no draft the receipt policy covers posts without the
|
||||
/// document that supports it, decided in one place.
|
||||
/// SOURCE: docs/spec/rules.md B-43; IRS Pub. 583.
|
||||
/// SOURCE: BS-entry-5; IRS Pub. 583.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the entry is covered and has no receipt: SHOULD refuse
|
||||
/// (ReceiptRequired), NEVER journal.
|
||||
@@ -1748,7 +1748,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a reversal never leaves a fixed asset's figures and its books
|
||||
/// apart.
|
||||
/// SOURCE: docs/spec/rules.md B-9, B-15; P3 depreciation review R3.
|
||||
/// SOURCE: BS-ledger-5, BS-asset-1; P3 depreciation review R3.
|
||||
/// SCENARIOS (the entry, or the original its reversal chain starts
|
||||
/// from, since reversing a reversal re-instates that original):
|
||||
/// 1. IF it is an asset's disposal entry:
|
||||
@@ -1774,7 +1774,7 @@ impl Store {
|
||||
/// reverses is refused for every entry, by `Ledger::check_reversal`
|
||||
/// with `ReversalBeforeOriginal`, D-73; it was this store's check
|
||||
/// for runs and schedule months alone. A journal an earlier
|
||||
/// version wrote replays as it was, B-28.)
|
||||
/// version wrote replays as it was, BS-entry-4.)
|
||||
/// 6. Otherwise: a run of an active asset is un-posted (its month is
|
||||
/// due again, caught up by the next run).
|
||||
/// ```
|
||||
@@ -2142,10 +2142,10 @@ impl Store {
|
||||
/// depreciable_basis, built_in_gain_704c}`: the facts, and for the
|
||||
/// line's readers the figures as derived when written (null for a
|
||||
/// purchase's depreciable basis: the cost, whatever it becomes).
|
||||
/// Replay reads the facts and never recomputes the figures (rules.md
|
||||
/// B-28). It needs the journal feature `asset_basis`: refused,
|
||||
/// Replay reads the facts and never recomputes the figures (
|
||||
/// BS-entry-4). It needs the journal feature `asset_basis`: refused,
|
||||
/// journaling nothing, in books that haven't declared it (books an
|
||||
/// older version wrote, until their format upgrade: B-27).
|
||||
/// older version wrote, until their format upgrade: BS-format-1).
|
||||
pub fn set_asset_basis(
|
||||
&mut self,
|
||||
id: AssetId,
|
||||
@@ -2287,7 +2287,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: the books carry the schedule through the month's end.
|
||||
/// SOURCE: docs/spec/rules.md B-15; plan/served.md P3 "Settled in
|
||||
/// SOURCE: BS-asset-1; plan/served.md P3 "Settled in
|
||||
/// design" (2026-10-20): a month skipped is caught up in the
|
||||
/// month the run is made (an immaterial miss; a material one is
|
||||
/// restated, ASC 250, by a human and the CPA).
|
||||
@@ -2485,8 +2485,8 @@ impl Store {
|
||||
/// after its month, a run reversed and re-instated after the
|
||||
/// disposal's month) is that run's own error and correction, dated
|
||||
/// when they were made, the same with or without the disposal.
|
||||
/// SOURCE: docs/spec/rules.md B-15 (a disposed asset depreciates through
|
||||
/// its disposal day); B-9 (a mistake is corrected by an opposite
|
||||
/// SOURCE: BS-asset-1 (a disposed asset depreciates through
|
||||
/// its disposal day); BS-ledger-5 (a mistake is corrected by an opposite
|
||||
/// entry); plan/served.md P3, settled in design (a miss is
|
||||
/// corrected in the period the correction is made, a material
|
||||
/// one restated); Ledger::dispose_asset INVARIANT 1. P3 review
|
||||
@@ -2589,7 +2589,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a disposal takes exactly the depreciation of the days held,
|
||||
/// whatever the runs posted.
|
||||
/// SOURCE: docs/spec/rules.md B-15 (the disposal day is held);
|
||||
/// SOURCE: BS-asset-1 (the disposal day is held);
|
||||
/// Ledger::dispose_asset INVARIANTS 1, 2; P3 depreciation
|
||||
/// review R2.
|
||||
/// INVARIANTS:
|
||||
@@ -2986,7 +2986,7 @@ impl Store {
|
||||
self.rehearse(|l| l.close_period_to(id, to))?;
|
||||
if matches!(to, CloseTo::Members(_) | CloseTo::MembersCumulative { .. }) {
|
||||
// A close counted from its regime's start: an older version
|
||||
// would replay it under the run rule (format gate, B-27).
|
||||
// would replay it under the run rule (format gate, BS-format-1).
|
||||
// Refused before anything is journaled until the books
|
||||
// declare it.
|
||||
self.ensure_feature(crate::format::MEMBERS_CUMULATIVE)?;
|
||||
@@ -3145,7 +3145,7 @@ impl Store {
|
||||
/// then no-ops, which keeps replay deterministic: every account
|
||||
/// creation is an `account.added` event. The engine's account
|
||||
/// (`Ledger::add_control_account`): never refused for its name or a
|
||||
/// missing tax category (rules.md B-32), so an invoice, a bill or a
|
||||
/// missing tax category (BS-ledger-11), so an invoice, a bill or a
|
||||
/// payroll run is never refused over a chart label.
|
||||
fn ensure_control_account(
|
||||
&mut self,
|
||||
@@ -3234,7 +3234,7 @@ impl Store {
|
||||
Ok((entry_id, journaled))
|
||||
}
|
||||
|
||||
/// The feature a document's lines need (rules.md B-27): a line naming
|
||||
/// The feature a document's lines need (BS-format-1): a line naming
|
||||
/// a project is `document_line_projects`'s; a document naming none is
|
||||
/// written as every version before it wrote one.
|
||||
fn ensure_document_lines(&self, lines: &[DocumentLine]) -> Result<(), StoreError> {
|
||||
@@ -3244,7 +3244,7 @@ impl Store {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The feature a document's new fields need (rules.md B-27): an
|
||||
/// The feature a document's new fields need (BS-format-1): an
|
||||
/// invoice or bill naming a number, terms, a snapshot, a reference, a
|
||||
/// memo or a duplicate's reason, or a line naming its account, quantity
|
||||
/// or unit price, needs `documents_v2` (plan P4b S4.3; D-52). A
|
||||
@@ -3319,7 +3319,7 @@ impl Store {
|
||||
/// GOAL: a document's new fields are journaled with it, so replay can
|
||||
/// never lose them, and a document naming none is written byte
|
||||
/// for byte as an earlier version wrote it.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-40 (plan P4b S4.3); A-2, A-13.
|
||||
/// SOURCE: BS-format-1, BS-arap-4 (plan P4b S4.3); A-2, A-13.
|
||||
/// INVARIANTS:
|
||||
/// 1. A write naming a number, terms, a snapshot, a reference, a memo,
|
||||
/// a line account, quantity or unit price MUST need journal feature
|
||||
@@ -3446,7 +3446,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// The issued copy of an invoice, filed in the call that issues it
|
||||
/// (plan P4b S4.3 item 11, A-7; rules.md B-40 item 3): the entry, then
|
||||
/// (plan P4b S4.3 item 11, A-7; BS-arap-4 item 3): the entry, then
|
||||
/// `invoice.created`, then `receipt.attached` on the entry
|
||||
/// (`INV-0007.pdf`, `application/pdf`, "Issued invoice"), then
|
||||
/// `attachment.linked` to the invoice. The server renders the PDF
|
||||
@@ -3462,7 +3462,7 @@ impl Store {
|
||||
/// GOAL: the copy sent is kept with the invoice, or nothing is.
|
||||
/// SOURCE: IRS Pub. 583 (keep invoices); Rev. Proc. 98-25 (the audit
|
||||
/// trail keeps the record as issued); plan P4b S4.3, 8.3.11;
|
||||
/// rules.md B-40 item 3.
|
||||
/// BS-arap-4 item 3.
|
||||
/// INVARIANTS:
|
||||
/// 1. Every refusal (an unknown customer, an invalid line or due
|
||||
/// date, a duplicate number, a closed period, a feature the books
|
||||
@@ -3811,7 +3811,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a payment is journaled once and replays to the same figures,
|
||||
/// in any version that can open the books.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-38; plan/served.md P4b.7
|
||||
/// SOURCE: BS-format-1, BS-arap-2; plan/served.md P4b.7
|
||||
/// (document_standing).
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (overpaid, before the invoice, a
|
||||
@@ -3908,7 +3908,7 @@ impl Store {
|
||||
}
|
||||
|
||||
/// Settle one or more invoices or bills in one entry (plan P4b S6;
|
||||
/// rules.md B-42): the core posts it ([`ledger_core::Ledger::settle`]);
|
||||
/// BS-arap-6): the core posts it ([`ledger_core::Ledger::settle`]);
|
||||
/// this journals its lines once and one `invoice.payment_received` or
|
||||
/// `bill.paid` per application, each naming the control line it tags,
|
||||
/// then the payment method. A single legacy-shaped payment is
|
||||
@@ -4026,7 +4026,7 @@ impl Store {
|
||||
Ok(live)
|
||||
}
|
||||
|
||||
/// Write off an invoice as a bad debt (plan P4b S7; rules.md B-41),
|
||||
/// Write off an invoice as a bad debt (plan P4b S7; BS-arap-5),
|
||||
/// filing its evidence in the same call. The write-off's entry (Dr
|
||||
/// 6990 Bad Debt Expense / Cr A/R) is journaled through the standard
|
||||
/// entry flow, then `invoice.written_off`, then the evidence: a
|
||||
@@ -4038,7 +4038,7 @@ impl Store {
|
||||
/// GOAL: a bad debt comes off the receivables with the proof it was
|
||||
/// worthless, in one call that is all or nothing.
|
||||
/// SOURCE: IRC §166(a); Treas. Reg. §1.166-1(e), -2(a), -3(a);
|
||||
/// docs/spec/rules.md B-41; plan P4b S7, 8.3.6.
|
||||
/// BS-arap-5; plan P4b S7, 8.3.6.
|
||||
/// INVARIANTS:
|
||||
/// 1. A write that needs journal feature documents_v2 (the event
|
||||
/// type) MUST be refused in books that haven't declared it,
|
||||
@@ -4144,7 +4144,7 @@ impl Store {
|
||||
}
|
||||
Ok((entry_id, attachment_id))
|
||||
}
|
||||
/// The journal features a settlement needs (rules.md B-27, B-42):
|
||||
/// The journal features a settlement needs (BS-format-1, BS-arap-6):
|
||||
/// `documents_v2` for more than one application, a discount or a fee
|
||||
/// (an older version would drop them, and the balance would be wrong),
|
||||
/// `document_standing` when an application pays more than an older
|
||||
@@ -4207,7 +4207,7 @@ impl Store {
|
||||
/// ```text
|
||||
/// GOAL: a send is journaled once and replays to the same record, in
|
||||
/// every version that can read the books.
|
||||
/// SOURCE: docs/spec/rules.md B-27, B-38; plan P4b S5, A-4.
|
||||
/// SOURCE: BS-format-1, BS-arap-2; plan P4b S5, A-4.
|
||||
/// SCENARIOS:
|
||||
/// 1. IF the engine refuses it (unknown or void invoice, a date
|
||||
/// before the invoice, no recipients, a text the books won't
|
||||
@@ -4528,13 +4528,13 @@ impl Store {
|
||||
Ok(live)
|
||||
}
|
||||
|
||||
/// Add a project (rules.md B-37): `class.added`, then `project.set`
|
||||
/// Add a project (BS-statement-5): `class.added`, then `project.set`
|
||||
/// when `facts` say more than the defaults. Returns its id.
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: a project in one command, journaled as two events only when
|
||||
/// it has facts, so a name-only project is a plain class.
|
||||
/// SOURCE: docs/spec/rules.md B-37 item 1; B-27 (journal feature
|
||||
/// SOURCE: BS-statement-5 item 1; BS-format-1 (journal feature
|
||||
/// `projects`).
|
||||
/// INVARIANTS:
|
||||
/// 1. A refusal journals nothing: the whole record is rehearsed, and
|
||||
@@ -5186,7 +5186,7 @@ impl Store {
|
||||
///
|
||||
/// ```text
|
||||
/// GOAL: rename an account, keeping the name it had in the journal.
|
||||
/// SOURCE: rules.md B-31; Rev. Proc. 98-25 (docs/spec/sources/
|
||||
/// SOURCE: BS-ledger-10; Rev. Proc. 98-25 (docs/spec/sources/
|
||||
/// irs-records.md): a report printed under the old name can
|
||||
/// be tied to the new one.
|
||||
/// INVARIANTS:
|
||||
@@ -5251,7 +5251,7 @@ impl Store {
|
||||
/// Set (or clear) an account's tax category and deductible percent.
|
||||
/// Journaled as `account.tax_set`. Under
|
||||
/// `policy.require_tax_category = refuse`, an account that needs a
|
||||
/// category is never left without one (rules.md B-32;
|
||||
/// category is never left without one (BS-ledger-11;
|
||||
/// `Ledger::check_tax_category_kept`).
|
||||
pub fn set_account_tax(
|
||||
&mut self,
|
||||
@@ -5646,7 +5646,7 @@ impl Store {
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/// The journal feature a link to `subject` needs, if any: a subject
|
||||
/// kind an older version doesn't know (a project, rules.md B-37).
|
||||
/// kind an older version doesn't know (a project, BS-statement-5).
|
||||
/// Callers filing a file with links ask it before filing, so a refusal
|
||||
/// leaves nothing half-filed.
|
||||
pub fn subject_feature(subject: Subject) -> Option<&'static str> {
|
||||
@@ -6847,8 +6847,8 @@ fn document_line_json(l: &DocumentLine) -> Value {
|
||||
"description": l.description,
|
||||
"amount": l.amount.to_string(),
|
||||
});
|
||||
// Its project, behind the feature document_line_projects (rules.md
|
||||
// B-27, B-37 item 8); a line naming none is written as before it.
|
||||
// Its project, behind the feature document_line_projects (
|
||||
// BS-format-1, BS-statement-5 item 8); a line naming none is written as before it.
|
||||
if let Some(c) = l.class_id {
|
||||
v["class_id"] = json!(c);
|
||||
}
|
||||
@@ -6927,7 +6927,7 @@ fn invoice_fields_json(payload: &mut Value, fields: &arap::InvoiceFields) {
|
||||
}
|
||||
|
||||
/// Add a bill's new fields to its `bill.created` payload, each key only when
|
||||
/// set. A duplicate's reason is journaled for the record (rules.md B-40 item
|
||||
/// set. A duplicate's reason is journaled for the record (BS-arap-4 item
|
||||
/// 4); the bill itself keeps none.
|
||||
fn bill_fields_json(payload: &mut Value, fields: &arap::BillFields) {
|
||||
if let Some(r) = &fields.vendor_ref {
|
||||
@@ -7151,7 +7151,7 @@ fn parse_side(s: &str) -> Result<Side, StoreError> {
|
||||
/// earlier version accepted ("+10000-01-01" and "-0001-01-01" included).
|
||||
/// The calendar the books keep (ledger_core::calendar) bounds new
|
||||
/// commands, never replay: a date an earlier version journaled always
|
||||
/// replays (rules.md B-28).
|
||||
/// replays (BS-entry-4).
|
||||
fn parse_date(s: &str) -> Result<chrono::NaiveDate, StoreError> {
|
||||
chrono::NaiveDate::parse_from_str(s, "%Y-%m-%d")
|
||||
.map_err(|_| StoreError::JournalCorrupt(format!("bad date {s}")))
|
||||
@@ -7248,7 +7248,7 @@ fn get_opt_decimal(p: &Value, key: &str) -> Result<Decimal, StoreError> {
|
||||
/// A full TIN is found as the version before P3 found one
|
||||
/// (`ledger_core::parties::replaying`): a name, reason or fact an earlier
|
||||
/// version took replays, however the commands' detector has widened since
|
||||
/// (rules.md B-28).
|
||||
/// (BS-entry-4).
|
||||
pub(crate) fn replay_line_into_ledger(
|
||||
ledger: &mut Ledger,
|
||||
line: &JournalLine,
|
||||
@@ -7384,7 +7384,7 @@ fn replay_line(
|
||||
let want = get_u64(p, "id")?;
|
||||
let orig = get_u64(p, "reverses")?;
|
||||
// As journaled: a reversal later rules would refuse (a void
|
||||
// under a payment that stands) replays (rules.md B-28).
|
||||
// under a payment that stands) replays (BS-entry-4).
|
||||
let got = ledger.replay_reverse_entry(
|
||||
orig,
|
||||
parse_date(get_str(p, "date")?)?,
|
||||
@@ -7400,7 +7400,7 @@ fn replay_line(
|
||||
let want = get_u64(p, "id")?;
|
||||
// No convention (every schedule before P3): equal months, as
|
||||
// they were posted. A convention this version doesn't know is
|
||||
// newer, never corrupt (rules.md B-27).
|
||||
// newer, never corrupt (BS-format-1).
|
||||
let convention = match p.get("convention") {
|
||||
None | Some(Value::Null) => ledger_core::ScheduleConvention::MonthlyEven,
|
||||
Some(Value::String(c)) => {
|
||||
@@ -7525,7 +7525,7 @@ fn replay_line(
|
||||
}
|
||||
"account.renamed" => {
|
||||
// Only that the account exists: the name rules are the
|
||||
// command's (rules.md B-28). `code`, `previous` and `reason`
|
||||
// command's (BS-entry-4). `code`, `previous` and `reason`
|
||||
// are the record, not state.
|
||||
ledger.replay_rename_account(get_u64(p, "account_id")?, get_str(p, "name")?)?;
|
||||
}
|
||||
@@ -7567,7 +7567,7 @@ fn replay_line(
|
||||
| "attachment.text_extracted" => {
|
||||
// Not accounting state; the projection records them. (The text
|
||||
// record is checked for shape here: an unknown status is newer,
|
||||
// rules.md B-27.)
|
||||
// BS-format-1.)
|
||||
if line.line_type == "attachment.text_extracted" {
|
||||
crate::meta::text_extracted_of(line)?;
|
||||
}
|
||||
@@ -7578,7 +7578,7 @@ fn replay_line(
|
||||
}
|
||||
"audit.run" => {
|
||||
// Not accounting state; the projection records it. Checked
|
||||
// for shape here (an unknown scope is newer, rules.md B-27).
|
||||
// for shape here (an unknown scope is newer, BS-format-1).
|
||||
crate::meta::audit_run_of(line)?;
|
||||
}
|
||||
// A claim that someone checked; no figure moves.
|
||||
@@ -7647,7 +7647,7 @@ fn replay_line(
|
||||
}
|
||||
"party.updated" => {
|
||||
// A field this version doesn't know: a newer one wrote it
|
||||
// (rules.md B-27). A known field with a bad value is damage.
|
||||
// (BS-format-1). A known field with a bad value is damage.
|
||||
if let Some(field) = p
|
||||
.get("change")
|
||||
.and_then(|c| c.get("field"))
|
||||
@@ -7754,7 +7754,7 @@ fn replay_line(
|
||||
// this line says it was the asset's run for the month, which is
|
||||
// what the books carry for the asset (Ledger::accumulated_posted).
|
||||
// Replay checks only that it is well formed and names an asset
|
||||
// and entry that exist (rules.md B-28).
|
||||
// and entry that exist (BS-entry-4).
|
||||
let amount = get_str(p, "amount")?.parse::<Decimal>().map_err(|_| {
|
||||
StoreError::JournalCorrupt("asset.depreciation_posted amount".into())
|
||||
})?;
|
||||
@@ -8083,8 +8083,8 @@ fn optional_decimal(p: &Value, key: &str) -> Result<Option<Decimal>, ()> {
|
||||
|
||||
/// An `asset.basis_set`'s facts. A rule or §704(c) method this version
|
||||
/// doesn't know was written by a newer one: NewerJournal, never corrupt
|
||||
/// (rules.md B-27). The figures the line carries are type-checked and
|
||||
/// otherwise left to its readers: replay never recomputes them (B-28).
|
||||
/// (BS-format-1). The figures the line carries are type-checked and
|
||||
/// otherwise left to its readers: replay never recomputes them (BS-entry-4).
|
||||
fn asset_basis_from_journal(
|
||||
line: &JournalLine,
|
||||
p: &Value,
|
||||
@@ -8122,7 +8122,7 @@ fn asset_basis_from_journal(
|
||||
|
||||
/// A journaled close's target. A rounding rule only a newer version
|
||||
/// writes (an unknown name, or a value that isn't a name) is newer, never
|
||||
/// corrupt (rules.md B-27).
|
||||
/// corrupt (BS-format-1).
|
||||
fn close_to_from_journal(line: &JournalLine, v: Option<&Value>) -> Result<CloseTo, StoreError> {
|
||||
let corrupt = |what: &str| StoreError::JournalCorrupt(format!("close_to: {what}"));
|
||||
let ids = |v: &Value| -> Result<Vec<AccountId>, StoreError> {
|
||||
@@ -9002,11 +9002,11 @@ fn apply_line_rows(conn: &Connection, line: &JournalLine) -> Result<(), StoreErr
|
||||
)?;
|
||||
}
|
||||
// A payment moves no document row: what a document is paid is read
|
||||
// from the ledger lines tagged with it (schema v15, rules.md B-38).
|
||||
// from the ledger lines tagged with it (schema v15, BS-arap-2).
|
||||
"invoice.payment_received" => {}
|
||||
// A write-off moves no document row either: written_off and the
|
||||
// status are derived from the tagged lines (the tag is set by
|
||||
// replay; rules.md B-41).
|
||||
// replay; BS-arap-5).
|
||||
"invoice.written_off" => {}
|
||||
"bill.paid" => {
|
||||
conn.execute(
|
||||
@@ -9396,8 +9396,8 @@ pub enum Subject {
|
||||
Schedule(u64),
|
||||
/// A reconciliation (its statement).
|
||||
Reconciliation(u64),
|
||||
/// A project (its contract, spec, pitch, correspondence; rules.md
|
||||
/// B-37). Journal feature `projects`.
|
||||
/// A project (its contract, spec, pitch, correspondence;
|
||||
/// BS-statement-5). Journal feature `projects`.
|
||||
Project(u64),
|
||||
/// The company itself (formation documents).
|
||||
Company,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Documents through the store, at random (rules.md B-38 INVARIANTS 1, 2,
|
||||
//! Documents through the store, at random (BS-arap-2 INVARIANTS 1, 2,
|
||||
//! 4 and 6; plan P4b.15): histories of invoices, bills, payments (with a
|
||||
//! payment method and a reference, or none), voids, reversals of any
|
||||
//! entry, closed months and refused hand lines, run through `Store`, then
|
||||
@@ -9,7 +9,7 @@
|
||||
//! the live books, their replay and a viewer's snapshot agree on
|
||||
//! every figure, at every date, and the control accounts equal
|
||||
//! their documents.
|
||||
//! SOURCE: docs/spec/rules.md B-28 (replay), B-38 INVARIANTS 1, 2, 4, 6.
|
||||
//! SOURCE: BS-entry-4 (replay), BS-arap-2 INVARIANTS 1, 2, 4, 6.
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
@@ -417,7 +417,7 @@ fn agree(live: &Ledger, dir: &Path, docs: &[DocRef]) -> Result<(), TestCaseError
|
||||
proptest! {
|
||||
#![proptest_config(ProptestConfig::with_cases(32))]
|
||||
|
||||
/// B-38 INVARIANT 4 (and 1, 2, 6 through the store): a document's
|
||||
/// BS-arap-2 INVARIANT 4 (and 1, 2, 6 through the store): a document's
|
||||
/// state is a function of the journal and the day. Half the history,
|
||||
/// then the books reopened and compared; the rest on the reopened
|
||||
/// books, compared again.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Documents read their figures from the ledger lines tagged with them
|
||||
//! (plan P4b S1, D-45; rules.md B-38): the books an earlier version wrote,
|
||||
//! (plan P4b S1, D-45; BS-arap-2): the books an earlier version wrote,
|
||||
//! replayed, and the golden figures that version showed for them.
|
||||
//!
|
||||
//! The fixture `tests/fixtures/p4-arap-before` is a books dir written by
|
||||
@@ -377,7 +377,7 @@ fn legacy_reversal_now_counts() {
|
||||
assert_eq!(trial_balance_json(&again), g["trial_balance"]);
|
||||
}
|
||||
|
||||
/// B-38 scenario 5 and item 7 in books an earlier version keeps: the
|
||||
/// BS-arap-2 scenario 5 and item 7 in books an earlier version keeps: the
|
||||
/// right payment after the wrong one was reversed waits for the journal
|
||||
/// feature document_standing (an older version would count both),
|
||||
/// refused and journaling nothing until the owner's upgrade; a payment
|
||||
@@ -430,7 +430,7 @@ fn repaying_after_a_reversal_waits_for_document_standing() {
|
||||
}
|
||||
|
||||
/// The control guard through the store, and a void under a payment:
|
||||
/// refused, journaling nothing (B-38 scenarios 3 and 6).
|
||||
/// refused, journaling nothing (BS-arap-2 scenarios 3 and 6).
|
||||
#[test]
|
||||
fn the_store_refuses_hand_lines_and_a_void_under_a_payment() {
|
||||
let dir = fixture("guard");
|
||||
@@ -619,7 +619,7 @@ fn legacy_documents_replay_with_tags() {
|
||||
|
||||
/// A document's new fields (its number, terms, snapshots, references, a
|
||||
/// line's account, quantity or price) wait for the journal feature
|
||||
/// `documents_v2` (plan P4b S4.3; rules.md B-27): refused,
|
||||
/// `documents_v2` (plan P4b S4.3; BS-format-1): refused,
|
||||
/// FormatUpgradePending, journaling nothing, in books that haven't declared
|
||||
/// it; after the owner's upgrade the same writes are taken, and the books
|
||||
/// replay to what was live.
|
||||
@@ -831,7 +831,7 @@ fn no_new_fields_journals_byte_for_byte() {
|
||||
}
|
||||
|
||||
/// The issued copy is filed with the invoice or nothing is (plan P4b S4.3
|
||||
/// item 11, A-7; rules.md B-40 item 3): a refusal leaves the journal, the
|
||||
/// item 11, A-7; BS-arap-4 item 3): a refusal leaves the journal, the
|
||||
/// ledger and the allocators exactly as they were; an issue journals the
|
||||
/// entry, `invoice.created`, `receipt.attached` on that entry
|
||||
/// (`INV-0007.pdf`, `application/pdf`, "Issued invoice") and
|
||||
@@ -1166,7 +1166,7 @@ fn sends_replay_and_project() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A send changes no figure (plan P4b S5, B-38): on the fixture book an
|
||||
/// A send changes no figure (plan P4b S5, BS-arap-2): on the fixture book an
|
||||
/// earlier version wrote, every report, every derived document figure and
|
||||
/// the invoice's whole DocState are the same before and after it.
|
||||
#[test]
|
||||
@@ -1247,7 +1247,7 @@ fn mark_sent_on_void_refused() {
|
||||
|
||||
/// A settlement of two invoices, a discount and a processor's fee: one
|
||||
/// entry whose events name the lines they tag, every figure derived, and
|
||||
/// the books replaying to the same lines (plan P4b S6; rules.md B-42
|
||||
/// the books replaying to the same lines (plan P4b S6; BS-arap-6
|
||||
/// INVARIANTS 1 and 3).
|
||||
#[test]
|
||||
fn a_settlement_names_its_lines_and_replays() {
|
||||
@@ -1360,7 +1360,7 @@ fn a_settlement_names_its_lines_and_replays() {
|
||||
/// A settlement of more than one document, a discount or a fee needs
|
||||
/// `documents_v2`: refused, journaling nothing, in books without it, and
|
||||
/// accepted after the owner's upgrade, replaying to the same books (plan
|
||||
/// P4b S6; rules.md B-27, B-42).
|
||||
/// P4b S6; BS-format-1, BS-arap-6).
|
||||
#[test]
|
||||
fn settlement_waits_for_documents_v2() {
|
||||
use ledger_core::{Application, DocRef, SettleParams};
|
||||
@@ -1422,7 +1422,7 @@ fn settlement_waits_for_documents_v2() {
|
||||
|
||||
/// Legacy payment events carry no `line`, so replay keeps the positional
|
||||
/// rule: the first untagged control line for the payment's amount, in the
|
||||
/// order the events come (plan P4b S6; rules.md B-42 INVARIANT 3).
|
||||
/// order the events come (plan P4b S6; BS-arap-6 INVARIANT 3).
|
||||
#[test]
|
||||
fn legacy_payment_events_keep_the_positional_rule() {
|
||||
use ledger_core::{DocRef, Movement};
|
||||
@@ -1460,7 +1460,7 @@ fn legacy_payment_events_keep_the_positional_rule() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Bad-debt write-offs (plan P4b S7; rules.md B-41)
|
||||
// Bad-debt write-offs (plan P4b S7; BS-arap-5)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// The evidence a write-off test files: a collection letter.
|
||||
@@ -1527,7 +1527,7 @@ fn a_write_off_whose_notice_is_anothers_receipt_is_refused_before_posting() {
|
||||
/// A write-off needs journal feature documents_v2 (its event type is new;
|
||||
/// an older version refuses the unknown type): refused, journaling
|
||||
/// nothing, until the owner's upgrade; then it is taken and replays to the
|
||||
/// same books (R-A, B-27).
|
||||
/// same books (R-A, BS-format-1).
|
||||
#[test]
|
||||
fn write_off_waits_for_documents_v2() {
|
||||
let dir = fixture("write-off-v2");
|
||||
@@ -1582,7 +1582,7 @@ fn write_off_waits_for_documents_v2() {
|
||||
/// A write-off is journaled as its entry and one `invoice.written_off`,
|
||||
/// and replay derives the same figures and the projection agrees: the
|
||||
/// invoice reads Written off, the bad-debt expense is on 6990, and the
|
||||
/// control account still equals its documents (B-41, B-38 INVARIANT 1).
|
||||
/// control account still equals its documents (BS-arap-5, BS-arap-2 INVARIANT 1).
|
||||
#[test]
|
||||
fn write_off_replays_and_projects() {
|
||||
let dir = test_dir("write-off-replay");
|
||||
@@ -1600,7 +1600,7 @@ fn write_off_replays_and_projects() {
|
||||
)
|
||||
.unwrap();
|
||||
// Half paid, the rest written off: the invoice reads Written off with
|
||||
// 50 paid and 50 written off (B-38 SCENARIO 7).
|
||||
// 50 paid and 50 written off (BS-arap-2 SCENARIO 7).
|
||||
s.receive_payment(inv, d(2026, 4, 20), cents(5_000), bank)
|
||||
.unwrap();
|
||||
let from = journal_len(&dir.0);
|
||||
@@ -1683,7 +1683,7 @@ fn write_off_replays_and_projects() {
|
||||
s.verify().unwrap();
|
||||
}
|
||||
|
||||
/// No evidence, no write-off (B-41 INVARIANT 1; Treas. Reg.
|
||||
/// No evidence, no write-off (BS-arap-5 INVARIANT 1; Treas. Reg.
|
||||
/// §1.166-2(a)): refused, journaling nothing; an attachment already filed
|
||||
/// is linked instead, to the entry and the invoice.
|
||||
#[test]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! never carry a month twice, take exactly cost less salvage over
|
||||
//! the life, and dispose at proceeds less the book value of the
|
||||
//! days held.
|
||||
//! SOURCE: docs/spec/rules.md B-9, B-10, B-15; plan/served.md P3 (settled
|
||||
//! SOURCE: BS-ledger-5, BS-ledger-6, BS-asset-1; plan/served.md P3 (settled
|
||||
//! in design: a skipped month is caught up in the month the run is
|
||||
//! made); Ledger::dispose_asset INVARIANT 1.
|
||||
//! INVARIANTS (checked after every command, refused or not):
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//! Spec-derived store tests for asset tags and serial numbers (rules.md
|
||||
//! B-24): journaling (`asset.tagged` {asset_id, tag, previous_tag},
|
||||
//! Spec-derived store tests for asset tags and serial numbers (
|
||||
//! BS-asset-3): journaling (`asset.tagged` {asset_id, tag, previous_tag},
|
||||
//! `asset.serial_set` {asset_id, serial | null}), replay on reopen, the v9
|
||||
//! SQLite projection agreeing with the journal (`Store::verify`), books
|
||||
//! written before tags existed, refusals journaling nothing, and corrupt
|
||||
//! `asset.serial_set` lines refused on open; and tax basis (B-25:
|
||||
//! `asset.serial_set` lines refused on open; and tax basis (BS-asset-4:
|
||||
//! `asset.basis_set`, pre-P3 `asset.tax_basis_set` {asset_id, rule,
|
||||
//! contributor_basis | null} replayed, the v10 schema and v13's, corrupt
|
||||
//! and newer payloads). A database at an older schema under this
|
||||
//! version's file name is rebuilt, never migrated, and P2's own file is
|
||||
//! left as it is (each schema keeps a file of its own: rules.md B-27,
|
||||
//! left as it is (each schema keeps a file of its own: BS-format-1,
|
||||
//! tests/schema_files.rs).
|
||||
//!
|
||||
//! Expectations come from the doc comments on `Store::set_asset_tag`,
|
||||
@@ -405,7 +405,7 @@ fn downgrade_db_to_v8(dir: &Path) {
|
||||
|
||||
/// A database at schema v8 under this version's own file name (what an
|
||||
/// older wanderbooks once migrated in place) is never migrated now: each
|
||||
/// schema keeps a file of its own (rules.md B-27), so this one is damaged,
|
||||
/// schema keeps a file of its own (BS-format-1), so this one is damaged,
|
||||
/// kept aside and rebuilt from the journal as the books open, and verifies.
|
||||
#[test]
|
||||
fn a_v8_database_migrates_and_verifies() {
|
||||
@@ -571,7 +571,7 @@ fn a_description_change_replays_and_verifies() {
|
||||
s.verify().unwrap();
|
||||
}
|
||||
|
||||
// ------------------------------------------------- tax basis (rules.md B-25)
|
||||
// ------------------------------------------------- tax basis (BS-asset-4)
|
||||
//
|
||||
// Expectations from `Store::set_asset_basis` (journaled as
|
||||
// `asset.basis_set`, the feature `asset_basis` declared first),
|
||||
@@ -822,7 +822,7 @@ fn a_basis_set_whose_figures_disagree_still_replays() {
|
||||
}
|
||||
|
||||
/// A basis rule or §704(c) method this version doesn't know was written
|
||||
/// by a newer one: NewerJournal, never corrupt (rules.md B-27); a figure
|
||||
/// by a newer one: NewerJournal, never corrupt (BS-format-1); a figure
|
||||
/// or fact that isn't a decimal string (or null) is corrupt.
|
||||
#[test]
|
||||
fn an_unknown_basis_rule_or_method_is_newer() {
|
||||
@@ -955,7 +955,7 @@ fn downgrade_db_to_v10(dir: &Path) {
|
||||
/// for byte: this version builds its own file from the journal, its
|
||||
/// runs table keyed by entry with every run kept and the new columns
|
||||
/// empty, and it verifies; a basis set after then reloads from it (each
|
||||
/// schema in a file of its own: rules.md B-27).
|
||||
/// schema in a file of its own: BS-format-1).
|
||||
#[test]
|
||||
fn a_p2_database_is_left_and_this_versions_built_from_the_journal() {
|
||||
use ledger_core::BasisRule::*;
|
||||
@@ -1175,7 +1175,7 @@ fn reversing_a_linked_acquisition_still_opens_and_verifies() {
|
||||
Store::open(&dir).unwrap().verify().unwrap();
|
||||
}
|
||||
|
||||
// ------------------------------------------------- depreciation runs (rules.md B-15 rules 6 and 8)
|
||||
// ------------------------------------------------- depreciation runs (BS-asset-1 rules 6 and 8)
|
||||
|
||||
/// A run is the books' record of what they carry for an asset
|
||||
/// (Ledger::accumulated_posted): recorded live, replayed from the journal,
|
||||
@@ -1219,7 +1219,7 @@ fn runs_replay_reload_and_verify_catches_a_tampered_run() {
|
||||
|
||||
/// The writer and the viewer read an `asset.depreciation_posted` line the
|
||||
/// same way: well formed and naming an asset and an entry that exist, it
|
||||
/// replays (any period an earlier version journaled, rules.md B-28);
|
||||
/// replays (any period an earlier version journaled, BS-entry-4);
|
||||
/// otherwise both refuse it as corrupt.
|
||||
#[test]
|
||||
fn the_viewer_and_writer_agree_on_a_bad_depreciation_posted_payload() {
|
||||
@@ -1257,7 +1257,7 @@ fn the_viewer_and_writer_agree_on_a_bad_depreciation_posted_payload() {
|
||||
}
|
||||
}
|
||||
|
||||
/// B-27: books an older version wrote (format 1, declaring nothing) refuse
|
||||
/// BS-format-1: books an older version wrote (format 1, declaring nothing) refuse
|
||||
/// a basis while they wait for the owner's format upgrade, a purchase's
|
||||
/// too, journaling nothing; the feature is never declared on the way (P3
|
||||
/// review, 2026-10-21).
|
||||
|
||||
@@ -875,7 +875,7 @@ fn a_run_reinstated_after_its_rerun_was_reversed_still_counts() {
|
||||
Store::open(dir.path()).unwrap().verify().unwrap();
|
||||
}
|
||||
|
||||
/// P3 review round 2: a correction comes after what it corrects (B-9). A
|
||||
/// P3 review round 2: a correction comes after what it corrects (BS-ledger-5). A
|
||||
/// reversal of a depreciation run dated before the run (March's run, dated
|
||||
/// Mar 31, reversed on Feb 10) would leave January and February with
|
||||
/// negative depreciation, and a disposal on Feb 15 clearing what February
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Audits and attestations in the store (plan P8; rules.md B-45): the
|
||||
//! Audits and attestations in the store (plan P8; BS-ledger-13): the
|
||||
//! `audits` feature, the figure head, idempotent runs, attestations that
|
||||
//! rest on a head, and the integrity findings only the store can see.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The store refuses what the books can't hold, before it journals
|
||||
//! anything, never a panic (P0 review round 3, S1: a panic stops the books
|
||||
//! server). The bounds are for new commands only: books an earlier version
|
||||
//! wrote past them open exactly as written (rules.md B-28; P0 review round
|
||||
//! wrote past them open exactly as written (BS-entry-4; P0 review round
|
||||
//! 4), each bound's pair here or in tests/fixtures/old-books.
|
||||
//!
|
||||
//! ```text
|
||||
@@ -233,7 +233,7 @@ fn disposal_proceeds_larger_than_a_line_are_refused() {
|
||||
assert_eq!(old.ledger().get_entry(2).unwrap().date(), d(10000, 1, 31));
|
||||
}
|
||||
|
||||
/// The bounds are for new commands only (rules.md B-28: posted is
|
||||
/// The bounds are for new commands only (BS-entry-4: posted is
|
||||
/// forever). A journal line an earlier version wrote past them (a date
|
||||
/// after 9999, up to chrono's last day, as chrono writes it: "+10000-01-01";
|
||||
/// a draft or recurring line past the line limit) opens, in the writer and the viewer alike, exactly as written. A
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! An invoice's or bill's lines in the journal (rules.md B-37 item 8,
|
||||
//! B-27): a line naming its project carries `class_id` (journal feature
|
||||
//! An invoice's or bill's lines in the journal (BS-statement-5 item 8,
|
||||
//! BS-format-1): a line naming its project carries `class_id` (journal feature
|
||||
//! `document_line_projects`), and the entry's revenue or expense line for
|
||||
//! that project is tagged by `entry.line_class_set` right after its
|
||||
//! `entry.line_added`. A document naming no project is journaled exactly
|
||||
@@ -9,7 +9,7 @@
|
||||
//! ```text
|
||||
//! GOAL: a document's projects are journaled once, replay exactly, and
|
||||
//! never reach books whose owner hasn't consented to the format.
|
||||
//! SOURCE: docs/spec/rules.md B-37 item 8, B-27, B-28; plan/served.md
|
||||
//! SOURCE: BS-statement-5 item 8, BS-format-1, BS-entry-4; plan/served.md
|
||||
//! D-39 (the owner's upgrade).
|
||||
//! ```
|
||||
|
||||
@@ -479,7 +479,7 @@ fn old_invoices_and_bills_replay_unchanged() {
|
||||
|
||||
/// A document line's `class_id` that isn't a class id is damage, never
|
||||
/// silently no project; null is none, and an id is taken as journaled
|
||||
/// (replay checks no line, B-28).
|
||||
/// (replay checks no line, BS-entry-4).
|
||||
#[test]
|
||||
fn a_document_lines_class_id_that_isnt_an_id_is_corrupt() {
|
||||
let journal = |dir: &Path, class: Value| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Documents whose lines' sum is past exact arithmetic are refused, never a
|
||||
//! panic (kernel sweep unit K-U4; rules.md B-21, B-28).
|
||||
//! panic (kernel sweep unit K-U4; BS-entry-3, BS-entry-4).
|
||||
//!
|
||||
//! A posted entry's lines are bounded by the line cap at the moment it
|
||||
//! posts, restored or new (`entry.posted` validates), so a report's sums
|
||||
@@ -9,8 +9,8 @@
|
||||
//! ```text
|
||||
//! GOAL: a document whose lines sum past exact arithmetic is refused with
|
||||
//! a ledger error and journals nothing.
|
||||
//! SOURCE: docs/spec/rules.md B-28 (a replayed line is accepted of any
|
||||
//! size), B-21 (amounts are exact); bookspec BS-entry-3,
|
||||
//! SOURCE: BS-entry-4 (a replayed line is accepted of any
|
||||
//! size), BS-entry-3 (amounts are exact); bookspec BS-entry-3,
|
||||
//! BS-entry-4.
|
||||
//! ```
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//! ```text
|
||||
//! GOAL: the decision ("no 1099" included) and how each payment was made
|
||||
//! are kept as records, and no version ever misreads them.
|
||||
//! SOURCE: rules.md B-19, B-27; ledger_store::form1099 INVARIANTS 1-5.
|
||||
//! SOURCE: BS-1099-1, BS-format-1; ledger_store::form1099 INVARIANTS 1-5.
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
@@ -139,7 +139,7 @@ fn types(dir: &Path) -> Vec<(String, serde_json::Value)> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// B-27: a line that needs a feature is written only in books that
|
||||
/// BS-format-1: a line that needs a feature is written only in books that
|
||||
/// declare it, and a command never declares one on the way. Books an
|
||||
/// older version wrote (format 1) refuse a decision and a payment method
|
||||
/// while they wait for their format upgrade, journaling nothing; the
|
||||
@@ -500,7 +500,7 @@ fn marking_a_w9_keeps_who_decided_the_1099() {
|
||||
assert_eq!(v.decisions_1099, [decision]);
|
||||
}
|
||||
|
||||
/// B-27: a value only a newer version writes, in a line of a type this
|
||||
/// BS-format-1: a value only a newer version writes, in a line of a type this
|
||||
/// version knows (a 1099 decision, a reason kind, a payment method's
|
||||
/// kind), is newer, never corrupt; a malformed one is corrupt.
|
||||
#[test]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! GOAL: an older wanderbooks tells the human to update, not that the
|
||||
//! books are damaged, and never shows books that differ from the
|
||||
//! record without saying so.
|
||||
//! SOURCE: rules.md B-27; plan/served.md 5.1 (format gate).
|
||||
//! SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
|
||||
//! INVARIANTS:
|
||||
//! 1. A whole, chained line of a type this version doesn't know, or a
|
||||
//! journal.format_set newer than it reads, is NewerJournal: from
|
||||
@@ -436,7 +436,7 @@ fn edit_journal(dir: &Path, edit: impl FnOnce(&mut Vec<String>)) {
|
||||
}
|
||||
|
||||
/// A line's own hash is checked only by the next line's prev, so the
|
||||
/// gate's refusal waits for it (rules.md B-27): a flipped bit in a middle
|
||||
/// gate's refusal waits for it (BS-format-1): a flipped bit in a middle
|
||||
/// line's type, or a declared format edited from 1 to 2, reads like books
|
||||
/// from a newer wanderbooks until the next line shows the line changed.
|
||||
/// That is corruption, from the writer and the viewer alike.
|
||||
@@ -525,8 +525,8 @@ fn a_newer_line_the_next_line_chains_onto_is_newer_and_intact() {
|
||||
/// A line the gate refuses, followed by a complete line this version
|
||||
/// can't even parse as JSON (or a blank one), is unverified: nothing
|
||||
/// checks the refused line, so it is newer or damaged, never corrupt for
|
||||
/// certain (a newer format may frame its lines its own way; rules.md
|
||||
/// B-27), and never intact.
|
||||
/// certain (a newer format may frame its lines its own way;
|
||||
/// BS-format-1), and never intact.
|
||||
#[test]
|
||||
fn a_refused_line_followed_by_a_garbled_line_is_unverified() {
|
||||
for (i, garbled) in ["{not json", "", "[1,2]", "{\"prev\":7}"]
|
||||
@@ -567,7 +567,7 @@ fn append_raw(dir: &Path, bytes: &[u8]) {
|
||||
}
|
||||
|
||||
/// A newer format frames the lines after its declaration its own way
|
||||
/// (rules.md B-27): a float, a string seq, a key of its own. This version
|
||||
/// (BS-format-1): a float, a string seq, a key of its own. This version
|
||||
/// reads only the next line's prev, so it never calls such books corrupt:
|
||||
/// the declaration is intact when that prev checks it, unverified when the
|
||||
/// next line has no prev it can read, and corrupt only when a prev it can
|
||||
@@ -632,7 +632,7 @@ fn a_newer_format_frames_its_lines_its_own_way() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A key beside the envelope's is never dropped (rules.md B-27): the line
|
||||
/// A key beside the envelope's is never dropped (BS-format-1): the line
|
||||
/// is refused as newer, and its hash covers the key, so the next line
|
||||
/// still checks it (intact), a next line hashed without the key shows it
|
||||
/// was added (corrupt), and as the last line it is unverified. The writer
|
||||
@@ -759,7 +759,7 @@ fn an_old_reader_never_repairs_newer_books() {
|
||||
assert_eq!(store.tail_repairs().unwrap().len(), 1);
|
||||
}
|
||||
|
||||
/// B-27 ("a cut-off last line is set aside only when the lines before it
|
||||
/// BS-format-1 ("a cut-off last line is set aside only when the lines before it
|
||||
/// pass"; Store::open SCENARIO 3): a complete line that chains and passes
|
||||
/// the gate but can't be applied (a post of an entry that doesn't exist),
|
||||
/// or a first line that isn't store.created, refuses the open with the
|
||||
@@ -803,7 +803,7 @@ fn a_bad_complete_line_before_a_torn_tail_leaves_the_journal_as_it_was() {
|
||||
));
|
||||
}
|
||||
|
||||
/// The viewer applies the writer's rule for the first line (B-27: the
|
||||
/// The viewer applies the writer's rule for the first line (BS-format-1: the
|
||||
/// two read the same journal the same way): it must be a store.created
|
||||
/// naming a currency. Any other first line, or a store.created without a
|
||||
/// sound base_currency, is corrupt for both; neither guesses a currency.
|
||||
@@ -920,7 +920,7 @@ fn read_journal_and_format_gives_every_line_and_the_format() {
|
||||
);
|
||||
}
|
||||
|
||||
/// P3's journal extensions (rules.md B-27; plan D-39): each is announced
|
||||
/// P3's journal extensions (BS-format-1; plan D-39): each is announced
|
||||
/// by a feature this version knows, `account_renamed` for an
|
||||
/// `account.renamed`, `require_tax_category` for a `settings.set` naming
|
||||
/// `policy.require_tax_category`. Books an older version made (books():
|
||||
@@ -1090,7 +1090,7 @@ fn lines(dir: &Path) -> Vec<serde_json::Value> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// P3 (defect 9; rules.md B-27, D-39): a daily schedule's
|
||||
/// P3 (defect 9; BS-format-1, D-39): a daily schedule's
|
||||
/// schedule.registered, which carries convention "daily", needs journal
|
||||
/// feature schedule_convention. Books an older version made (books():
|
||||
/// format 1) refuse one, journaling nothing, until the owner's format
|
||||
@@ -1193,7 +1193,7 @@ fn a_monthly_even_schedule_declares_no_feature() {
|
||||
}
|
||||
|
||||
/// P3: a schedule convention this version doesn't know (one a newer
|
||||
/// version adds) is newer, never corrupt (rules.md B-27); one that isn't a
|
||||
/// version adds) is newer, never corrupt (BS-format-1); one that isn't a
|
||||
/// string is damage.
|
||||
#[test]
|
||||
fn an_unknown_schedule_convention_is_newer_not_corrupt() {
|
||||
@@ -1234,7 +1234,7 @@ fn an_unknown_schedule_convention_is_newer_not_corrupt() {
|
||||
assert_corrupt(Store::open(&dir));
|
||||
}
|
||||
|
||||
/// P4b S4.2 (rules.md B-27): a `party.updated` naming a field this version
|
||||
/// P4b S4.2 (BS-format-1): a `party.updated` naming a field this version
|
||||
/// doesn't know is newer, never corrupt; a known field with a malformed
|
||||
/// value is still damage.
|
||||
#[test]
|
||||
@@ -1283,7 +1283,7 @@ fn an_unknown_party_field_is_newer_not_corrupt() {
|
||||
assert_corrupt(Store::open(&dir));
|
||||
}
|
||||
|
||||
/// P3 (R3; rules.md B-27): a schedule month reversed within its month is
|
||||
/// P3 (R3; BS-format-1): a schedule month reversed within its month is
|
||||
/// posted again only in books that declare journal feature month_reposting
|
||||
/// (an older version would refuse the second schedule.posted as posted
|
||||
/// twice): books an older version made wait for the format upgrade, and
|
||||
@@ -1506,7 +1506,7 @@ fn the_replay_fuzzer_writes_every_event_type() {
|
||||
/// Done-when (plan P4b S5): the send event is this version's, it needs
|
||||
/// `documents_v2`, and the books declare that feature before the first
|
||||
/// `invoice.sent` line, so a version without it stops at the declaration
|
||||
/// and reports the books as newer, never corrupt (rules.md B-27).
|
||||
/// and reports the books as newer, never corrupt (BS-format-1).
|
||||
#[test]
|
||||
fn an_older_version_stops_at_invoice_sent() {
|
||||
assert!(EVENT_TYPES.contains(&"invoice.sent"));
|
||||
@@ -1585,9 +1585,9 @@ fn an_older_version_stops_at_invoice_sent() {
|
||||
|
||||
/// The weekly fuzz run of 2026-10-26 (`fuzz_store_replay`, crash
|
||||
/// 0dfab1cc): a journal whose `convention.set` names a kind this version
|
||||
/// doesn't know. The writer says NewerJournal (B-27: newer content is
|
||||
/// doesn't know. The writer says NewerJournal (BS-format-1: newer content is
|
||||
/// newer, never corrupt); the viewer must say the same, since the two
|
||||
/// share one reading of the journal (rules.md B-27, docs/architecture.md
|
||||
/// share one reading of the journal (BS-format-1, docs/architecture.md
|
||||
/// "The journal format gate").
|
||||
#[test]
|
||||
fn an_unknown_convention_kind_is_newer_for_the_writer_and_the_viewer_alike() {
|
||||
@@ -1624,7 +1624,7 @@ fn an_unknown_convention_kind_is_newer_for_the_writer_and_the_viewer_alike() {
|
||||
/// `drafts_v2`, and the books declare that feature before the first such
|
||||
/// line, so a version without it stops at the declaration and reports the
|
||||
/// books as newer, never corrupt, never keeping a discarded draft that
|
||||
/// would block a close (rules.md B-27, B-43).
|
||||
/// would block a close (BS-format-1, BS-entry-5).
|
||||
#[test]
|
||||
fn an_older_version_stops_at_the_draft_events() {
|
||||
assert!(EVENT_TYPES.contains(&"entry.draft_state_set"));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! The format upgrade (plan/served.md 3.9, D-39; rules.md B-27): books an
|
||||
//! The format upgrade (plan/served.md 3.9, D-39; BS-format-1): books an
|
||||
//! older wanderbooks wrote open on their old journal format, refuse only
|
||||
//! what needs the new one, and move to this version's format in one
|
||||
//! journaled step; books this version makes are in its format from their
|
||||
@@ -9,7 +9,7 @@
|
||||
//! without the owner's go-ahead, and an upgrade changes nothing of the
|
||||
//! books but what may be written from then on.
|
||||
//! SOURCE: plan/served.md 3.9 ("Format changes are the server's gate, not
|
||||
//! the updater's"); D-39; rules.md B-27.
|
||||
//! the updater's"); D-39; BS-format-1.
|
||||
//! INVARIANTS:
|
||||
//! 1. New books declare this version's format, every feature it knows,
|
||||
//! as they are created: they wait for no upgrade.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Golden file for draft states, discard and the one evidence gate
|
||||
//! (`docs/parity.md`: "Draft states and discard" and "One evidence gate").
|
||||
//!
|
||||
//! Rules: `docs/spec/rules.md` B-43 (a draft waits on its evidence; one that
|
||||
//! Rules: BS-entry-5 (a draft waits on its evidence; one that
|
||||
//! will never post can be discarded), D-47 (a reversal needs no receipt of
|
||||
//! its own), B-12 (a period with an open draft cannot close).
|
||||
//! its own), BS-period-2 (a period with an open draft cannot close).
|
||||
//!
|
||||
//! It is a `Store` fixture, not a bare `Ledger`, because the gate's second
|
||||
//! half (is a receipt on file) lives in the store. Every expected value is
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Members closes in the journal (P3 defect 17, rules.md B-13, B-27):
|
||||
//! Members closes in the journal (P3 defect 17, BS-partner-1, BS-format-1):
|
||||
//! the cumulative rule's feature declaration, its `since_seq`, what a
|
||||
//! newer or damaged rounding tag does on replay, and the first close after
|
||||
//! the upgrade on books an earlier version wrote. Every expected figure is
|
||||
@@ -166,7 +166,7 @@ fn three_cumulative_closes(dir: &Path) -> Books {
|
||||
b
|
||||
}
|
||||
|
||||
/// Contract (rules.md B-27; P3 defect 17; D-39): a members close counted
|
||||
/// Contract (BS-format-1; P3 defect 17; D-39): a members close counted
|
||||
/// from its regime's start needs the `members_cumulative` feature, so an
|
||||
/// older version stops at its declaration (it would replay the close under
|
||||
/// the run rule). New books declare it on their second line, with the rest
|
||||
@@ -262,7 +262,7 @@ fn the_first_cumulative_close_declares_its_feature() {
|
||||
/// A change to a journaled close's target.
|
||||
type Edit = dyn Fn(&mut Value);
|
||||
|
||||
/// Contract (rules.md B-27; P3 review R-9): a rounding rule only a newer
|
||||
/// Contract (BS-format-1; P3 review R-9): a rounding rule only a newer
|
||||
/// version writes is newer, never corrupt: an unknown name, or a value
|
||||
/// that isn't a name. A `since_seq` beside another rule, or a
|
||||
/// "cumulative_since" without a usable one, is damage.
|
||||
@@ -325,7 +325,7 @@ fn an_unknown_rounding_is_newer_not_corrupt() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Contract (B-13, B-8): a count that starts after the books' first close
|
||||
/// Contract (BS-partner-1, BS-ledger-4): a count that starts after the books' first close
|
||||
/// journals the close it starts at, and replays to it. January's cent
|
||||
/// closes at 50/50 (close 1, A's: the tie). February's at 60/40 starts a
|
||||
/// new count at close 2 (0.006 / 0.004: A's), and March's continues it
|
||||
@@ -364,7 +364,7 @@ fn a_count_that_starts_later_journals_its_start() {
|
||||
assert_eq!((bal(b.caps[0]), bal(b.caps[1])), (dec("0.02"), dec("0.01")));
|
||||
}
|
||||
|
||||
/// Contract (B-8, B-13): replay re-derives where each count of members
|
||||
/// Contract (BS-ledger-4, BS-partner-1): replay re-derives where each count of members
|
||||
/// closes starts and refuses a close journaled with another start, so a
|
||||
/// wrong `since_seq` makes the books refuse to open, never show figures
|
||||
/// split some other way.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Books P2 wrote, served by this version before the owner's go-ahead
|
||||
//! (plan/served.md 3.9, D-39; rules.md B-27, B-28): nothing is written
|
||||
//! (plan/served.md 3.9, D-39; BS-format-1, BS-entry-4): nothing is written
|
||||
//! that P2 can't read, or would read with another meaning, and every line
|
||||
//! P2 wrote opens.
|
||||
//!
|
||||
@@ -23,7 +23,7 @@
|
||||
//! upgrade (a category P2 knew, months run in order, a disposal on or
|
||||
//! after the in-service date).
|
||||
//! 3. A line P2 accepted replays, in the writer and the viewer, however
|
||||
//! the commands' checks have widened since (B-28).
|
||||
//! the commands' checks have widened since (BS-entry-4).
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
@@ -318,7 +318,7 @@ fn update_party_journals_party_updated() {
|
||||
assert_eq!(got.notes.as_deref(), Some("net 30"));
|
||||
}
|
||||
|
||||
/// Oracle: P4b S4.2 (A-13, rules.md B-39, R-A step 3): a party's email and
|
||||
/// Oracle: P4b S4.2 (A-13, BS-arap-3, R-A step 3): a party's email and
|
||||
/// default terms are `party.updated` facts the `documents_v2` feature
|
||||
/// guards. In books that haven't declared it they are refused, journaling
|
||||
/// nothing; after the upgrade they journal, replay gives them back, and an
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! A party named the creditor of a liability (rules.md B-35, P3 defect
|
||||
//! A party named the creditor of a liability (BS-partner-3, P3 defect
|
||||
//! 24), in the store: journaled as `party.creditor_set {id, account_id,
|
||||
//! on}`, which needs the journal feature `party_creditors`: books this
|
||||
//! version made declared it when they were created; books an older
|
||||
//! version wrote refuse it until their format upgrade (rules.md B-27).
|
||||
//! version wrote refuse it until their format upgrade (BS-format-1).
|
||||
//!
|
||||
//! Oracles: `Store::set_party_creditor`'s doc, `format::KNOWN_FEATURES`
|
||||
//! and `PARTY_CREDITORS`, `Store::ensure_feature`'s doc (refused,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Projects in the journal (rules.md B-37): `class.added`, then the whole
|
||||
//! Projects in the journal (BS-statement-5): `class.added`, then the whole
|
||||
//! record as `project.set` (journal feature `projects`); links to a
|
||||
//! project and decisions naming one wait for the feature too.
|
||||
//!
|
||||
@@ -6,7 +6,7 @@
|
||||
//! GOAL: a project's record is journaled once, whole, replays exactly,
|
||||
//! and books waiting for their format upgrade can still add
|
||||
//! projects by name but write nothing an older reader would misread.
|
||||
//! SOURCE: docs/spec/rules.md B-37, B-27; D-39 (the owner's upgrade).
|
||||
//! SOURCE: BS-statement-5, BS-format-1; D-39 (the owner's upgrade).
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//! A reversal is dated on or after the entry it reverses, for every kind of
|
||||
//! entry (D-73, 2026-11-08; rules.md B-9; bookspec BS-ledger-5): a
|
||||
//! entry (D-73, 2026-11-08; BS-ledger-5; bookspec BS-ledger-5): a
|
||||
//! correction comes after what it corrects. A journal an earlier version
|
||||
//! wrote may hold one dated before its original, and it opens as it was
|
||||
//! (B-28: bounds bind new commands, never replay).
|
||||
//! (BS-entry-4: bounds bind new commands, never replay).
|
||||
//!
|
||||
//! ```text
|
||||
//! GOAL: no new reversal precedes its original; no old one stops a journal
|
||||
//! from opening, or moves a figure.
|
||||
//! SOURCE: docs/spec/rules.md B-9, B-28; plan/served.md D-73.
|
||||
//! SOURCE: BS-ledger-5, BS-entry-4; plan/served.md D-73.
|
||||
//! ```
|
||||
|
||||
use chrono::NaiveDate;
|
||||
@@ -114,7 +114,7 @@ fn a_plain_entrys_reversal_is_not_dated_before_it() {
|
||||
|
||||
/// A journal an earlier version wrote, holding a reversal dated before its
|
||||
/// original, opens exactly as it was: same figures, chain verified, in the
|
||||
/// writer and again after a snapshot-less reopen (B-28).
|
||||
/// writer and again after a snapshot-less reopen (BS-entry-4).
|
||||
#[test]
|
||||
fn a_journal_with_an_earlier_dated_reversal_opens_as_it_was() {
|
||||
let (dir, s, rent, cash, e) = books("replay");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Spec-derived tests for control-role assignment in the store.
|
||||
//!
|
||||
//! Oracles: `docs/spec/rules.md` B-23 ("the assignment is journaled, so
|
||||
//! Oracles: BS-ledger-8 ("the assignment is journaled, so
|
||||
//! replay never depends on a setting outside the journal"), the doc comment
|
||||
//! on `Store::assign_role` (journaled as `role.assigned`, with the account
|
||||
//! that filled the role before), and the `Ledger::assign_role` spec (a
|
||||
@@ -246,7 +246,7 @@ fn a_refused_assignment_journals_nothing() {
|
||||
assert_eq!(state(s.ledger()), mid);
|
||||
}
|
||||
|
||||
/// Oracle: B-23 (replay never depends on a setting outside the journal):
|
||||
/// Oracle: BS-ledger-8 (replay never depends on a setting outside the journal):
|
||||
/// reopening gives the same assignments, and later commands still post to
|
||||
/// the assigned accounts.
|
||||
#[test]
|
||||
@@ -304,7 +304,7 @@ fn assignments_replay_on_reopen_and_steer_later_invoices() {
|
||||
assert_eq!(state(s.ledger()), after);
|
||||
}
|
||||
|
||||
/// Oracle: B-23 + close_period: a close to retained earnings after the
|
||||
/// Oracle: BS-ledger-8 + close_period: a close to retained earnings after the
|
||||
/// role is assigned goes to the assigned account, and replays identically.
|
||||
#[test]
|
||||
fn a_close_to_assigned_retained_earnings_replays_identically() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Each projection schema in a file of its own (ledger_store::db_file_for;
|
||||
//! plan/served.md 3.9: before the owner consents to a format upgrade, the
|
||||
//! way back to an older version is always there; rules.md B-27).
|
||||
//! way back to an older version is always there; BS-format-1).
|
||||
//!
|
||||
//! ```text
|
||||
//! GOAL: an older version, gone back to, finds the books it can open,
|
||||
|
||||
@@ -117,7 +117,7 @@ fn assert_every_reader_agrees(dir: &std::path::Path, s: &Store) {
|
||||
/// until their format upgrade (the owner's go-ahead, D-39); then it is
|
||||
/// made, after the one declaration.
|
||||
/// `invoicing.first_number` is settable only while no numbered invoice
|
||||
/// exists (A-2, rules.md B-40): once a number has been issued the series
|
||||
/// exists (A-2, BS-arap-4): once a number has been issued the series
|
||||
/// has begun, so changing or clearing the starting number is refused before
|
||||
/// anything is journaled, and a legacy invoice (no number) never locks it.
|
||||
#[test]
|
||||
@@ -568,7 +568,7 @@ fn a_template_amount_is_at_most_a_lines() {
|
||||
}
|
||||
|
||||
/// A setting key or convention kind this version doesn't know is a newer
|
||||
/// version's, never damage (rules.md B-27).
|
||||
/// version's, never damage (BS-format-1).
|
||||
#[test]
|
||||
fn a_newer_key_or_kind_is_newer() {
|
||||
for (event, payload) in [
|
||||
@@ -773,7 +773,7 @@ fn figures(s: &Store) -> (Value, Vec<ledger_core::JournalEntry>) {
|
||||
|
||||
fn run(s: &mut Store, op: &Op) {
|
||||
// A record (anything but a post or a template's draft) changes no
|
||||
// figure and no entry (rules.md B-29; Lean Step.record_changes_no_figure).
|
||||
// figure and no entry (BS-ledger-9; Lean Step.record_changes_no_figure).
|
||||
let records = !matches!(op, Op::Post(_) | Op::Template(_));
|
||||
let before = records.then(|| figures(s));
|
||||
run_op(s, op);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! event, replays identically, and waits for the owner's format upgrade.
|
||||
//!
|
||||
//! Expected behavior comes from `docs/receipt-store.md` (the three events)
|
||||
//! and rules.md B-27 (a feature is declared before its first line).
|
||||
//! and BS-format-1 (a feature is declared before its first line).
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use ledger_core::Currency;
|
||||
|
||||
@@ -723,7 +723,7 @@ fn schedules_and_recurring_entries_replay_exactly() {
|
||||
assert!(store.run_recurring(date(2, 28)).unwrap().is_empty());
|
||||
}
|
||||
|
||||
/// Regression (B-12, found by the refusal property on 2026-10-13):
|
||||
/// Regression (BS-period-2, found by the refusal property on 2026-10-13):
|
||||
/// `run_recurring` leaves occurrences in a closed period ungenerated
|
||||
/// instead of creating drafts there, and still generates the rest.
|
||||
#[test]
|
||||
@@ -1246,7 +1246,7 @@ mod refusals {
|
||||
}]
|
||||
};
|
||||
match *op {
|
||||
// Named for the code: a sibling's name is refused (B-31), and
|
||||
// Named for the code: a sibling's name is refused (BS-ledger-10), and
|
||||
// a code is the first refusal.
|
||||
Op::AddAccount(c, t, p, h) => store
|
||||
.add_account(
|
||||
@@ -1772,7 +1772,7 @@ mod refusals {
|
||||
/// Regression (CI, 2026-10-13): a payroll run with unrounded employer
|
||||
/// tax posted $65.27794, and sums of it differed in scale between the
|
||||
/// journal replay and the SQLite read-back. Posting now refuses
|
||||
/// fractions of a cent (B-3; `no_entry_posts_a_fraction_of_the_minor_unit`);
|
||||
/// fractions of a cent (BS-ledger-1; `no_entry_posts_a_fraction_of_the_minor_unit`);
|
||||
/// this replays the sequence with the tax rounded, as callers must.
|
||||
#[test]
|
||||
fn regression_payroll_with_a_fraction_of_a_cent() {
|
||||
@@ -1793,7 +1793,7 @@ mod refusals {
|
||||
}
|
||||
|
||||
/// D-75: the ten-place bound on a foreign amount is the command's, never
|
||||
/// replay's (B-28). A journal an earlier version wrote, holding a line with
|
||||
/// replay's (BS-entry-4). A journal an earlier version wrote, holding a line with
|
||||
/// a 26-place foreign amount, opens with its figures exactly as journaled.
|
||||
#[test]
|
||||
fn a_journaled_foreign_line_finer_than_ten_places_still_opens() {
|
||||
@@ -2398,7 +2398,7 @@ fn books_written_under_older_rules_still_open() {
|
||||
);
|
||||
// The write-off replays as written: its line is the invoice's
|
||||
// (WriteOff), so what it owes fell by 30.00 and what was written off
|
||||
// rose by it (B-41, B-38).
|
||||
// rose by it (BS-arap-5, BS-arap-2).
|
||||
let st = store
|
||||
.ledger()
|
||||
.invoice_state(2, NaiveDate::from_ymd_opt(2026, 6, 30).unwrap())
|
||||
@@ -2426,7 +2426,7 @@ fn books_written_under_older_rules_still_open() {
|
||||
/// written through main 188c90ea's Store API (or, for x_older_rules, its
|
||||
/// JournalWriter, as above), and expected.json by main's own code: verify,
|
||||
/// the canonical report snapshot, and every record as replayed. They hold
|
||||
/// what P0 bounds for new commands only (rules.md B-28): dates before 0001
|
||||
/// what P0 bounds for new commands only (BS-entry-4): dates before 0001
|
||||
/// and after 9999 (to chrono's first and last days), draft, recurring and
|
||||
/// share amounts past the line limit (to Decimal's largest), a contributor
|
||||
/// basis past it, sub-cent document and payroll lines, an asset life of
|
||||
@@ -2500,7 +2500,7 @@ fn old_books_figures(l: &ledger_core::Ledger) -> serde_json::Value {
|
||||
})
|
||||
}
|
||||
|
||||
/// Contract (posted is forever, rules.md B-28; P0 review round 4,
|
||||
/// Contract (posted is forever, BS-entry-4; P0 review round 4,
|
||||
/// 2026-10-17): every book an earlier version wrote opens, in the writer
|
||||
/// (Store::open, its database rebuilt from the journal) and the viewer
|
||||
/// (Snapshot::load) alike, verifies as it did, and replays to exactly the
|
||||
@@ -2540,7 +2540,7 @@ fn books_an_earlier_version_wrote_open_to_its_figures() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every figure the engine derives from old books (B-28: computed, or
|
||||
/// Every figure the engine derives from old books (BS-entry-4: computed, or
|
||||
/// refused with TooLargeToCompute or DateOutOfRange, never a panic): every
|
||||
/// report over the books' whole span and the calendar's, every asset's
|
||||
/// schedule and register row, every amortization plan, every recurring
|
||||
@@ -2636,7 +2636,7 @@ fn every_figure_of(l: &ledger_core::Ledger) -> (usize, usize) {
|
||||
tally(reports::general_ledger(l, start, end).map(|_| ()));
|
||||
tally(reports::members_equity(l, start, end, &members).map(|_| ()));
|
||||
// The statement of cash flows foots on every book, or is refused
|
||||
// for a reason: never an engine error (rules.md B-14 rule 9).
|
||||
// for a reason: never an engine error (BS-statement-3 rule 9).
|
||||
let cf = reports::cash_flow(
|
||||
l,
|
||||
&reports::CashFlowParams {
|
||||
@@ -2738,7 +2738,7 @@ fn every_figure_of(l: &ledger_core::Ledger) -> (usize, usize) {
|
||||
(ok, refused)
|
||||
}
|
||||
|
||||
/// B-28 over every old book: each figure is computed or refused, never a
|
||||
/// BS-entry-4 over every old book: each figure is computed or refused, never a
|
||||
/// panic, in the writer's ledger and the viewer's.
|
||||
#[test]
|
||||
fn every_figure_over_old_books_is_computed_or_refused() {
|
||||
@@ -2909,7 +2909,7 @@ fn store_add(store: &mut Store, code: &str, t: AccountType) -> ledger_core::Acco
|
||||
store.add_account(code, code, t, None, false).unwrap()
|
||||
}
|
||||
|
||||
/// Contract (rules.md B-13): each members close journals its rounding rule
|
||||
/// Contract (BS-partner-1): each members close journals its rounding rule
|
||||
/// and replays under it: "cumulative_since" with the close its count starts
|
||||
/// at for new closes (P3), "cumulative" for the run rule of 2026-10-13 to
|
||||
/// P3, "largest_remainder" for the per-close rule of earlier on 2026-10-13.
|
||||
@@ -3387,7 +3387,7 @@ fn searching_entries_filters_and_pages() {
|
||||
}
|
||||
|
||||
/// The database's invoice row keeps no figure of its own (schema 15,
|
||||
/// rules.md B-38): what it has been paid is the ledger's, read from the
|
||||
/// BS-arap-2): what it has been paid is the ledger's, read from the
|
||||
/// lines tagged with it, so a reversed payment no longer counts; the row
|
||||
/// is the same before and after each payment, and verify agrees.
|
||||
#[test]
|
||||
@@ -3607,7 +3607,7 @@ fn a_database_with_damaged_pages_is_rebuilt() {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// P3: renaming an account, and the tax category policy (defects 15 and 8;
|
||||
// rules.md B-31, B-32).
|
||||
// BS-ledger-10, BS-ledger-11).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Every row of every projection table but the journal's own (`events`,
|
||||
@@ -3675,7 +3675,7 @@ fn figures_but_names(l: &ledger_core::Ledger) -> serde_json::Value {
|
||||
})
|
||||
}
|
||||
|
||||
/// rename_account (repro 1.2; rules.md B-31): a rename changes the
|
||||
/// rename_account (repro 1.2; BS-ledger-10): a rename changes the
|
||||
/// account's name and nothing else: no figure, entry or line, no earlier
|
||||
/// journal line, no projection row but `accounts.name`; the journal gains
|
||||
/// one `account.renamed` line (keyed by id, with the old name and the
|
||||
@@ -3778,7 +3778,7 @@ fn rename_account_changes_only_the_name_defect_15() {
|
||||
assert_eq!(snap.ledger().chart().get(rent).unwrap().name, "Rent");
|
||||
}
|
||||
|
||||
/// rules.md B-28's pair for renames (review R5): the command refuses a
|
||||
/// BS-entry-4's pair for renames (review R5): the command refuses a
|
||||
/// blank name, a sibling's or nine digits; replay takes a journaled line
|
||||
/// holding any of them (a later version may tighten the rules, never lock
|
||||
/// out books it wrote), and refuses only an account that doesn't exist.
|
||||
@@ -3850,7 +3850,7 @@ fn tax_policy(store: &mut Store, value: Option<&str>) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// add_account_with_tax and the policy (rules.md B-32): under warn an
|
||||
/// add_account_with_tax and the policy (BS-ledger-11): under warn an
|
||||
/// account is created without a category; under refuse a revenue or
|
||||
/// expense account that isn't a header is refused without one, journaling
|
||||
/// nothing, and created with one as account.added then account.tax_set;
|
||||
@@ -3996,7 +3996,7 @@ fn the_tax_category_policy_refuses_only_what_it_says() {
|
||||
Store::open(&dir).unwrap().verify().unwrap();
|
||||
}
|
||||
|
||||
/// rules.md B-28's pair for the policy (review R5): the policy is the
|
||||
/// BS-entry-4's pair for the policy (review R5): the policy is the
|
||||
/// commands', never replay's. A journal that sets refuse and then clears
|
||||
/// a category, or adds an uncategorized expense account, replays.
|
||||
#[test]
|
||||
@@ -4065,7 +4065,7 @@ mod p3_properties {
|
||||
..ProptestConfig::default()
|
||||
})]
|
||||
|
||||
/// rules.md B-31 (the engine-side counterpart to the Lean note,
|
||||
/// BS-ledger-10 (the engine-side counterpart to the Lean note,
|
||||
/// docs/verification.md law 15): on books with postings, any sequence
|
||||
/// of renames changes no figure (the ledger's statements, without
|
||||
/// names), no entry and no earlier journal line; live equals
|
||||
@@ -4098,7 +4098,7 @@ mod p3_properties {
|
||||
prop_assert!(live.differs_from(reopened.ledger()).is_empty());
|
||||
}
|
||||
|
||||
/// rules.md B-32: add_account_with_tax is refused exactly when the
|
||||
/// BS-ledger-11: add_account_with_tax is refused exactly when the
|
||||
/// policy is refuse, the account needs a category (revenue or
|
||||
/// expense, not a header) and none is given, or when the category
|
||||
/// doesn't fit; a refusal journals nothing.
|
||||
@@ -4303,7 +4303,7 @@ fn books_written_under_p3_keep_their_names() {
|
||||
assert_eq!(chart_of(snap.ledger()), want);
|
||||
}
|
||||
|
||||
/// rules.md B-31: a new account's name is journaled trimmed, as a rename
|
||||
/// BS-ledger-10: a new account's name is journaled trimmed, as a rename
|
||||
/// journals one, so the live books, a reopen and the projection all read
|
||||
/// the same name; the command's text rules refuse a name a report can't
|
||||
/// print on one line, journaling nothing.
|
||||
|
||||
Reference in new issue
Block a user