fix: text diff calc refactor err

This commit is contained in:
Zixuan Chen 2024-08-08 00:36:59 +08:00
parent af274eac79
commit 9d8221ca29
No known key found for this signature in database
3 changed files with 93 additions and 13 deletions

View file

@ -8101,6 +8101,95 @@ fn unknown_fuzz_err_1() {
)
}
#[test]
fn text_fuzz_err_1() {
test_multi_sites(
5,
vec![FuzzTarget::All],
&mut [
Handle {
site: 143,
target: 29,
container: 98,
action: Generic(GenericAction {
value: Container(Unknown(255)),
bool: true,
key: 3149642750,
pos: 18097429212317875131,
length: 64871186039035,
prop: 17565089386645696778,
}),
},
SyncAll,
SyncAll,
SyncAll,
SyncAll,
Checkout {
site: 55,
to: 4294916923,
},
Handle {
site: 251,
target: 0,
container: 239,
action: Generic(GenericAction {
value: I32(657457152),
bool: true,
key: 656877351,
pos: 2821266740684990247,
length: 2826896240219203367,
prop: 17521015924422327227,
}),
},
SyncAll,
Handle {
site: 0,
target: 0,
container: 0,
action: Generic(GenericAction {
value: I32(426766319),
bool: true,
key: 3146720292,
pos: 18694838926267,
length: 10314409433236454331,
prop: 18391499916132989883,
}),
},
SyncAll,
Undo {
site: 111,
op_len: 1869573999,
},
Undo {
site: 111,
op_len: 1869573999,
},
Undo {
site: 111,
op_len: 1869573999,
},
Undo {
site: 111,
op_len: 4294966971,
},
Sync { from: 59, to: 255 },
Handle {
site: 0,
target: 0,
container: 0,
action: Generic(GenericAction {
value: I32(0),
bool: false,
key: 0,
pos: 0,
length: 0,
prop: 0,
}),
},
],
)
}
#[test]
fn minify() {
minify_error(

View file

@ -6,7 +6,7 @@ use generic_btree::{
};
use loro_common::{Counter, HasId, HasIdSpan, IdFull, IdSpan, Lamport, PeerID, ID};
use rle::HasLength as _;
use tracing::instrument;
use tracing::{instrument, trace};
use crate::{cursor::AbsolutePosition, VersionVector};
@ -598,7 +598,7 @@ impl Tracker {
self._checkout(from, false);
self._checkout(to, true);
// self.id_to_cursor.diagnose();
tracing::trace!("Trace::diff {:#?}, ", &self);
// tracing::trace!("Trace::diff {:#?}, ", &self);
self.rope.get_diff()
}

View file

@ -700,7 +700,6 @@ impl DiffCalculatorTrait for ListDiffCalculator {
}
RichtextChunkValue::StyleAnchor { .. } => unreachable!(),
RichtextChunkValue::Unknown(len) => {
trace!("unknown id={:?}", id);
delta = handle_unknown(id, oplog, len, &mut on_new_container, delta);
}
RichtextChunkValue::MoveAnchor => {
@ -824,13 +823,7 @@ impl DiffCalculatorTrait for RichtextDiffCalculator {
}
_ => {
if !matches!(&*self.mode, RichtextCalcMode::Crdt { .. }) {
self.mode = Box::new(RichtextCalcMode::Crdt {
tracker: Box::new(RichtextTracker::new_with_unknown()),
styles: Vec::new(),
start_vv: vv.clone(),
});
return;
unreachable!();
}
}
}
@ -841,7 +834,7 @@ impl DiffCalculatorTrait for RichtextDiffCalculator {
styles,
start_vv,
} => {
if !vv.includes_vv(start_vv) || tracker.all_vv().includes_vv(vv) {
if !vv.includes_vv(start_vv) || !tracker.all_vv().includes_vv(vv) {
*tracker = Box::new(RichtextTracker::new_with_unknown());
styles.clear();
*start_vv = vv.clone();
@ -859,7 +852,6 @@ impl DiffCalculatorTrait for RichtextDiffCalculator {
op: crate::op::RichOp,
vv: Option<&crate::VersionVector>,
) {
trace!("apply_change: {:?}", op.id());
match &mut *self.mode {
RichtextCalcMode::Linear {
diff,
@ -1051,7 +1043,6 @@ impl DiffCalculatorTrait for RichtextDiffCalculator {
} => {
trace!("end with crdt mode");
tracing::debug!("CalcDiff {:?} {:?}", from, to);
trace!("tracker version vector = {:?}", tracker.all_vv());
let mut delta = DeltaRope::new();
for item in tracker.diff(from, to) {
match item {