Skip to main content

macrame/integrity/
mod.rs

1pub mod audit;
2pub mod rebuild;
3pub mod shadow;
4
5pub use audit::audit_current;
6pub use rebuild::{rebuild_current, RebuildReport};
7pub use shadow::{ShadowOutcome, ShadowStep};
8
9/// The latest-belief projection of `links` โ€” **the single definition** (T0.2).
10///
11/// [Doctrine VI](../../docs/architecture/s0-s3-foundations.md) says
12/// `links_current` must equal this at all times: one row per interval key
13/// `(source_id, target_id, edge_type, valid_from)`, the one with the greatest
14/// `recorded_at`. `rebuild_current` makes it so and `audit_current` checks it.
15///
16/// It lived in both files, byte-for-byte, until 0.6.0. That is the failure class
17/// [D-035](../../docs/architecture/s13-decision-register.md#d-035) exists to
18/// prevent โ€” a rule stated twice is a rule that can disagree with itself โ€” and
19/// it had a second consequence nobody had named: the audit that `rebuild_within`
20/// ran on itself was, in effect, a runtime check that the two copies still
21/// agreed, paid on every archive, under the archive's write lock, forever. With
22/// one definition that check is tautological by construction rather than by
23/// assumption, which is what made it safe to stop paying for it (D-077).
24///
25/// `rn` is not projected: callers select the eight ledger columns.
26pub(crate) const LATEST_BELIEF_PROJECTION: &str = r#"
27    SELECT source_id, target_id, edge_type, valid_from,
28           valid_to, weight, properties, recorded_at
29    FROM (
30        SELECT source_id, target_id, edge_type, valid_from,
31               valid_to, weight, properties, recorded_at,
32               ROW_NUMBER() OVER (
33                   PARTITION BY source_id, target_id, edge_type, valid_from
34                   ORDER BY recorded_at DESC
35               ) AS rn
36        FROM links
37    ) WHERE rn = 1
38"#;