test(latest-event): Check that we don't apply invalid edits in the latest event

This commit is contained in:
Damir Jelić
2026-04-15 12:54:28 +02:00
parent 62ff895ce8
commit 9e242abda9

View File

@@ -2290,6 +2290,76 @@ mod builder_tests {
);
}
#[async_test]
async fn test_remote_edit_invalid_edit() {
let room_id = room_id!("!r0");
let user_id = user_id!("@mnt_io:matrix.org");
let event_factory = EventFactory::new().sender(user_id).room(room_id);
let event_id_0 = event_id!("$ev0");
let event_id_1 = event_id!("$ev1");
let server = MatrixMockServer::new().await;
let client = server.client_builder().build().await;
// Prelude.
{
// Create the room.
client.base_client().get_or_create_room(room_id, RoomState::Joined);
// Initialise the event cache store.
client
.event_cache_store()
.lock()
.await
.expect("Could not acquire the event cache lock")
.as_clean()
.expect("Could not acquire a clean event cache lock")
.handle_linked_chunk_updates(
LinkedChunkId::Room(room_id),
vec![
Update::NewItemsChunk {
previous: None,
new: ChunkIdentifier::new(0),
next: None,
},
Update::PushItems {
at: Position::new(ChunkIdentifier::new(0), 0),
items: vec![
// a text message
event_factory
.text_msg("hello")
.sender(user_id!("@alice:example.org"))
.event_id(event_id_0)
.into(),
// a replacement of the previous message
event_factory
.text_msg("* goodbye")
.event_id(event_id_1)
.sender(user_id!("@malory:example.org"))
.edit(
event_id_0,
RoomMessageEventContent::text_plain("goodbye").into(),
)
.into(),
],
},
],
)
.await
.unwrap();
}
let event_cache = client.event_cache();
event_cache.subscribe().unwrap();
let (room_event_cache, _) = event_cache.for_room(room_id).await.unwrap();
assert_remote_value_matches_room_message_with_body!(
// We get `event_id_0` because the edit `event_id_1` is invalid.
Builder::new_remote(&room_event_cache, LatestEventValue::None, user_id, None).await => with body = "hello"
);
}
#[async_test]
async fn test_remote_double_edit() {
let room_id = room_id!("!r0");