80381e06a573 | atagen | 2026-10-25 03:02 UTC | 1 | mod support; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 2 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 3 | use std::time::Duration; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 4 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 5 | #[cfg(feature = "mirror")] |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 6 | use macltok::Mirror; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 7 | use macltok::{ |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 8 | ClientHandle, Engine, EngineConfig, EngineError, Event, EventStream, HistoryGap, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 9 | HistoryRepairPhase, HistoryRepairReport, HistoryRepairStop, RecentHistoryState, Termination, |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 10 | TimelineDiff, TimelineId, TimelineItem, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 11 | }; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 12 | use matrix_sdk::{ |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 13 | Client, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 14 | ruma::{EventId, RoomId, api::client::sync::sync_events::v5, event_id, room_id}, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 15 | test_utils::mocks::{MatrixMockServer, RoomMessagesResponseTemplate}, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 16 | }; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 17 | use matrix_sdk_test::{ALICE, JoinedRoomBuilder, event_factory::EventFactory}; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 18 | use support::shut_down; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 19 | use wiremock::ResponseTemplate; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 20 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 21 | struct TestRoom { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 22 | server: MatrixMockServer, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 23 | sync_client: Client, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 24 | handle: ClientHandle, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 25 | events: EventStream, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 26 | running: tokio::task::JoinHandle<Result<Termination, EngineError>>, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 27 | /// the open room's timeline, kept current by every helper that reads events |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 28 | items: imbl::Vector<TimelineItem>, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 29 | opened: bool, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 30 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 31 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 32 | async fn start_room(room_id: &RoomId) -> TestRoom { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 33 | let server = MatrixMockServer::new().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 34 | server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 35 | .mock_sliding_sync() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 36 | .ok(v5::Response::new("1".to_owned())) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 37 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 38 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 39 | let client = server.client_builder().build().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 40 | server.mock_room_state_encryption().plain().mount().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 41 | server.sync_joined_room(&client, room_id).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 42 | let sync_client = client.clone(); |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 43 | let config = EngineConfig::default() |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 44 | .with_initial_history_limit(0) |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 45 | .with_search_backfill_pages_per_room(0); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 46 | let (engine, handle, events) = Engine::from_client(client, config).await.unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 47 | let running = tokio::spawn(engine.run()); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 48 | TestRoom { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 49 | server, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 50 | sync_client, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 51 | handle, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 52 | events, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 53 | running, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 54 | items: imbl::Vector::new(), |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 55 | opened: false, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 56 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 57 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 58 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 59 | /// the next event that satisfies `predicate`. only the open itself may reset the room |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 60 | /// timeline, history after it has to arrive as diffs |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 61 | async fn next_until(room: &mut TestRoom, mut predicate: impl FnMut(&Event) -> bool) -> Event { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 62 | tokio::time::timeout(Duration::from_secs(5), async { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 63 | loop { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 64 | let event = room.events.recv().await.expect("event stream closed"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 65 | match &event { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 66 | Event::TimelineReset { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 67 | timeline_id: TimelineId::Room(_), |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 68 | items, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 69 | } => { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 70 | assert!(!room.opened, "history reset the room timeline"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 71 | room.opened = true; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 72 | room.items = items.clone(); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 73 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 74 | Event::TimelineChanged { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 75 | timeline_id: TimelineId::Room(_), |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 76 | diffs, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 77 | } => { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 78 | for diff in diffs.clone() { |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 79 | assert!( |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 80 | !matches!(diff, TimelineDiff::Reset { .. }), |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 81 | "history replaced the room timeline" |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 82 | ); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 83 | diff.try_apply(&mut room.items) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 84 | .expect("diff did not fit the timeline"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 85 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 86 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 87 | _ => {} |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 88 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 89 | if predicate(&event) { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 90 | return event; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 91 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 92 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 93 | }) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 94 | .await |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 95 | .expect("expected event did not arrive") |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 96 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 97 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 98 | async fn timeline_until( |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 99 | room: &mut TestRoom, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 100 | predicate: impl Fn(&imbl::Vector<TimelineItem>) -> bool, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 101 | ) { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 102 | tokio::time::timeout(Duration::from_secs(5), async { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 103 | while !predicate(&room.items) { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 104 | next_until(room, |_| true).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 105 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 106 | }) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 107 | .await |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 108 | .expect("the timeline never got there"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 109 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 110 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 111 | async fn open_room(room: &mut TestRoom, room_id: &RoomId) { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 112 | room.handle.open_room(room_id.to_owned()).await.unwrap(); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 113 | next_until(room, |event| { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 114 | matches!(event, Event::TimelineReset { timeline_id, .. } if timeline_id.room_id() == room_id) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 115 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 116 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 117 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 118 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 119 | async fn cache_event_before_open(room: &TestRoom, room_id: &RoomId, id: &EventId, body: &str) { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 120 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 121 | .sync_room( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 122 | &room.sync_client, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 123 | JoinedRoomBuilder::new(room_id).add_timeline_event( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 124 | EventFactory::new() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 125 | .text_msg(body) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 126 | .event_id(id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 127 | .sender(&ALICE), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 128 | ), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 129 | ) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 130 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 131 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 132 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 133 | fn history_event( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 134 | room_id: &RoomId, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 135 | id: &EventId, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 136 | body: &str, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 137 | ) -> matrix_sdk::ruma::serde::Raw<matrix_sdk::ruma::events::AnyTimelineEvent> { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 138 | EventFactory::new() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 139 | .room(room_id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 140 | .text_msg(body) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 141 | .event_id(id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 142 | .sender(&ALICE) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 143 | .into_raw_timeline() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 144 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 145 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 146 | async fn wait_for_recent(room: &mut TestRoom, room_id: &RoomId) -> RecentHistoryState { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 147 | let event = next_until(room, |event| { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 148 | matches!(event, Event::RecentHistoryChanged { room_id: id, state, .. } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 149 | if id == room_id && !matches!(state, RecentHistoryState::Loading)) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 150 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 151 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 152 | match event { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 153 | Event::RecentHistoryChanged { state, .. } => state, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 154 | _ => unreachable!(), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 155 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 156 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 157 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 158 | async fn wait_for_settled_fill(room: &mut TestRoom) -> HistoryRepairReport { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 159 | match next_until(room, |event| { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 160 | matches!(event, Event::HistoryRepairChanged(report) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 161 | if report.phase != HistoryRepairPhase::Bridging) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 162 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 163 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 164 | { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 165 | Event::HistoryRepairChanged(report) => report, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 166 | _ => unreachable!(), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 167 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 168 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 169 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 170 | fn has_event(items: &imbl::Vector<TimelineItem>, id: &EventId) -> bool { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 171 | items.iter().any( |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 172 | |item| matches!(item, TimelineItem::Event(event) if event.event_id.as_deref() == Some(id)), |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 173 | ) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 174 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 175 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 176 | fn gap_in(items: &imbl::Vector<TimelineItem>) -> Option<HistoryGap> { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 177 | items.iter().find_map(|item| match item { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 178 | TimelineItem::HistoryGap(gap) => Some(gap.clone()), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 179 | _ => None, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 180 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 181 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 182 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 183 | #[tokio::test] |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 184 | async fn automatic_recent_load_is_bounded_and_keeps_cached_history_behind_a_gap() { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 185 | let room_id = room_id!("!recent-repair:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 186 | let old_id = event_id!("$old:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 187 | let new_ids = [ |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 188 | event_id!("$fresh-a:localhost"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 189 | event_id!("$fresh-b:localhost"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 190 | event_id!("$fresh-c:localhost"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 191 | event_id!("$fresh-d:localhost"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 192 | ]; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 193 | let mut room = start_room(room_id).await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 194 | for (index, id) in new_ids.iter().enumerate() { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 195 | let token = format!("recent-{index}"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 196 | let response = RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 197 | .end_token(token.clone()) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 198 | .events(vec![history_event(room_id, id, "recent event")]); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 199 | if index > 0 { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 200 | let previous = format!("recent-{}", index - 1); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 201 | room.server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 202 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 203 | .match_from(&previous) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 204 | .ok(response) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 205 | .mock_once() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 206 | .mount() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 207 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 208 | } else { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 209 | room.server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 210 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 211 | .ok(response) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 212 | .mock_once() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 213 | .mount() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 214 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 215 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 216 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 217 | cache_event_before_open(&room, room_id, old_id, "retained old event").await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 218 | open_room(&mut room, room_id).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 219 | timeline_until(&mut room, |items| { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 220 | gap_in(items).is_some() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 221 | && has_event(items, old_id) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 222 | && new_ids.iter().all(|id| has_event(items, id)) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 223 | }) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 224 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 225 | assert_eq!( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 226 | wait_for_recent(&mut room, room_id).await, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 227 | RecentHistoryState::Loaded |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 228 | ); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 229 | let requests = room.server.received_requests().await.unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 230 | let messages = requests |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 231 | .iter() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 232 | .filter(|request| request.url.path().ends_with("/messages")) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 233 | .collect::<Vec<_>>(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 234 | assert_eq!(messages.len(), 4); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 235 | assert!(!messages[0].url.query_pairs().any(|(key, _)| key == "from")); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 236 | shut_down(&room.handle, &mut room.events, room.running).await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 237 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 238 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 239 | #[tokio::test] |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 240 | async fn explicit_recent_start_coalesces_with_the_automatic_load() { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 241 | let room_id = room_id!("!recent-coalesce:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 242 | let fresh_id = event_id!("$coalesced:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 243 | let mut room = start_room(room_id).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 244 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 245 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 246 | .ok(RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 247 | .with_delay(Duration::from_millis(300)) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 248 | .events(vec![history_event(room_id, fresh_id, "shared result")])) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 249 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 250 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 251 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 252 | open_room(&mut room, room_id).await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 253 | tokio::time::timeout(Duration::from_secs(5), async { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 254 | loop { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 255 | let requested = room |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 256 | .server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 257 | .received_requests() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 258 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 259 | .unwrap() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 260 | .iter() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 261 | .any(|request| request.url.path().ends_with("/messages")); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 262 | if requested { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 263 | break; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 264 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 265 | tokio::task::yield_now().await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 266 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 267 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 268 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 269 | .expect("automatic recent request did not start"); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 270 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 271 | room.handle |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 272 | .retry_recent_history(room_id.to_owned()) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 273 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 274 | .unwrap(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 275 | assert_eq!( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 276 | wait_for_recent(&mut room, room_id).await, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 277 | RecentHistoryState::Loaded |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 278 | ); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 279 | let requests = room.server.received_requests().await.unwrap(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 280 | assert_eq!( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 281 | requests |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 282 | .iter() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 283 | .filter(|request| request.url.path().ends_with("/messages")) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 284 | .count(), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 285 | 1 |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 286 | ); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 287 | shut_down(&room.handle, &mut room.events, room.running).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 288 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 289 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 290 | #[cfg(feature = "mirror")] |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 291 | #[tokio::test] |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 292 | async fn fill_gap_returns_after_the_mirror_contains_the_committed_rows() { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 293 | let server = MatrixMockServer::new().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 294 | server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 295 | .mock_sliding_sync() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 296 | .ok(v5::Response::new("1".to_owned())) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 297 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 298 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 299 | let client = server.client_builder().build().await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 300 | let room_id = room_id!("!fill-gap-mirror:localhost"); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 301 | server.mock_room_state_encryption().plain().mount().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 302 | server.sync_joined_room(&client, room_id).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 303 | let sync_client = client.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 304 | let old_id = event_id!("$gap-old:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 305 | let fresh_id = event_id!("$gap-fresh:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 306 | let middle_id = event_id!("$gap-middle:localhost"); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 307 | let (engine, handle, events) = Engine::from_client( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 308 | client, |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 309 | EngineConfig::default() |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 310 | .with_initial_history_limit(0) |
74befbc72baf | atagen | 2026-10-25 11:18 UTC | 311 | .with_search_backfill_pages_per_room(0), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 312 | ) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 313 | .await |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 314 | .unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 315 | let running = tokio::spawn(engine.run()); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 316 | let (mirror, mirror_handle) = Mirror::new(handle.clone(), events); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 317 | let mirror_running = tokio::spawn(mirror.run()); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 318 | server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 319 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 320 | .ok(RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 321 | .end_token("recent-gap") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 322 | .events(vec![history_event(room_id, fresh_id, "new window")])) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 323 | .mock_once() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 324 | .mount() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 325 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 326 | server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 327 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 328 | .match_from("recent-gap") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 329 | .ok(RoomMessagesResponseTemplate::default().end_token("recent-gap")) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 330 | .mock_once() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 331 | .mount() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 332 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 333 | server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 334 | .sync_room( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 335 | &sync_client, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 336 | JoinedRoomBuilder::new(room_id).add_timeline_event( |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 337 | EventFactory::new() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 338 | .text_msg("old retained") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 339 | .event_id(old_id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 340 | .sender(&ALICE), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 341 | ), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 342 | ) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 343 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 344 | handle.open_room(room_id.to_owned()).await.unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 345 | let timeline_id = TimelineId::from(room_id.to_owned()); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 346 | let gap = tokio::time::timeout(Duration::from_secs(5), async { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 347 | loop { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 348 | if let Some(gap) = mirror_handle |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 349 | .snapshot() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 350 | .timelines |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 351 | .get(&timeline_id) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 352 | .and_then(|timeline| gap_in(&timeline.items)) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 353 | { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 354 | break gap; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 355 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 356 | tokio::task::yield_now().await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 357 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 358 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 359 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 360 | .expect("the recent history gap did not reach the mirror"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 361 | tokio::time::timeout(Duration::from_secs(5), async { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 362 | loop { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 363 | if mirror_handle.snapshot().recent_history.get(room_id) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 364 | == Some(&RecentHistoryState::Loaded) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 365 | { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 366 | break; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 367 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 368 | tokio::task::yield_now().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 369 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 370 | }) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 371 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 372 | .expect("automatic recent loading did not finish"); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 373 | server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 374 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 375 | .match_from("recent-gap") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 376 | .ok(RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 377 | .with_delay(Duration::from_millis(300)) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 378 | .events(vec![ |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 379 | history_event(room_id, middle_id, "middle page"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 380 | history_event(room_id, old_id, "old retained overlap"), |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 381 | ])) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 382 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 383 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 384 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 385 | |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 386 | let fill_handle = handle.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 387 | let target_gap_id = gap.id.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 388 | let fill_gap_id = target_gap_id.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 389 | let fill = tokio::spawn(async move { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 390 | fill_handle |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 391 | .fill_history_gap(room_id.to_owned(), fill_gap_id) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 392 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 393 | }); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 394 | tokio::time::timeout(Duration::from_secs(5), async { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 395 | loop { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 396 | let snapshot = mirror_handle.snapshot(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 397 | let active_gap = snapshot.repairs.get(room_id).is_some_and(|report| { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 398 | report.gap_id == target_gap_id && report.phase == HistoryRepairPhase::Bridging |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 399 | }); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 400 | if active_gap { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 401 | break; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 402 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 403 | tokio::task::yield_now().await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 404 | } |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 405 | }) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 406 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 407 | .expect("the active repair report did not identify its target gap"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 408 | fill.await.unwrap().unwrap(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 409 | let snapshot = mirror_handle.snapshot(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 410 | let timeline = snapshot |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 411 | .timelines |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 412 | .get(&timeline_id) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 413 | .expect("the room timeline disappeared"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 414 | let event_ids = timeline |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 415 | .items |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 416 | .iter() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 417 | .filter_map(|item| match item { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 418 | TimelineItem::Event(event) => event.event_id.as_deref(), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 419 | _ => None, |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 420 | }) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 421 | .collect::<Vec<_>>(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 422 | assert!(event_ids.contains(&fresh_id)); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 423 | assert!(event_ids.contains(&middle_id)); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 424 | assert!(event_ids.contains(&old_id)); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 425 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 426 | handle.shutdown().await.unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 427 | assert_eq!(running.await.unwrap().unwrap(), Termination::ShutDown); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 428 | mirror_running.await.unwrap(); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 429 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 430 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 431 | #[tokio::test] |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 432 | async fn cancelling_a_gap_fill_keeps_committed_progress_for_retry() { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 433 | let room_id = room_id!("!cancel-gap-fill:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 434 | let old_id = event_id!("$cancel-gap-old:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 435 | let fresh_id = event_id!("$cancel-gap-fresh:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 436 | let middle_id = event_id!("$cancel-gap-middle:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 437 | let mut room = start_room(room_id).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 438 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 439 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 440 | .ok(RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 441 | .end_token("gap-cursor-1") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 442 | .events(vec![history_event(room_id, fresh_id, "recent")])) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 443 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 444 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 445 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 446 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 447 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 448 | .match_from("gap-cursor-1") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 449 | .ok(RoomMessagesResponseTemplate::default().end_token("gap-cursor-1")) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 450 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 451 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 452 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 453 | cache_event_before_open(&room, room_id, old_id, "old cached").await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 454 | open_room(&mut room, room_id).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 455 | timeline_until(&mut room, |items| gap_in(items).is_some()).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 456 | let gap = gap_in(&room.items).unwrap(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 457 | assert_eq!( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 458 | wait_for_recent(&mut room, room_id).await, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 459 | RecentHistoryState::Loaded |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 460 | ); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 461 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 462 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 463 | .match_from("gap-cursor-1") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 464 | .ok(RoomMessagesResponseTemplate::default() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 465 | .end_token("gap-cursor-2") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 466 | .events(vec![history_event( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 467 | room_id, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 468 | middle_id, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 469 | "committed progress", |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 470 | )])) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 471 | .mock_once() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 472 | .mount() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 473 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 474 | room.server |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 475 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 476 | .match_from("gap-cursor-2") |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 477 | .ok(RoomMessagesResponseTemplate::default() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 478 | .with_delay(Duration::from_secs(5)) |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 479 | .events(vec![history_event(room_id, old_id, "old overlap")])) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 480 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 481 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 482 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 483 | let fill_handle = room.handle.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 484 | let gap_id = gap.id.clone(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 485 | let fill = tokio::spawn(async move { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 486 | fill_handle |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 487 | .fill_history_gap(room_id.to_owned(), gap_id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 488 | .await |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 489 | }); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 490 | tokio::time::timeout(Duration::from_secs(5), async { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 491 | loop { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 492 | let requested = room |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 493 | .server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 494 | .received_requests() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 495 | .await |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 496 | .unwrap() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 497 | .iter() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 498 | .any(|request| { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 499 | request.url.path().ends_with("/messages") |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 500 | && request |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 501 | .url |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 502 | .query_pairs() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 503 | .any(|(key, value)| key == "from" && value == "gap-cursor-2") |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 504 | }); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 505 | if requested { |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 506 | break; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 507 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 508 | tokio::task::yield_now().await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 509 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 510 | }) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 511 | .await |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 512 | .expect("the second gap page did not start"); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 513 | room.handle |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 514 | .cancel_history_repair(room_id.to_owned()) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 515 | .await |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 516 | .unwrap(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 517 | let error = fill.await.unwrap().unwrap_err(); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 518 | assert_eq!(error.kind, macltok::ErrorKind::Interrupted); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 519 | let report = wait_for_settled_fill(&mut room).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 520 | assert_eq!(report.stop, Some(HistoryRepairStop::Cancelled)); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 521 | assert!(report.failure.is_none()); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 522 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 523 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 524 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 525 | .match_from("gap-cursor-2") |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 526 | .ok( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 527 | RoomMessagesResponseTemplate::default().events(vec![history_event( |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 528 | room_id, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 529 | old_id, |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 530 | "old overlap", |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 531 | )]), |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 532 | ) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 533 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 534 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 535 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 536 | room.handle |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 537 | .fill_history_gap(room_id.to_owned(), gap.id) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 538 | .await |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 539 | .unwrap(); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 540 | timeline_until(&mut room, |items| { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 541 | [fresh_id, middle_id, old_id] |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 542 | .iter() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 543 | .all(|id| has_event(items, id)) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 544 | && gap_in(items).is_none() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 545 | }) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 546 | .await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 547 | shut_down(&room.handle, &mut room.events, room.running).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 548 | } |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 549 | |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 550 | #[tokio::test] |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 551 | async fn failed_automatic_recent_load_is_public_and_keeps_the_cached_timeline() { |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 552 | let room_id = room_id!("!failed-recent:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 553 | let old_id = event_id!("$failed-old:localhost"); |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 554 | let mut room = start_room(room_id).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 555 | room.server |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 556 | .mock_room_messages() |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 557 | .respond_with(ResponseTemplate::new(403).set_body_json(serde_json::json!({ |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 558 | "errcode": "M_FORBIDDEN", |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 559 | "error": "history is unavailable", |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 560 | }))) |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 561 | .mock_once() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 562 | .mount() |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 563 | .await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 564 | cache_event_before_open(&room, room_id, old_id, "kept event").await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 565 | open_room(&mut room, room_id).await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 566 | let state = wait_for_recent(&mut room, room_id).await; |
c9f0fd0ee1cc | atagen | 2026-10-25 06:16 UTC | 567 | assert!(matches!(state, RecentHistoryState::Failed(_))); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 568 | shut_down(&room.handle, &mut room.events, room.running).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 569 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 570 | |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 571 | #[tokio::test] |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 572 | async fn closing_during_a_recent_load_settles_idle_not_failed() { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 573 | let room_id = room_id!("!close-recent:localhost"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 574 | let mut room = start_room(room_id).await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 575 | room.server |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 576 | .mock_room_messages() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 577 | .ok(RoomMessagesResponseTemplate::default() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 578 | .with_delay(Duration::from_secs(5)) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 579 | .events(vec![history_event( |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 580 | room_id, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 581 | event_id!("$never:localhost"), |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 582 | "too late", |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 583 | )])) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 584 | .mock_once() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 585 | .mount() |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 586 | .await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 587 | open_room(&mut room, room_id).await; |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 588 | tokio::time::timeout(Duration::from_secs(5), async { |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 589 | while !room |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 590 | .server |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 591 | .received_requests() |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 592 | .await |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 593 | .unwrap() |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 594 | .iter() |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 595 | .any(|request| request.url.path().ends_with("/messages")) |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 596 | { |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 597 | tokio::task::yield_now().await; |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 598 | } |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 599 | }) |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 600 | .await |
002c79e4c6ec | atagen | 2026-10-25 10:42 UTC | 601 | .expect("the recent load never asked for messages"); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 602 | room.handle.close_room(room_id.to_owned()).await.unwrap(); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 603 | let mut states = Vec::new(); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 604 | next_until(&mut room, |event| { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 605 | if let Event::RecentHistoryChanged { state, .. } = event { |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 606 | states.push(state.clone()); |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 607 | } |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 608 | matches!(event, Event::TimelineClosed { timeline_id } if timeline_id.room_id() == room_id) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 609 | }) |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 610 | .await; |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 611 | assert_eq!( |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 612 | states, |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 613 | [RecentHistoryState::Loading, RecentHistoryState::Idle] |
d9b96952ec60 | atagen | 2026-10-25 09:07 UTC | 614 | ); |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 615 | shut_down(&room.handle, &mut room.events, room.running).await; |
80381e06a573 | atagen | 2026-10-25 03:02 UTC | 616 | } |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 617 | |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 618 | #[tokio::test] |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 619 | async fn a_reply_whose_target_is_not_loaded_fetches_it() { |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 620 | let room_id = room_id!("!replies:localhost"); |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 621 | let target_id = event_id!("$target:localhost"); |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 622 | let reply_id = event_id!("$reply:localhost"); |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 623 | let mut room = start_room(room_id).await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 624 | room.server |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 625 | .mock_room_messages() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 626 | .ok(RoomMessagesResponseTemplate::default()) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 627 | .mount() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 628 | .await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 629 | room.server |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 630 | .mock_room_event() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 631 | .match_event_id() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 632 | .ok(EventFactory::new() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 633 | .room(room_id) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 634 | .text_msg("target") |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 635 | .event_id(target_id) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 636 | .sender(&ALICE) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 637 | .into_event()) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 638 | .mount() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 639 | .await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 640 | room.server |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 641 | .sync_room( |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 642 | &room.sync_client, |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 643 | JoinedRoomBuilder::new(room_id).add_timeline_event( |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 644 | EventFactory::new() |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 645 | .text_msg("reply") |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 646 | .reply_to(target_id) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 647 | .event_id(reply_id) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 648 | .sender(&ALICE), |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 649 | ), |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 650 | ) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 651 | .await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 652 | open_room(&mut room, room_id).await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 653 | timeline_until(&mut room, |items| { |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 654 | items.iter().any(|item| { |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 655 | matches!(item, TimelineItem::Event(event) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 656 | if event.event_id.as_deref() == Some(reply_id) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 657 | && event.reply_to.as_ref().is_some_and(|reply| { |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 658 | matches!(reply.details, macltok::ReplyDetails::Ready { .. }) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 659 | })) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 660 | }) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 661 | }) |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 662 | .await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 663 | shut_down(&room.handle, &mut room.events, room.running).await; |
6f47f7cbe75a | atagen | 2026-10-26 02:27 UTC | 664 | } |