diff options
| author | tv <tv@krebsco.de> | 2026-11-17 03:32:39 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 04:40:21 +0100 |
| commit | cbe4d4384e9e11db903a6c25f1b339f6de01c766 (patch) | |
| tree | 1fd104609e16c0110fbbfe0dc0531d47bcd0dc76 /src | |
| parent | 345977eb749ebaa73632830cea42f19ce01e0ef1 (diff) | |
vectors: a snapshot after a checkpoint
The snapshot of a compaction after the store moved to a checkpoint, built
from a document every run builds alike: its change's hash and bytes, which a
run of this code prints, as no script apart encodes Automerge. Left empty
until a run prints them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/federation/vectors.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/federation/vectors.rs b/src/federation/vectors.rs index c905547..54971f9 100644 --- a/src/federation/vectors.rs +++ b/src/federation/vectors.rs @@ -211,3 +211,78 @@ fn the_changes_founding_a_swarm() { expected(&FORK_FOUNDING) ); } + +/// The snapshot of a compaction after the store moved to a checkpoint (`docs/store.md`, +/// Remakes): tv's write on the root, a checkpoint at it, proposed by tv, passed by tv's and +/// lass's votes and written by its version event, all put in one change of one writer at +/// time 0 after the genesis change; the snapshot at those heads of the compaction `c-1`, +/// coordinated by tv's node, proposed at time 0. Its change's hash and bytes, printed by a +/// run of this code, as no script apart encodes Automerge. +const SNAPSHOT: (&str, &str) = ("", ""); + +#[test] +fn a_snapshot_after_a_checkpoint() { + use super::fold::Federation; + use super::held::Holding; + use super::store::Fold; + use crate::document::{ActorId, Document, events}; + let (tv, lass) = (tv(), Party::new("lass", 2)); + let first = first(); + let root = first.root(); + let on = first.hash(); + let write = tv.write( + &[Id::of(&root)], + "home/tv/laptop", + harness::str("10.243.7.3"), + ); + let mut next = first.after(on); + next.checkpoint = Some(vec![Id::of(&write)]); + let proposal = tv.propose(&[Id::of(&write)], &next.json()); + let votes = [&tv, &lass].map(|party| party.vote(&[Id::of(&proposal)], on, next.hash(), true)); + let written = harness::version_event(&[Id::of(&votes[0]), Id::of(&votes[1])], next.hash()); + let mut doc = Document::new(); + doc.apply_changes(events::founding(Federation::NAME, &root, &[])) + .expect("the genesis change"); + let mut doc = doc.with_actor(ActorId::from(&[7u8; 16][..])); + events::put( + &mut doc, + &[&write, &proposal, &votes[0], &votes[1], &written], + ); + let holding = Holding::default(); + holding.read(holding.unread(&doc, 0).expect("a store")); + assert_eq!( + holding.with(|store| Id::of(store.checkpoint()) != Id::of(&root)), + Some(true) + ); + let heads = doc.get_heads(); + let policy = serde_json::json!({}); + let snapshot = crate::remake::snapshot::build( + &doc, + &crate::remake::snapshot::SnapshotParams { + remake_id: "c-1", + coordinator: &first.parties[0].nodes[0], + previous: crate::document::replica::Epoch::GENESIS, + base_heads: &heads, + policy: &policy, + proposed_at: crate::clock::UnixMillis(0), + kind: "compact", + content: None, + translation: &serde_json::Value::Null, + held: Some(&holding), + }, + ) + .expect("a snapshot"); + let changes = snapshot.doc.get_changes(&[]); + let [change] = changes.as_slice() else { + panic!("a snapshot of one change"); + }; + let bytes: String = change + .raw_bytes() + .iter() + .map(|byte| format!("{byte:02x}")) + .collect(); + assert_eq!( + (change.hash().to_string(), bytes), + (SNAPSHOT.0.to_owned(), SNAPSHOT.1.to_owned()) + ); +} |
