merge: SOURCE lines cite what states the rule now, not a retired record (S-E4; re-checked)

Thirty-seven SOURCE clauses across four crates cited a retired bookspec
record: BS-format-1 (25), BS-ledger-13 (8), BS-ledger-12 (4). Each now
cites the product rule that states its fact: the journal format gate,
its features, the owner's upgrade and the projection schemas
(WB-format-1 to 4), the audit (WB-ledger-16), evidence read from the
bytes (WB-ledger-15). source_refs now refuses a retired id unless the
clause names a live successor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-09 09:01:34 -07:00
commit 009049d968
18 files changed
+138 -41

No files matched your search

+1 -1
View File
@@ -6122,7 +6122,7 @@ impl Ledger {
/// GOAL: record a send as a fact of the document's life, without
/// touching a figure: a send moves no money.
/// SOURCE: BS-arap-2 (a document keeps no figure of its
/// own), BS-format-1 (the invoice.sent line, feature documents_v2);
/// own), WB-format-2 (the invoice.sent line, feature documents_v2);
/// plan P4b S5, A-4 (the books record sends; they never send).
/// INVARIANTS:
/// 1. The invoice MUST exist, and a send MUST NOT be dated before it.
@@ -12,6 +12,12 @@
//! branch are counted, and that count is a floor-style constant: it
//! changes only on purpose, in the same commit as the constant.
//!
//! A bookspec id whose record is retired is no source: the retired
//! record states what the rule was, not what governs now. It is kept
//! only in a historical mention that names a live successor in the same
//! clause ("formerly BS-ledger-13, now WB-ledger-16"), so a reader can
//! follow the rule forward without the code resting on a retired id.
//!
//! The second check flags any retired rule number (the old wanderbooks
//! numbering, a word-boundary capital letter, hyphen and a number from
//! 1 to 45) in every tracked text file, outside the excluded index and
@@ -146,6 +152,8 @@ fn is_path_like(token: &str) -> bool {
struct ClauseCtx<'a> {
root: &'a Path,
bs_ids: &'a BTreeSet<String>,
/// The retired records' ids and why each was retired.
retired_bs: &'a BTreeMap<String, String>,
wb_ids: &'a BTreeSet<String>,
identifiers: &'a BTreeSet<String>,
basenames: &'a BTreeSet<String>,
@@ -158,15 +166,29 @@ fn check_clause(clause: &str, ctx: &ClauseCtx<'_>, bad: &mut Vec<String>, at: &s
};
let mut errors: Vec<String> = Vec::new();
let mut cited = false;
for id in ids_in(text, "BS-") {
let bs_ids = ids_in(text, "BS-");
let wb_ids = ids_in(text, "WB-");
// A live rule named in the same clause is a retired id's successor:
// the retirement names it, or the claims file does.
let successor = wb_ids.iter().any(|id| ctx.wb_ids.contains(id))
|| bs_ids
.iter()
.any(|id| ctx.bs_ids.contains(id) && !ctx.retired_bs.contains_key(id));
for id in &bs_ids {
cited = true;
if !ctx.bs_ids.contains(&id) {
if !ctx.bs_ids.contains(id) {
errors.push(format!("unknown bookspec id {id}"));
} else if let Some(reason) = ctx.retired_bs.get(id)
&& !successor
{
errors.push(format!(
"retired bookspec id {id} is no source ({reason}); cite the rule that states it now, or name its successor in this clause"
));
}
}
for id in ids_in(text, "WB-") {
for id in &wb_ids {
cited = true;
if !ctx.wb_ids.contains(&id) {
if !ctx.wb_ids.contains(id) {
errors.push(format!("unknown product rule {id}"));
}
}
@@ -256,6 +278,24 @@ pub(crate) fn every_source_line_cites_an_existing_rule_or_source() {
.collect();
assert!(!bs_ids.is_empty(), "the pinned bookspec has rules");
let retired_bs: BTreeMap<String, String> = bookspec_checker::records()
.iter()
.filter(|r| r.is_retired())
.map(|r| {
(
r.id.to_string(),
r.retired
.as_ref()
.map(|retired| retired.reason.clone())
.unwrap_or_default(),
)
})
.collect();
assert!(
!retired_bs.is_empty(),
"the pinned bookspec has retired rules"
);
let claims_dir = root.join("docs/spec/claims");
let mut wb_ids = BTreeSet::new();
for entry in std::fs::read_dir(&claims_dir).expect("docs/spec/claims") {
@@ -350,6 +390,7 @@ pub(crate) fn every_source_line_cites_an_existing_rule_or_source() {
let ctx = ClauseCtx {
root: &root,
bs_ids: &bs_ids,
retired_bs: &retired_bs,
wb_ids: &wb_ids,
identifiers: &identifiers,
basenames: &basenames,
@@ -377,6 +418,62 @@ pub(crate) fn every_source_line_cites_an_existing_rule_or_source() {
);
}
#[test]
fn a_retired_bookspec_id_is_no_source() {
let bs_ids: BTreeSet<String> = ["BS-format-1", "BS-ledger-12", "BS-ledger-13", "BS-ledger-7"]
.into_iter()
.map(str::to_string)
.collect();
let retired: BTreeMap<String, String> = [
("BS-format-1", "wholly a product rule"),
("BS-ledger-12", "kept as WB-ledger-15"),
("BS-ledger-13", "kept as WB-ledger-16"),
]
.into_iter()
.map(|(id, why)| (id.to_string(), why.to_string()))
.collect();
let wb_ids: BTreeSet<String> = ["WB-format-1", "WB-ledger-15", "WB-ledger-16"]
.into_iter()
.map(str::to_string)
.collect();
let root = repo_root();
let empty: BTreeSet<String> = BTreeSet::new();
let ctx = ClauseCtx {
root: &root,
bs_ids: &bs_ids,
retired_bs: &retired,
wb_ids: &wb_ids,
identifiers: &empty,
basenames: &empty,
};
let problems = |text: &str| {
let mut bad = Vec::new();
check_clause(text, &ctx, &mut bad, "t");
bad
};
// A bare retired id is no source, however much plan or decision
// text surrounds it.
assert_eq!(problems("SOURCE: BS-ledger-13.").len(), 1);
assert_eq!(
problems("SOURCE: BS-ledger-12; plan/served.md P6.").len(),
1
);
assert_eq!(problems("SOURCE: BS-format-1; D-39.").len(), 1);
// A historical mention that names a live successor in the same
// clause is allowed, so the rule can be followed forward.
assert!(problems("SOURCE: formerly BS-ledger-13, now WB-ledger-16.").is_empty());
assert!(problems("SOURCE: formerly BS-ledger-12, now WB-ledger-15.").is_empty());
assert!(problems("SOURCE: formerly BS-format-1, now WB-format-1.").is_empty());
assert!(
problems("SOURCE: formerly BS-ledger-12, now BS-ledger-7 and WB-ledger-15.").is_empty()
);
// A live rule alone passes as it always did.
assert!(problems("SOURCE: BS-ledger-7.").is_empty());
}
fn retired_count(text: &str) -> usize {
let chars: Vec<char> = text.chars().collect();
let mut count = 0usize;
@@ -12,7 +12,7 @@
//! SOURCE: BS-arap-2 (a document keeps no figure of its own); BS-arap-5
//! (the direct write-off); BS-arap-6 (settlement); BS-ledger-5,
//! BS-ledger-6 (reversal and void); BS-period-2 (a closed period
//! takes no postings); BS-format-1 (the invoice.sent line).
//! takes no postings); WB-format-2 (the invoice.sent line).
//! ```
//!
//! Every test compares the whole ledger to a clone taken before a refused
+1 -1
View File
@@ -4,7 +4,7 @@
//! ```text
//! GOAL: Tobin, Mo or the CPA, on an older viewer, learn to update it,
//! not that the books are damaged.
//! SOURCE: BS-format-1; plan/served.md 5.1 (the viewer reads the journal
//! SOURCE: WB-format-1; plan/served.md 5.1 (the viewer reads the journal
//! directly, so it meets the same gate).
//! ```
+7 -7
View File
@@ -6,7 +6,7 @@
//! that gives the same findings and the same workpaper for the same
//! books, and attestations that rest on a head that has not moved.
//! SOURCE: IRS Pub. 583 (records); Rev. Proc. 98-25 §5.01 (the audit
//! trail); BS-ledger-13; DECISION D-9 (the bar), D-53
//! trail); WB-ledger-16; DECISION D-9 (the bar), D-53
//! (an audit is a run, not a job), IZ-1k (the head).
//! INVARIANTS:
//! 1. `books.audit` previews (what it will check; nothing changes),
@@ -356,7 +356,7 @@ impl BooksServer {
/// ```text
/// GOAL: the whole programme of checks over the books through a day,
/// its workpaper filed, the run journaled.
/// SOURCE: plan/served.md P8; BS-ledger-13; D-9, D-53.
/// SOURCE: plan/served.md P8; WB-ledger-16; D-9, D-53.
/// INVARIANTS:
/// 1. Without `confirmed`, a preview that lists the checks and
/// changes nothing; with it, the preview's digest is required.
@@ -529,7 +529,7 @@ impl BooksServer {
/// ```text
/// GOAL: an audit run's workpaper, whole.
/// SOURCE: plan/served.md P8 step 3; BS-ledger-13.
/// SOURCE: plan/served.md P8 step 3; WB-ledger-16.
/// INVARIANTS:
/// 1. Read-only; the JSON is the one filed, the PDF is handed over.
/// ```
@@ -581,7 +581,7 @@ impl BooksServer {
/// ```text
/// GOAL: a checker's claim that a receipt supports an entry.
/// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9.
/// SOURCE: plan/served.md P8 step 4; WB-ledger-16; D-9.
/// INVARIANTS:
/// 1. The reading is compared with the entry's amount and date; a
/// difference is recorded, marked, and never counts.
@@ -619,7 +619,7 @@ impl BooksServer {
/// ```text
/// GOAL: a checker's claim that it reviewed an entry whole.
/// SOURCE: plan/served.md P8 step 4; BS-ledger-13.
/// SOURCE: plan/served.md P8 step 4; WB-ledger-16.
/// ```
#[tool(
name = "books.review_entry",
@@ -649,7 +649,7 @@ impl BooksServer {
/// ```text
/// GOAL: a checker's claim that a period is right, resting on an
/// audit run at the books' current head.
/// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9; IZ-1k.
/// SOURCE: plan/served.md P8 step 4; WB-ledger-16; D-9; IZ-1k.
/// INVARIANTS:
/// 1. Refused unless an audit through the period's end stands at
/// the current head.
@@ -697,7 +697,7 @@ impl BooksServer {
/// ```text
/// GOAL: every claim that someone checked, and whether it counts.
/// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9.
/// SOURCE: plan/served.md P8 step 4; WB-ledger-16; D-9.
/// INVARIANTS:
/// 1. `counted` is read against the bar as it stands now.
/// ```
+4 -4
View File
@@ -7,7 +7,7 @@
//! wherever they are evidence.
//! SOURCE: plan/served.md P6 step 4 (defect 4) and step 5 (defect 10);
//! IZ-18 (no FIFO guess: `entry.settles` only); Rev. Proc. 98-25
//! (an audit trail); BS-ledger-12.
//! (an audit trail); WB-ledger-15.
//! ```
use super::*;
@@ -23,7 +23,7 @@ impl BooksServer {
/// ```text
/// GOAL: find a filed file by its exact bytes, its receipt number, or
/// what its text says.
/// SOURCE: plan/served.md P6 step 4; BS-ledger-12.
/// SOURCE: plan/served.md P6 step 4; WB-ledger-15.
/// INVARIANTS:
/// 1. EXACTLY one of sha256, receipt_number and text is given.
/// 2. Withdrawn files are listed too, marked (a duplicate is found
@@ -96,7 +96,7 @@ impl BooksServer {
/// ```text
/// GOAL: record what a human read off a file, without touching the file
/// or the ledger's amounts.
/// SOURCE: plan/served.md P6 step 5 (defect 10); BS-ledger-12.
/// SOURCE: plan/served.md P6 step 5 (defect 10); WB-ledger-15.
/// INVARIANTS:
/// 1. Journaled as `attachment.annotated`; a refusal journals nothing.
/// 2. The fields are the closed list of `AnnotationFieldsParam`; at
@@ -206,7 +206,7 @@ impl BooksServer {
/// GOAL: hold identical files once, linked wherever they were evidence,
/// without ever leaving an entry the receipt policy covers with
/// none.
/// SOURCE: plan/served.md P6 step 4 (defect 4); BS-ledger-12.
/// SOURCE: plan/served.md P6 step 4 (defect 4); WB-ledger-15.
/// INVARIANTS:
/// 1. Records sharing one blob SHA are one set; the oldest is kept
/// and linked to every subject the others had.
+1 -1
View File
@@ -9,7 +9,7 @@
//! the viewer and bookspec use.
//! SOURCE: BS-statement-5 (DECISION, owner, 2026-10-21; job
//! costing; ASC 450-30-25-1 for on-spec work), BS-period-3 (omitted
//! dates), BS-format-1 (journal feature `projects`).
//! dates), WB-format-2 (journal feature `projects`).
//! INVARIANTS:
//! 1. Every field is checked before anything is written; a refusal
//! journals nothing.
+1 -1
View File
@@ -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); BS-ledger-13; DECISION D-9 (the bar), D-53
//! trail); WB-ledger-16; 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
+1 -1
View File
@@ -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);
//! BS-format-1 (an older reader says "newer", never "corrupt").
//! WB-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?,
+2 -2
View File
@@ -377,7 +377,7 @@ impl JournalFormat {
/// ```text
/// GOAL: an older wanderbooks never misreads newer books, and never
/// calls them corrupt.
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
/// SOURCE: WB-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.
@@ -647,7 +647,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: BS-format-1 (the envelope and its hash are frozen across
/// SOURCE: WB-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:
+2 -2
View File
@@ -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;
/// BS-format-1 (the envelope is frozen).
/// WB-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"; BS-format-1.
/// SOURCE: docs/receipt-store.md "Line format"; WB-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
+10 -10
View File
@@ -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); BS-format-1.
/// schema in a file of its own); WB-format-4.
/// 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
@@ -909,7 +909,7 @@ impl Store {
///
/// ```text
/// GOAL: books that tell every reader which format they are in.
/// SOURCE: BS-format-1; plan/served.md 5.1 (format gate).
/// SOURCE: WB-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: BS-format-1; plan/served.md 5.1 (format gate), 3.9 and
/// SOURCE: WB-format-1, WB-format-3; 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; BS-format-1.
/// gate"); D-39; WB-format-3.
/// INVARIANTS:
/// 1. One journal line declares the whole format: the format moves
/// exactly once, never feature by feature.
@@ -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: BS-format-1, BS-entry-5; plan P4.
/// SOURCE: WB-format-2, 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.
@@ -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: BS-format-1, BS-arap-4 (plan P4b S4.3); A-2, A-13.
/// SOURCE: WB-format-2, 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
@@ -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: BS-format-1, BS-arap-2; plan/served.md P4b.7
/// SOURCE: WB-format-2, BS-arap-2; plan/served.md P4b.7
/// (document_standing).
/// SCENARIOS:
/// 1. IF the engine refuses it (overpaid, before the invoice, a
@@ -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: BS-format-1, BS-arap-2; plan P4b S5, A-4.
/// SOURCE: WB-format-2, 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
@@ -4534,7 +4534,7 @@ impl Store {
/// ```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: WB-statement-5; BS-format-1 (journal feature
/// SOURCE: WB-statement-5; WB-format-2 (journal feature
/// `projects`).
/// INVARIANTS:
/// 1. A refusal journals nothing: the whole record is rehearsed, and
@@ -4971,7 +4971,7 @@ impl Store {
/// ```text
/// GOAL: a new monthly-even schedule's months are whole units of its
/// currency, and what an earlier version journaled never moves.
/// SOURCE: BS-prepaid-4, BS-format-1, BS-entry-8; D-72 (owner,
/// SOURCE: BS-prepaid-4, WB-format-2, BS-entry-8; D-72 (owner,
/// 2026-11-08).
/// INVARIANTS:
/// 1. The rule is a fact of the books when the schedule is written:
@@ -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: BS-statement-5 statement 6, BS-format-1, BS-entry-4; plan/served.md
//! SOURCE: BS-statement-5 statement 6, WB-format-2, BS-entry-4; plan/served.md
//! D-39 (the owner's upgrade).
//! ```
+1 -1
View File
@@ -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: BS-1099-1, BS-format-1; ledger_store::form1099 INVARIANTS 1-5.
//! SOURCE: BS-1099-1, WB-format-2; ledger_store::form1099 INVARIANTS 1-5.
//! ```
use chrono::NaiveDate;
+1 -1
View File
@@ -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: BS-format-1; plan/served.md 5.1 (format gate).
//! SOURCE: WB-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
+1 -1
View File
@@ -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; BS-format-1.
//! the updater's"); D-39; WB-format-3.
//! INVARIANTS:
//! 1. New books declare this version's format, every feature it knows,
//! as they are created: they wait for no upgrade.
+1 -1
View File
@@ -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: BS-statement-5, BS-format-1; D-39 (the owner's upgrade).
//! SOURCE: BS-statement-5, WB-format-2; D-39 (the owner's upgrade).
//! ```
use chrono::NaiveDate;
@@ -5,7 +5,7 @@
//! ```text
//! GOAL: a yen schedule's months are whole yen, and what an earlier
//! version journaled never moves.
//! SOURCE: BS-prepaid-4, BS-format-1, BS-entry-8; plan/served.md D-72
//! SOURCE: BS-prepaid-4, WB-format-2, BS-entry-8; plan/served.md D-72
//! (owner, 2026-11-08).
//! INVARIANTS:
//! 1. In books that declared the feature, a monthly_even schedule's