huskies: merge 664_story_crdt_lamport_clock_inner_seq_must_resume_from_max_own_author_seq_1_instead_of_resetting_to_1_on_restart_phase_c

This commit is contained in:
dave
2026-04-27 12:26:28 +00:00
parent 25603bb8cb
commit 9040d18f50
5 changed files with 240 additions and 2 deletions
+27
View File
@@ -47,6 +47,21 @@ where
}
}
/// Returns the current Lamport sequence number for this list.
pub fn our_seq(&self) -> SequenceNumber {
self.our_seq
}
/// Advance the internal sequence counter to at least `seq`.
///
/// After `advance_seq(n)`, the next local op will carry `seq = max(our_seq, n) + 1`
/// instead of the default `1`. Used on restart to resume the Lamport clock
/// from the document-wide floor so that newly-created registers don't
/// re-emit low sequence numbers.
pub fn advance_seq(&mut self, seq: SequenceNumber) {
self.our_seq = max(self.our_seq, seq);
}
/// Locally insert some content causally after the given operation
pub fn insert<U: Into<JsonValue>>(&mut self, after: OpId, content: U) -> Op<JsonValue> {
let mut op = Op::new(
@@ -365,6 +380,18 @@ mod test {
assert_eq!(list.view(), vec![1, 4, 2, 3]);
}
#[test]
fn test_advance_seq_resumes_from_floor() {
let mut list = ListCrdt::<i64>::new(make_author(1), vec![]);
list.advance_seq(100);
assert_eq!(list.our_seq(), 100);
let op = list.insert(ROOT_ID, 42);
assert_eq!(
op.seq, 101,
"first op after advance_seq(100) must have seq=101"
);
}
#[test]
fn test_list_idempotence() {
let mut list = ListCrdt::<i64>::new(make_author(1), vec![]);