From 01ec08ac008729fc41f73f6700cfbed52a01c632 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:01:51 +0800 Subject: [PATCH] fix: conflict check when reference right is none (#40) --- .cargo/config.toml | 3 +++ y-octo/src/doc/codec/update.rs | 5 +++++ y-octo/src/doc/document.rs | 17 +++++++++++++++++ y-octo/src/doc/store.rs | 2 +- .../edge-case-left-right-same-node.bin | Bin 0 -> 6673 bytes 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 y-octo/src/fixtures/edge-case-left-right-same-node.bin diff --git a/.cargo/config.toml b/.cargo/config.toml index 4768414..2603371 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ [env] CARGO_WORKSPACE_DIR = { value = "", relative = true } + +[unstable] +gc = true diff --git a/y-octo/src/doc/codec/update.rs b/y-octo/src/doc/codec/update.rs index 1f48eb0..d107666 100644 --- a/y-octo/src/doc/codec/update.rs +++ b/y-octo/src/doc/codec/update.rs @@ -466,6 +466,11 @@ mod tests { (include_bytes!("../../fixtures/database.bin").to_vec(), 1, 149), (include_bytes!("../../fixtures/large.bin").to_vec(), 1, 9036), (include_bytes!("../../fixtures/with-subdoc.bin").to_vec(), 2, 30), + ( + include_bytes!("../../fixtures/edge-case-left-right-same-node.bin").to_vec(), + 2, + 243, + ), ]; for (doc, clients, structs) in docs { diff --git a/y-octo/src/doc/document.rs b/y-octo/src/doc/document.rs index a180ffc..8acad3f 100644 --- a/y-octo/src/doc/document.rs +++ b/y-octo/src/doc/document.rs @@ -608,4 +608,21 @@ mod tests { assert_eq!(&text.to_string(), "hello world"); }); } + + #[test] + #[cfg_attr(any(miri, loom), ignore)] + fn test_apply_update() { + let updates = [ + include_bytes!("../fixtures/basic.bin").to_vec(), + include_bytes!("../fixtures/database.bin").to_vec(), + include_bytes!("../fixtures/large.bin").to_vec(), + include_bytes!("../fixtures/with-subdoc.bin").to_vec(), + include_bytes!("../fixtures/edge-case-left-right-same-node.bin").to_vec(), + ]; + + for update in updates { + let mut doc = Doc::new(); + doc.apply_update_from_binary_v1(&update).unwrap(); + } + } } diff --git a/y-octo/src/doc/store.rs b/y-octo/src/doc/store.rs index aeb8316..d13eaea 100644 --- a/y-octo/src/doc/store.rs +++ b/y-octo/src/doc/store.rs @@ -554,7 +554,6 @@ impl DocStore { let mut right = right.get_mut_unchecked(); right.left = item_owner_ref.clone(); } - this.right = right.clone(); } else { // no right, parent.start = this, delete this.left if let Some(parent_sub) = &this.parent_sub { @@ -565,6 +564,7 @@ impl DocStore { } } } + this.right = right.clone(); let parent_deleted = parent.item.get().map(|item| item.deleted()).unwrap_or(false); diff --git a/y-octo/src/fixtures/edge-case-left-right-same-node.bin b/y-octo/src/fixtures/edge-case-left-right-same-node.bin new file mode 100644 index 0000000000000000000000000000000000000000..c598191e22f76dbbe31283bf842935d152550615 GIT binary patch literal 6673 zcma)=O>84c6~|M(i3!QfWY7@AtdKC;)n<{#gY)Sm9FP-#2?)zway zCy}Das`u}z_kQnH^{ZyS3;y%RfBpUD$P5TnMY-0}rVpB-Eq;HkATDgLL^9d!x^j@` z!P_H_E}-?aRe=L0U590peOX;(JF=kybCRvs1qrSyYy%D`I#AUFSppB388rWm{)07M z5IGe}BY1Q|QDtRS7jzLa#M9;MfzgpxHtKSzu%;;)JsFkOv8MszDOHF32n>393wf#; zYMrfNXC0C2>=<$@Ky@~7({>h$uni?$!~RT;>OBPl^9ye}oDD&TtAeCMRbs_eiPeP; zd=pJPIo4rC1A=h}%BV$~8UsO5&vjJW;lK@>P? zlB{D6j>6>tkh@cZ9Po6XwmEcrCJ)RTUk~34-&+oc@2xC;0}G~XL6xnw8meqaR#CkX z3ONY~kzUI1WmnhevPQqnw~ABHK&J zoRx{us;u)k1e7$cVdYKJaAbGKG`%N64D$6GRaxbrnqxV^(7=OnH2dol&Ujupg5bd@ z9-Ty^_7vurCW``xZ4(;Lajww`?yYJeY?v|B*YT`)#=WEsY-T^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