feat(store): a record's source can be corrected without touching its words (P5)

Accounting reason: a convention, a decision or an open item carries who
decided it, when and on what authority. When that is recorded wrongly the
honest fix is to say so on the record, not to restate the policy: a policy
revision bumps the convention's revision and reads as a change of the rule,
and a new decision supersedes the old one. A source correction changes only
the authority and says why, so the audit trail shows the words were never
altered.

New event types convention.source_revised, decision.source_revised and
open_item.source_revised {id, source, reason} under the journal feature
source_revisions: an older version would refuse the types, or show the old
source as the record's authority, so it stops at the declaration instead
(rules.md B-27) and books that have not had the owner's upgrade refuse the
write with format_upgrade_pending, journaling nothing. Replay sets the
source and nothing else (the text, the revision and the journal line stay);
the projection updates the rows' existing source columns, so no schema
changed. A correction must be one: other words, the same source, no reason
or an unknown record is refused.

books.set_convention takes reason (the text exactly as it stands),
books.record_decision and books.raise_item take revises with reason. Without
reason the old refusal stands and now says how to correct only the source.

8.0.6: the hand-written lines of the three shapes in
books_written_under_older_rules_still_open; fixture old-books/p5_before,
written by b97234ac (a revised convention, two decisions, two open items, a
draft) through old-books-writer/src/bin/p5_before.rs, opens to that
version's figures, so no figure moved; books_p2_served_cut_over_whole
refuses the correction before consent and takes it after; the fuzzer and the
viewer's journal know the types. The live books refuse the new write until
the owner gives the go-ahead; merging does not need it.

Tests: a_source_only_revision_is_journaled,
a_source_revision_must_change_only_the_source,
source_revisions_wait_for_the_upgrade, source_revisions_is_its_own_feature.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HS8WZziDnyxunC23MUxrLp
This commit is contained in:
swaitsandClaude Fable 5.1 committed 2026-10-29 15:48:27 -06:00
1 parent cf73d0bda5
commit 4236f03744
19 files changed
+1188 -13

No files matched your search

+46
View File
@@ -65,6 +65,7 @@ pub const KNOWN_FEATURES: &[&str] = &[
DOCUMENTS_V2,
ATTACHMENT_TEXT,
DRAFTS_V2,
SOURCE_REVISIONS,
];
/// Feature: `period.closed` closes to members with `"rounding":
@@ -218,6 +219,15 @@ pub const ATTACHMENT_TEXT: &str = "attachment_text";
/// (rules.md B-27, B-43).
pub const DRAFTS_V2: &str = "drafts_v2";
/// Feature: `source_revisions` (plan P5): `convention.source_revised`,
/// `decision.source_revised` and `open_item.source_revised` correct who
/// decided a convention, a decision or an open item, when and on what,
/// 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).
pub const SOURCE_REVISIONS: &str = "source_revisions";
/// The line type that declares the journal format.
pub const FORMAT_SET: &str = "journal.format_set";
@@ -248,8 +258,10 @@ pub const EVENT_TYPES: &[&str] = &[
"class.added",
"convention.retired",
"convention.set",
"convention.source_revised",
"customer.added",
"decision.recorded",
"decision.source_revised",
"document.filed",
"entry.approved",
"entry.created",
@@ -276,6 +288,7 @@ pub const EVENT_TYPES: &[&str] = &[
"line.cleared",
"open_item.raised",
"open_item.resolved",
"open_item.source_revised",
"party.added",
"party.creditor_set",
"party.role_set",
@@ -989,6 +1002,39 @@ mod tests {
assert_eq!(up.adds(), vec!["the journal feature drafts_v2"]);
}
/// 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).
#[test]
fn source_revisions_is_its_own_feature() {
assert!(KNOWN_FEATURES.contains(&SOURCE_REVISIONS));
let before: Vec<&str> = KNOWN_FEATURES
.iter()
.copied()
.filter(|f| *f != SOURCE_REVISIONS)
.collect();
let l = line(
FORMAT_SET,
json!({"format": 2, "features": [DRAFTS_V2, SOURCE_REVISIONS]}),
);
match declared_knowing(&l, &before) {
Err(StoreError::NewerJournal { need, .. }) => {
assert_eq!(need, "journal features source_revisions")
}
other => panic!("expected NewerJournal, got {other:?}"),
}
let older = JournalFormat {
format: 2,
features: before.iter().map(|f| f.to_string()).collect(),
};
assert!(matches!(
older.require_feature(SOURCE_REVISIONS),
Err(StoreError::FormatUpgradePending { .. })
));
let up = older.upgrade().expect("waits for it");
assert_eq!(up.adds(), vec!["the journal feature source_revisions"]);
}
/// This version's format: the newest it reads, every feature it
/// knows, each once, sorted (what new books and an upgrade declare).
#[test]