cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 1 | use std::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 2 | sync::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 3 | Arc, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 4 | atomic::{AtomicUsize, Ordering}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 5 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 6 | time::Duration, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 7 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 8 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 9 | use matrix_sdk::ruma::events::room::MediaSource; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 10 | use matrix_sdk::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 11 | ruma::{event_id, events::Mentions, push::Ruleset, room_id, user_id}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 12 | test_utils::mocks::MatrixMockServer, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 13 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 14 | use matrix_sdk_test::{JoinedRoomBuilder, event_factory::EventFactory}; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 15 | use rusqlite::Connection; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 16 | use serde_json::json; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 17 | use wiremock::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 18 | Mock, ResponseTemplate, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 19 | matchers::{method, path, query_param, query_param_is_missing}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 20 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 21 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 22 | use super::super::store::{Account, MentionsStore}; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 23 | use super::*; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 24 | use crate::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 25 | MediaId, MediaKind, StoreConfig, TimelineContent, TimelineItem, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 26 | normalise::{MediaRegistration, MediaSourceInfo}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 27 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 28 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 29 | static STORES: AtomicUsize = AtomicUsize::new(0); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 30 | const MAX_BYTES: usize = 64 * 1024 * 1024; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 31 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 32 | fn config() -> StoreConfig { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 33 | let number = STORES.fetch_add(1, Ordering::Relaxed); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 34 | StoreConfig::sqlite( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 35 | std::env::temp_dir().join(format!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 36 | "macltok-mentions-service-{}-{number}", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 37 | std::process::id() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 38 | )), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 39 | "service commit test passphrase", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 40 | ) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 41 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 42 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 43 | fn account(client: &Client) -> Account { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 44 | Account { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 45 | homeserver: client.homeserver().to_string(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 46 | user_id: client.user_id().unwrap().to_owned(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 47 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 48 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 49 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 50 | async fn joined_client( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 51 | server: &MatrixMockServer, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 52 | room_id: &ruma::RoomId, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 53 | ) -> (Client, ruma::OwnedUserId) { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 54 | let client = server.client_builder().build().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 55 | let own_user = client.user_id().unwrap().to_owned(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 56 | let room_id = room_id.to_owned(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 57 | server |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 58 | .mock_sync() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 59 | .ok_and_run(&client, { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 60 | let own_user = own_user.clone(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 61 | move |builder| { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 62 | let factory = EventFactory::new().room(&room_id); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 63 | builder.add_global_account_data( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 64 | factory.push_rules(Ruleset::server_default(&own_user)), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 65 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 66 | builder.add_joined_room( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 67 | JoinedRoomBuilder::new(&room_id).add_state_event(factory.member(&own_user)), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 68 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 69 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 70 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 71 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 72 | (client, own_user) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 73 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 74 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 75 | #[tokio::test] |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 76 | async fn failed_batch_keeps_inbox_and_checkpoint_at_the_same_commit_boundary() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 77 | let server = MatrixMockServer::new().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 78 | let room_id = room_id!("!mentions:localhost"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 79 | let (client, own_user) = joined_client(&server, room_id).await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 80 | let event = EventFactory::new() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 81 | .room(room_id) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 82 | .text_msg("commit boundary") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 83 | .mentions(Mentions::with_user_ids([own_user.clone()])) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 84 | .event_id(event_id!("$commit-boundary:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 85 | .sender(user_id!("@bob:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 86 | .into_raw_sync(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 87 | let raw_room = serde_json::from_value(json!({ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 88 | "initial": true, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 89 | "timeline": [serde_json::to_value(event).unwrap()], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 90 | })) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 91 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 92 | let batch = ResponseCommitBatch { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 93 | connection_id: "mentions-connection".to_owned(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 94 | previous_pos: None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 95 | next_pos: "mentions-position-1".to_owned(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 96 | response: Default::default(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 97 | raw_rooms: [(room_id.to_owned(), raw_room)].into(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 98 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 99 | let config = config(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 100 | let store = MentionsStore::open(&config, account(&client), MAX_BYTES) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 101 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 102 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 103 | let media = Arc::new(MediaService::new( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 104 | client.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 105 | EngineConfig::default().max_media_bytes, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 106 | EngineConfig::default().max_media_sources, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 107 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 108 | let (_handle, mut service, updates) = |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 109 | Service::new(client, media, Some(store), EngineConfig::default()) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 110 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 111 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 112 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 113 | let connection = Connection::open(config.mentions_location()).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 114 | connection |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 115 | .execute_batch( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 116 | "CREATE TRIGGER fail_mentions_inbox_insert BEFORE INSERT ON records WHEN NEW.key NOT IN ('!cipher', '!head') BEGIN SELECT RAISE(ABORT, 'injected inbox write failure'); END; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 117 | CREATE TRIGGER fail_mentions_inbox_update BEFORE UPDATE ON records WHEN OLD.key NOT IN ('!cipher', '!head') BEGIN SELECT RAISE(ABORT, 'injected inbox write failure'); END;", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 118 | ) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 119 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 120 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 121 | assert!(service.batch(batch.clone()).await.is_err()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 122 | assert_eq!(service.data.revision, 0); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 123 | assert!(service.data.entries.is_empty()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 124 | assert!(service.data.checkpoints.is_empty()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 125 | assert_eq!(updates.borrow().revision, 0); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 126 | assert!(updates.borrow().entries.is_empty()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 127 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 128 | let reopened = MentionsStore::open(&config, account(&service.client), MAX_BYTES) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 129 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 130 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 131 | assert_eq!(reopened.revision(), 0); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 132 | assert!(reopened.read::<Data>("inbox").unwrap().is_none()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 133 | drop(reopened); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 134 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 135 | connection |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 136 | .execute_batch( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 137 | "DROP TRIGGER fail_mentions_inbox_insert; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 138 | DROP TRIGGER fail_mentions_inbox_update;", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 139 | ) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 140 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 141 | drop(connection); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 142 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 143 | service.batch(batch.clone()).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 144 | assert_eq!(service.data.revision, 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 145 | assert_eq!(service.data.entries.len(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 146 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 147 | service.data.checkpoints.get("mentions-connection"), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 148 | Some(&batch.next_pos) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 149 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 150 | assert_eq!(updates.borrow().revision, 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 151 | assert_eq!(updates.borrow().entries.len(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 152 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 153 | let reopened = MentionsStore::open(&config, account(&service.client), MAX_BYTES) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 154 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 155 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 156 | let persisted: Data = reopened.read("inbox").unwrap().unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 157 | assert_eq!(reopened.revision(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 158 | assert_eq!(persisted.revision, 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 159 | assert_eq!(persisted.entries.len(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 160 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 161 | persisted.checkpoints.get("mentions-connection"), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 162 | Some(&batch.next_pos) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 163 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 164 | drop(reopened); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 165 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 166 | service.batch(batch).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 167 | assert_eq!(service.data.revision, 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 168 | assert_eq!(service.store.as_ref().unwrap().revision(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 169 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 170 | drop(service); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 171 | config.delete().await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 172 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 173 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 174 | #[tokio::test] |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 175 | async fn service_recovers_notification_history_into_durable_unread_inbox() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 176 | let server = MatrixMockServer::new().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 177 | let room_id = room_id!("!mentions:localhost"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 178 | let (client, own_user) = joined_client(&server, room_id).await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 179 | let first = EventFactory::new() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 180 | .room(room_id) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 181 | .text_msg("history mention one") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 182 | .mentions(Mentions::with_user_ids([own_user.clone()])) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 183 | .event_id(event_id!("$history-one:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 184 | .sender(user_id!("@bob:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 185 | .into_raw_sync(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 186 | let second = EventFactory::new() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 187 | .room(room_id) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 188 | .text_msg("history mention two") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 189 | .mentions(Mentions::with_user_ids([own_user])) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 190 | .event_id(event_id!("$history-two:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 191 | .sender(user_id!("@bob:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 192 | .into_raw_sync(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 193 | let first = serde_json::from_str::<serde_json::Value>(first.json().get()).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 194 | let second = serde_json::from_str::<serde_json::Value>(second.json().get()).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 195 | Mock::given(method("GET")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 196 | .and(path("/_matrix/client/v3/notifications")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 197 | .and(query_param_is_missing("from")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 198 | .and(query_param("limit", "50")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 199 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 200 | "notifications": [{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 201 | "actions": ["notify"], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 202 | "event": first, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 203 | "read": true, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 204 | "room_id": room_id.as_str(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 205 | "ts": 1, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 206 | }], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 207 | "next_token": "history-page-two", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 208 | }))) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 209 | .mount(server.server()) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 210 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 211 | Mock::given(method("GET")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 212 | .and(path("/_matrix/client/v3/notifications")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 213 | .and(query_param("from", "history-page-two")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 214 | .and(query_param("limit", "50")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 215 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 216 | "notifications": [{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 217 | "actions": ["notify"], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 218 | "event": second, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 219 | "read": true, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 220 | "room_id": room_id.as_str(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 221 | "ts": 2, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 222 | }], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 223 | }))) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 224 | .mount(server.server()) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 225 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 226 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 227 | let config = config(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 228 | let store = MentionsStore::open(&config, account(&client), MAX_BYTES) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 229 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 230 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 231 | let media = Arc::new(MediaService::new( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 232 | client.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 233 | EngineConfig::default().max_media_bytes, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 234 | EngineConfig::default().max_media_sources, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 235 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 236 | let (handle, service, mut updates) = |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 237 | Service::new(client.clone(), media, Some(store), EngineConfig::default()) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 238 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 239 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 240 | let service_task = tokio::spawn(service.run()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 241 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 242 | let discovered = tokio::time::timeout(Duration::from_secs(10), async { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 243 | loop { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 244 | let page = updates.borrow_and_update().clone(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 245 | if page.entries.len() == 2 && !page.coverage.recovering { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 246 | break page; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 247 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 248 | updates.changed().await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 249 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 250 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 251 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 252 | handle.stop().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 253 | service_task.await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 254 | let discovered = discovered.expect("notification history should be recovered"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 255 | assert_eq!(discovered.entries.len(), 2); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 256 | assert!(discovered.entries.iter().all(|entry| !entry.read)); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 257 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 258 | let reopened = MentionsStore::open(&config, account(&client), MAX_BYTES) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 259 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 260 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 261 | let persisted: Data = reopened.read("inbox").unwrap().unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 262 | assert_eq!(reopened.revision(), persisted.revision); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 263 | assert_eq!(persisted.entries.len(), 2); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 264 | assert!(persisted.entries.values().all(|entry| !entry.read)); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 265 | assert!(persisted.latest_cursor.is_none()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 266 | assert!(persisted.history_cursor.is_none()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 267 | drop(reopened); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 268 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 269 | config.delete().await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 270 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 271 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 272 | fn message_body(item: &TimelineItem) -> Option<&str> { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 273 | match item { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 274 | TimelineItem::Event(event) => match &event.content { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 275 | TimelineContent::Message(message) => Some(&message.body), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 276 | _ => None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 277 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 278 | _ => None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 279 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 280 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 281 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 282 | fn media_registration() -> MediaRegistration { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 283 | MediaRegistration { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 284 | id: MediaId::new("test-scope#image".to_owned()), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 285 | kind: MediaKind::Image, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 286 | full: MediaSourceInfo { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 287 | source: MediaSource::Plain(ruma::mxc_uri!("mxc://mentions.example/image").to_owned()), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 288 | mimetype: Some("image/png".to_owned()), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 289 | declared_size: Some(1234), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 290 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 291 | thumbnail: None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 292 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 293 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 294 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 295 | #[tokio::test] |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 296 | async fn live_context_survives_capture_then_edit_and_redaction() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 297 | let server = MatrixMockServer::new().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 298 | let room_id = room_id!("!mentions:localhost"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 299 | let (client, own_user) = joined_client(&server, room_id).await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 300 | let mention = EventFactory::new() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 301 | .room(room_id) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 302 | .text_msg("direct mention") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 303 | .mentions(Mentions::with_user_ids([own_user])) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 304 | .event_id(event_id!("$live-mention:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 305 | .sender(user_id!("@bob:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 306 | .into_raw_sync(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 307 | let mut mention: serde_json::Value = serde_json::from_str(mention.json().get()).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 308 | mention["origin_server_ts"] = json!(10); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 309 | let following = EventFactory::new() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 310 | .room(room_id) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 311 | .text_msg("following") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 312 | .event_id(event_id!("$live-following:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 313 | .sender(user_id!("@bob:localhost")) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 314 | .into_raw_sync(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 315 | let mut following: serde_json::Value = serde_json::from_str(following.json().get()).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 316 | following["origin_server_ts"] = json!(11); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 317 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 318 | let media = Arc::new(MediaService::new( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 319 | client.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 320 | EngineConfig::default().max_media_bytes, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 321 | EngineConfig::default().max_media_sources, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 322 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 323 | let (_handle, mut service, _updates) = |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 324 | Service::new(client, media, None, EngineConfig::default()) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 325 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 326 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 327 | let room_id = room_id.to_owned(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 328 | let mention_key = MentionKey { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 329 | room_id: room_id.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 330 | event_id: event_id!("$live-mention:localhost").to_owned(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 331 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 332 | let following_id = format!("{room_id}\n$live-following:localhost"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 333 | let mut data = Data::default(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 334 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 335 | service.observe(&mut data, &room_id, mention).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 336 | service |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 337 | .observe(&mut data, &room_id, following) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 338 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 339 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 340 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 341 | let mention_identity = id(&mention_key); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 342 | let entry = data.entries.get(&mention_identity).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 343 | let revision = entry.revision; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 344 | let target = entry.event.clone(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 345 | service.captured( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 346 | &mut data, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 347 | mention_identity.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 348 | revision, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 349 | Ok(( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 350 | crate::EventContext { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 351 | events_before: Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 352 | event: Some(target), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 353 | events_after: Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 354 | start_token: None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 355 | end_token: None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 356 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 357 | Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 358 | Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 359 | )), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 360 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 361 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 362 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 363 | data.entries[&mention_identity].capture, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 364 | MentionCaptureState::Partial |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 365 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 366 | assert!(data.events.contains_key(&following_id)); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 367 | let (saved, _) = data.context(&mention_key).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 368 | let context = saved.context.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 369 | assert_eq!(context.events_after.len(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 370 | assert_eq!(message_body(&context.events_after[0]), Some("following")); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 371 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 372 | let edit = json!({ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 373 | "content": { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 374 | "body": "* edited following", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 375 | "m.new_content": {"body": "edited following", "msgtype": "m.text"}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 376 | "m.relates_to": {"event_id": "$live-following:localhost", "rel_type": "m.replace"}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 377 | "msgtype": "m.text" |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 378 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 379 | "event_id": "$live-following-edit:localhost", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 380 | "origin_server_ts": 12, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 381 | "room_id": room_id.as_str(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 382 | "sender": "@bob:localhost", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 383 | "type": "m.room.message" |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 384 | }); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 385 | service.observe(&mut data, &room_id, edit).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 386 | let (saved, _) = data.context(&mention_key).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 387 | let context = saved.context.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 388 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 389 | message_body(&context.events_after[0]), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 390 | Some("edited following") |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 391 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 392 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 393 | let saved_following = data.events.get_mut(&following_id).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 394 | assert!(saved_following.raw.is_some()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 395 | saved_following.media.push(media_registration()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 396 | assert_eq!(saved_following.media.len(), 1); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 397 | let redaction = json!({ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 398 | "content": {}, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 399 | "event_id": "$live-following-redaction:localhost", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 400 | "origin_server_ts": 13, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 401 | "redacts": "$live-following:localhost", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 402 | "room_id": room_id.as_str(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 403 | "sender": "@bob:localhost", |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 404 | "type": "m.room.redaction" |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 405 | }); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 406 | service |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 407 | .observe(&mut data, &room_id, redaction) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 408 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 409 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 410 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 411 | let saved_following = data.events.get(&following_id).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 412 | assert!(matches!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 413 | &saved_following.item, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 414 | TimelineItem::Event(event) if event.content == TimelineContent::Redacted |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 415 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 416 | assert!(saved_following.raw.is_none()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 417 | assert!(saved_following.media.is_empty()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 418 | let (saved, _) = data.context(&mention_key).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 419 | let context = saved.context.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 420 | assert!(matches!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 421 | &context.events_after[0], |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 422 | TimelineItem::Event(event) if event.content == TimelineContent::Redacted |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 423 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 424 | data.windows.remove(&mention_identity); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 425 | service.data = data; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 426 | let CommandOutput::MentionContext(context) = service |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 427 | .command(MentionsCommand::RetryContext(mention_key)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 428 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 429 | .unwrap() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 430 | else { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 431 | panic!("retry should return saved context"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 432 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 433 | assert_eq!(context.state, MentionCaptureState::Pending); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 434 | assert!(context.context.unwrap().event.is_some()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 435 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 436 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 437 | #[tokio::test] |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 438 | async fn explicit_recovery_rechecks_server_support() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 439 | let server = MatrixMockServer::new().await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 440 | let (client, _) = joined_client(&server, room_id!("!mentions:localhost")).await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 441 | let config = EngineConfig::default(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 442 | let media = Arc::new(MediaService::new( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 443 | client.clone(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 444 | config.max_media_bytes, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 445 | config.max_media_sources, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 446 | )); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 447 | let (_, mut service, _) = Service::new(client, media, None, config).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 448 | service.data.coverage.historical_supported = Some(false); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 449 | service.recovery_budget = 0; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 450 | service.command(MentionsCommand::Recover).await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 451 | assert_eq!(service.data.coverage.historical_supported, None); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 452 | assert!(service.data.coverage.recovering); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 453 | assert_eq!(service.recovery_budget, 20); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 454 | } |