@@ -915,7 +915,7 @@ public function test_sync_should_compact_is_false_for_non_compactor() {
915915 $ this ->assertFalse ( $ data ['rooms ' ][0 ]['should_compact ' ] );
916916 }
917917
918- public function test_sync_stale_compaction_succeeds_when_newer_compaction_exists () {
918+ public function test_sync_stale_compaction_is_stored_as_update_when_newer_compaction_exists () {
919919 wp_set_current_user ( self ::$ editor_id );
920920
921921 $ room = $ this ->get_post_room ();
@@ -945,9 +945,12 @@ public function test_sync_stale_compaction_succeeds_when_newer_compaction_exists
945945 )
946946 );
947947
948- // Client 3 sends a stale compaction at cursor 0. The server should find
949- // client 2's compaction in the updates after cursor 0 and silently discard
950- // this one.
948+ // Client 3 sends a stale compaction at cursor 0 (mirroring two offline
949+ // clients that reconnect from the same baseline cursor). The server
950+ // cannot run remove_updates_before_cursor because client 2 has already
951+ // advanced the frontier, but the bytes must still be stored as a
952+ // regular update so client 3's operations can propagate to other
953+ // clients via Yjs state-as-update merging.
951954 $ stale_compaction = array (
952955 'type ' => 'compaction ' ,
953956 'data ' => 'c3RhbGU= ' ,
@@ -960,16 +963,29 @@ public function test_sync_stale_compaction_succeeds_when_newer_compaction_exists
960963
961964 $ this ->assertSame ( 200 , $ response ->get_status () );
962965
963- // Verify the newer compaction is preserved and the stale one was not stored.
964- $ response = $ this ->dispatch_sync (
966+ // Verify the newer compaction is preserved AND the stale compaction's
967+ // bytes were persisted (now as type=update so subsequent compactions
968+ // don't trip the has_newer_compaction check).
969+ $ response = $ this ->dispatch_sync (
965970 array (
966971 $ this ->build_room ( $ room , 4 , 0 , array ( 'user ' => 'c4 ' ) ),
967972 )
968973 );
969- $ update_data = wp_list_pluck ( $ response ->get_data ()['rooms ' ][0 ]['updates ' ], ' data ' ) ;
974+ $ updates = $ response ->get_data ()['rooms ' ][0 ]['updates ' ];
970975
976+ $ update_data = wp_list_pluck ( $ updates , 'data ' );
971977 $ this ->assertContains ( 'Y29tcGFjdGVk ' , $ update_data , 'The newer compaction should be preserved. ' );
972- $ this ->assertNotContains ( 'c3RhbGU= ' , $ update_data , 'The stale compaction should not be stored. ' );
978+ $ this ->assertContains ( 'c3RhbGU= ' , $ update_data , 'The stale compaction bytes should be stored so client 3 \'s operations propagate. ' );
979+
980+ $ stale_entry = null ;
981+ foreach ( $ updates as $ entry ) {
982+ if ( 'c3RhbGU= ' === $ entry ['data ' ] ) {
983+ $ stale_entry = $ entry ;
984+ break ;
985+ }
986+ }
987+ $ this ->assertNotNull ( $ stale_entry , 'The stale compaction entry should be present in the room. ' );
988+ $ this ->assertSame ( 'update ' , $ stale_entry ['type ' ], 'The stale compaction should be stored as type=update, not type=compaction. ' );
973989 }
974990
975991 /*
0 commit comments