| 1 | use std::collections::BTreeSet; |
| 2 | use std::sync::Arc; |
| 3 | |
| 4 | use chrono::{DateTime, TimeZone, Utc}; |
| 5 | use mcp::{ |
| 6 | Access, AgentHub, AgentPolicy, Meeting, Outcome, ServerHandle, SourceError, SourceFuture, |
| 7 | TeamsSource, Transcript, TranscriptTurn, |
| 8 | }; |
| 9 | use rmcp::ServiceExt; |
| 10 | use rmcp::model::{CallToolRequestParams, ClientConfig}; |
| 11 | use rmcp::service::RunningService; |
| 12 | use rmcp::transport::StreamableHttpClientTransport; |
| 13 | use rmcp::transport::streamable_http_client::StreamableHttpClientTransportConfig; |
| 14 | use serde_json::{Value, json}; |
| 15 | use store::{ChannelRecord, ChatRecord, MessageRecord, Store, TeamRecord}; |
| 16 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
| 17 | use tokio::net::TcpStream; |
| 18 | |
| 19 | const TOKEN: &str = "test-token"; |
| 20 | const ALLOWED_CHAT: &str = "19:alpha@thread.v2"; |
| 21 | const HIDDEN_CHAT: &str = "19:beta@thread.v2"; |
| 22 | const CHANNEL: &str = "19:channel@thread.tacv2"; |
| 23 | const MEETING_CHAT: &str = "19:meeting_abc@thread.v2"; |
| 24 | const LIVE_MEETING_CHAT: &str = "19:meeting_live@thread.v2"; |
| 25 | const HIDDEN_MEETING_CHAT: &str = "19:meeting_hidden@thread.v2"; |
| 26 | |
| 27 | struct FakeSource { |
| 28 | store: Arc<Store>, |
| 29 | } |
| 30 | |
| 31 | impl TeamsSource for FakeSource { |
| 32 | fn store(&self) -> Result<Arc<Store>, SourceError> { |
| 33 | Ok(self.store.clone()) |
| 34 | } |
| 35 | |
| 36 | fn me_id(&self) -> Option<String> { |
| 37 | Some("user-me".to_owned()) |
| 38 | } |
| 39 | |
| 40 | fn calendar(&self, start: DateTime<Utc>, end: DateTime<Utc>) -> SourceFuture<'_, Vec<Meeting>> { |
| 41 | let meeting = Meeting { |
| 42 | title: "Sprint review".to_owned(), |
| 43 | start: Utc.with_ymd_and_hms(2026, 10, 7, 9, 0, 0).unwrap(), |
| 44 | end: Utc.with_ymd_and_hms(2026, 10, 7, 10, 0, 0).unwrap(), |
| 45 | all_day: false, |
| 46 | organizer: Some("Ada Example".to_owned()), |
| 47 | join_url: Some("https://teams.example/join".to_owned()), |
| 48 | meeting_chat_id: Some(MEETING_CHAT.to_owned()), |
| 49 | }; |
| 50 | Box::pin(async move { |
| 51 | Ok(vec![meeting] |
| 52 | .into_iter() |
| 53 | .filter(|meeting| meeting.start >= start && meeting.start < end) |
| 54 | .collect()) |
| 55 | }) |
| 56 | } |
| 57 | |
| 58 | fn transcript<'a>(&'a self, meeting_chat_id: &'a str) -> SourceFuture<'a, Transcript> { |
| 59 | Box::pin(async move { |
| 60 | if meeting_chat_id != MEETING_CHAT { |
| 61 | return Err(SourceError::Failed( |
| 62 | "no finished recording in this meeting chat".to_owned(), |
| 63 | )); |
| 64 | } |
| 65 | Ok(Transcript { |
| 66 | recording_name: Some("Sprint review".to_owned()), |
| 67 | created_at: None, |
| 68 | turns: vec![TranscriptTurn { |
| 69 | speaker: "Ada Example".to_owned(), |
| 70 | start_seconds: 1.0, |
| 71 | end_seconds: 4.5, |
| 72 | text: "Welcome everyone".to_owned(), |
| 73 | }], |
| 74 | }) |
| 75 | }) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | struct Harness { |
| 80 | hub: Arc<AgentHub>, |
| 81 | server: ServerHandle, |
| 82 | } |
| 83 | |
| 84 | impl Harness { |
| 85 | async fn start(propose: bool) -> Harness { |
| 86 | Harness::start_with(propose, false, false).await |
| 87 | } |
| 88 | |
| 89 | async fn start_with(propose: bool, calendar: bool, transcripts: bool) -> Harness { |
| 90 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 91 | seed(&store); |
| 92 | let policy = AgentPolicy { |
| 93 | enabled: true, |
| 94 | chats: Access::Selected(BTreeSet::from([ |
| 95 | ALLOWED_CHAT.to_owned(), |
| 96 | MEETING_CHAT.to_owned(), |
| 97 | LIVE_MEETING_CHAT.to_owned(), |
| 98 | ])), |
| 99 | channels: Access::Selected(BTreeSet::from([CHANNEL.to_owned()])), |
| 100 | propose, |
| 101 | calendar, |
| 102 | transcripts, |
| 103 | ..AgentPolicy::default() |
| 104 | }; |
| 105 | let (ui, _receiver) = tokio::sync::mpsc::unbounded_channel(); |
| 106 | let hub = AgentHub::new(store.clone(), policy, ui); |
| 107 | let server = mcp::start( |
| 108 | hub.clone(), |
| 109 | Arc::new(FakeSource { store }), |
| 110 | 0, |
| 111 | TOKEN.to_owned(), |
| 112 | ) |
| 113 | .await |
| 114 | .unwrap(); |
| 115 | Harness { hub, server } |
| 116 | } |
| 117 | |
| 118 | fn url(&self) -> String { |
| 119 | format!("http://{}/mcp", self.server.addr) |
| 120 | } |
| 121 | |
| 122 | async fn client(&self) -> RunningService<rmcp::RoleClient, ClientConfig> { |
| 123 | let transport = StreamableHttpClientTransport::from_config( |
| 124 | StreamableHttpClientTransportConfig::with_uri(self.url()).auth_header(TOKEN), |
| 125 | ); |
| 126 | ClientConfig::default().serve(transport).await.unwrap() |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | fn seed(store: &Store) { |
| 131 | let time = |minute: u32| Utc.with_ymd_and_hms(2026, 10, 6, 9, minute, 0).unwrap(); |
| 132 | let chat_of_kind = |id: &str, kind: &str, title: &str| ChatRecord { |
| 133 | id: id.to_owned(), |
| 134 | kind: kind.to_owned(), |
| 135 | title: title.to_owned(), |
| 136 | last_message_at: Some(time(5)), |
| 137 | ..ChatRecord::default() |
| 138 | }; |
| 139 | let chat = |id: &str, title: &str| chat_of_kind(id, "group", title); |
| 140 | store |
| 141 | .upsert_chats(&[ |
| 142 | chat(ALLOWED_CHAT, "Planning"), |
| 143 | chat(HIDDEN_CHAT, "Secrets"), |
| 144 | chat_of_kind(MEETING_CHAT, "meeting", "Sprint review"), |
| 145 | chat_of_kind(LIVE_MEETING_CHAT, "meeting", "Live sync"), |
| 146 | chat_of_kind(HIDDEN_MEETING_CHAT, "meeting", "Board meeting"), |
| 147 | ]) |
| 148 | .unwrap(); |
| 149 | store |
| 150 | .upsert_teams(&[TeamRecord { |
| 151 | id: "team-1".to_owned(), |
| 152 | name: "Platform".to_owned(), |
| 153 | }]) |
| 154 | .unwrap(); |
| 155 | store |
| 156 | .upsert_channels(&[ChannelRecord { |
| 157 | id: CHANNEL.to_owned(), |
| 158 | team_id: "team-1".to_owned(), |
| 159 | name: "General".to_owned(), |
| 160 | membership_type: None, |
| 161 | last_message_at: Some(time(6)), |
| 162 | unread: false, |
| 163 | }]) |
| 164 | .unwrap(); |
| 165 | let message = |
| 166 | |conversation_id: &str, message_id: &str, minute: u32, html: &str| MessageRecord { |
| 167 | conversation_id: conversation_id.to_owned(), |
| 168 | message_id: message_id.to_owned(), |
| 169 | sender_id: Some("user-ada".to_owned()), |
| 170 | sender_name: Some("Ada Example".to_owned()), |
| 171 | created_at: time(minute), |
| 172 | body_html: html.to_owned(), |
| 173 | attachments_json: "[]".to_owned(), |
| 174 | reactions_json: "[]".to_owned(), |
| 175 | mentions_json: "[]".to_owned(), |
| 176 | links_json: "[]".to_owned(), |
| 177 | ..MessageRecord::default() |
| 178 | }; |
| 179 | store |
| 180 | .upsert_messages(&[ |
| 181 | message(ALLOWED_CHAT, "m1", 1, "<p>budget <b>plan</b></p>"), |
| 182 | message(ALLOWED_CHAT, "m2", 2, "<p>lunch at noon</p>"), |
| 183 | message(HIDDEN_CHAT, "m3", 3, "<p>budget secrets</p>"), |
| 184 | message(CHANNEL, "m4", 4, "<p>budget channel post</p>"), |
| 185 | ]) |
| 186 | .unwrap(); |
| 187 | } |
| 188 | |
| 189 | async fn call( |
| 190 | client: &RunningService<rmcp::RoleClient, ClientConfig>, |
| 191 | tool: &'static str, |
| 192 | arguments: Value, |
| 193 | ) -> (bool, String) { |
| 194 | let params = CallToolRequestParams::new(tool) |
| 195 | .with_arguments(arguments.as_object().cloned().unwrap_or_default()); |
| 196 | let result = client.call_tool(params).await.unwrap(); |
| 197 | let text = result |
| 198 | .content |
| 199 | .first() |
| 200 | .and_then(|content| content.as_text()) |
| 201 | .map(|text| text.text.clone()) |
| 202 | .unwrap_or_default(); |
| 203 | (result.is_error == Some(true), text) |
| 204 | } |
| 205 | |
| 206 | async fn raw_status(addr: std::net::SocketAddr, host: &str, authorization: Option<&str>) -> u16 { |
| 207 | let mut stream = TcpStream::connect(addr).await.unwrap(); |
| 208 | let authorization = authorization |
| 209 | .map(|value| format!("Authorization: {value}\r\n")) |
| 210 | .unwrap_or_default(); |
| 211 | let request = format!( |
| 212 | "POST /mcp HTTP/1.1\r\nHost: {host}\r\n{authorization}Content-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{{}}" |
| 213 | ); |
| 214 | stream.write_all(request.as_bytes()).await.unwrap(); |
| 215 | let mut response = String::new(); |
| 216 | stream.read_to_string(&mut response).await.unwrap(); |
| 217 | response.split_whitespace().nth(1).unwrap().parse().unwrap() |
| 218 | } |
| 219 | |
| 220 | #[tokio::test] |
| 221 | async fn lists_all_eight_tools() { |
| 222 | let harness = Harness::start(true).await; |
| 223 | let client = harness.client().await; |
| 224 | let mut names: Vec<String> = client |
| 225 | .list_all_tools() |
| 226 | .await |
| 227 | .unwrap() |
| 228 | .into_iter() |
| 229 | .map(|tool| tool.name.to_string()) |
| 230 | .collect(); |
| 231 | names.sort(); |
| 232 | assert_eq!( |
| 233 | names, |
| 234 | [ |
| 235 | "get_transcript", |
| 236 | "list_channels", |
| 237 | "list_chats", |
| 238 | "list_meetings", |
| 239 | "propose_message", |
| 240 | "read_messages", |
| 241 | "search_messages", |
| 242 | "wait_for_event" |
| 243 | ] |
| 244 | ); |
| 245 | let info = client.peer_info().unwrap(); |
| 246 | assert_eq!(info.server_info.as_ref().unwrap().name, "rusty-teams"); |
| 247 | } |
| 248 | |
| 249 | #[tokio::test] |
| 250 | async fn rejects_missing_token_bad_host_and_serves_healthz() { |
| 251 | let harness = Harness::start(true).await; |
| 252 | let addr = harness.server.addr; |
| 253 | let own_host = addr.to_string(); |
| 254 | assert_eq!(raw_status(addr, &own_host, None).await, 401); |
| 255 | assert_eq!(raw_status(addr, &own_host, Some("Bearer wrong")).await, 401); |
| 256 | assert_eq!( |
| 257 | raw_status(addr, "evil.example", Some("Bearer test-token")).await, |
| 258 | 403 |
| 259 | ); |
| 260 | let authorized = raw_status(addr, &own_host, Some("Bearer test-token")).await; |
| 261 | assert!(authorized != 401 && authorized != 403, "{authorized}"); |
| 262 | |
| 263 | let mut stream = TcpStream::connect(addr).await.unwrap(); |
| 264 | stream |
| 265 | .write_all( |
| 266 | format!("GET /healthz HTTP/1.1\r\nHost: {own_host}\r\nConnection: close\r\n\r\n") |
| 267 | .as_bytes(), |
| 268 | ) |
| 269 | .await |
| 270 | .unwrap(); |
| 271 | let mut response = String::new(); |
| 272 | stream.read_to_string(&mut response).await.unwrap(); |
| 273 | assert!(response.starts_with("HTTP/1.1 200"), "{response}"); |
| 274 | assert!(response.ends_with("ok"), "{response}"); |
| 275 | } |
| 276 | |
| 277 | #[tokio::test] |
| 278 | async fn lists_only_allowed_conversations() { |
| 279 | let harness = Harness::start(true).await; |
| 280 | let client = harness.client().await; |
| 281 | let (_, chats) = call(&client, "list_chats", json!({})).await; |
| 282 | let chats: Value = serde_json::from_str(&chats).unwrap(); |
| 283 | let mut ids: Vec<&str> = chats["chats"] |
| 284 | .as_array() |
| 285 | .unwrap() |
| 286 | .iter() |
| 287 | .map(|chat| chat["id"].as_str().unwrap()) |
| 288 | .collect(); |
| 289 | ids.sort_unstable(); |
| 290 | let mut expected = vec![ALLOWED_CHAT, MEETING_CHAT, LIVE_MEETING_CHAT]; |
| 291 | expected.sort_unstable(); |
| 292 | assert_eq!(ids, expected); |
| 293 | let (_, channels) = call(&client, "list_channels", json!({})).await; |
| 294 | let channels: Value = serde_json::from_str(&channels).unwrap(); |
| 295 | assert_eq!(channels["channels"][0]["team"], "Platform"); |
| 296 | assert_eq!(channels["channels"][0]["channel"], "General"); |
| 297 | } |
| 298 | |
| 299 | #[tokio::test] |
| 300 | async fn read_messages_respects_scope_and_paging() { |
| 301 | let harness = Harness::start(true).await; |
| 302 | let client = harness.client().await; |
| 303 | let (is_error, text) = call( |
| 304 | &client, |
| 305 | "read_messages", |
| 306 | json!({"conversation_id": HIDDEN_CHAT}), |
| 307 | ) |
| 308 | .await; |
| 309 | assert!(is_error); |
| 310 | assert!( |
| 311 | text.contains("conversation not found or not allowed"), |
| 312 | "{text}" |
| 313 | ); |
| 314 | let (is_error, unknown) = call( |
| 315 | &client, |
| 316 | "read_messages", |
| 317 | json!({"conversation_id": "19:nope@thread.v2"}), |
| 318 | ) |
| 319 | .await; |
| 320 | assert!(is_error); |
| 321 | assert_eq!(unknown, text); |
| 322 | |
| 323 | let (is_error, body) = call( |
| 324 | &client, |
| 325 | "read_messages", |
| 326 | json!({"conversation_id": ALLOWED_CHAT}), |
| 327 | ) |
| 328 | .await; |
| 329 | assert!(!is_error, "{body}"); |
| 330 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 331 | assert_eq!(body["messages"][0]["text"], "budget plan"); |
| 332 | assert_eq!(body["messages"][1]["message_id"], "m2"); |
| 333 | |
| 334 | let (_, older) = call( |
| 335 | &client, |
| 336 | "read_messages", |
| 337 | json!({"conversation_id": ALLOWED_CHAT, "before_message_id": "m2"}), |
| 338 | ) |
| 339 | .await; |
| 340 | let older: Value = serde_json::from_str(&older).unwrap(); |
| 341 | assert_eq!(older["messages"].as_array().unwrap().len(), 1); |
| 342 | assert_eq!(older["messages"][0]["message_id"], "m1"); |
| 343 | } |
| 344 | |
| 345 | #[tokio::test] |
| 346 | async fn search_stays_inside_the_allowed_scope() { |
| 347 | let harness = Harness::start(true).await; |
| 348 | let client = harness.client().await; |
| 349 | let (is_error, body) = call(&client, "search_messages", json!({"query": "budget"})).await; |
| 350 | assert!(!is_error, "{body}"); |
| 351 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 352 | let mut message_ids: Vec<&str> = body["hits"] |
| 353 | .as_array() |
| 354 | .unwrap() |
| 355 | .iter() |
| 356 | .map(|hit| hit["message_id"].as_str().unwrap()) |
| 357 | .collect(); |
| 358 | message_ids.sort(); |
| 359 | assert_eq!(message_ids, ["m1", "m4"]); |
| 360 | assert!(!body.to_string().contains('\u{1}')); |
| 361 | } |
| 362 | |
| 363 | #[tokio::test] |
| 364 | async fn proposal_resolution_reaches_wait_for_event() { |
| 365 | let harness = Harness::start(true).await; |
| 366 | let client = harness.client().await; |
| 367 | let (_, start) = call(&client, "wait_for_event", json!({"timeout_seconds": 1})).await; |
| 368 | let start: Value = serde_json::from_str(&start).unwrap(); |
| 369 | let cursor = start["next"].as_u64().unwrap(); |
| 370 | |
| 371 | let (is_error, body) = call( |
| 372 | &client, |
| 373 | "propose_message", |
| 374 | json!({"conversation_id": ALLOWED_CHAT, "text": "Sounds good", "agent": "test"}), |
| 375 | ) |
| 376 | .await; |
| 377 | assert!(!is_error, "{body}"); |
| 378 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 379 | assert_eq!(body["state"], "pending"); |
| 380 | let proposal_id = body["proposal_id"].as_str().unwrap(); |
| 381 | assert!(harness.hub.resolve(proposal_id, Outcome::Sent)); |
| 382 | |
| 383 | let (_, events) = call( |
| 384 | &client, |
| 385 | "wait_for_event", |
| 386 | json!({"timeout_seconds": 5, "since": cursor}), |
| 387 | ) |
| 388 | .await; |
| 389 | let events: Value = serde_json::from_str(&events).unwrap(); |
| 390 | assert_eq!(events["events"][0]["type"], "proposal_resolved"); |
| 391 | assert_eq!(events["events"][0]["outcome"], "sent"); |
| 392 | assert_eq!(events["events"][0]["proposal_id"], proposal_id); |
| 393 | } |
| 394 | |
| 395 | #[tokio::test] |
| 396 | async fn propose_is_refused_when_turned_off_or_out_of_scope() { |
| 397 | let harness = Harness::start(false).await; |
| 398 | let client = harness.client().await; |
| 399 | let (is_error, text) = call( |
| 400 | &client, |
| 401 | "propose_message", |
| 402 | json!({"conversation_id": ALLOWED_CHAT, "text": "hi"}), |
| 403 | ) |
| 404 | .await; |
| 405 | assert!(is_error); |
| 406 | assert!(text.contains("turned off"), "{text}"); |
| 407 | |
| 408 | let (is_error, text) = call( |
| 409 | &client, |
| 410 | "propose_message", |
| 411 | json!({"conversation_id": HIDDEN_CHAT, "text": "hi"}), |
| 412 | ) |
| 413 | .await; |
| 414 | assert!(is_error); |
| 415 | assert!(text.contains("not found or not allowed"), "{text}"); |
| 416 | assert!(harness.hub.pending_proposal(ALLOWED_CHAT).is_none()); |
| 417 | } |
| 418 | |
| 419 | #[tokio::test] |
| 420 | async fn a_second_server_on_the_same_port_reports_it_clearly() { |
| 421 | let harness = Harness::start(true).await; |
| 422 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 423 | let (ui, _receiver) = tokio::sync::mpsc::unbounded_channel(); |
| 424 | let hub = AgentHub::new(store.clone(), AgentPolicy::default(), ui); |
| 425 | let result = mcp::start( |
| 426 | hub, |
| 427 | Arc::new(FakeSource { store }), |
| 428 | harness.server.addr.port(), |
| 429 | TOKEN.to_owned(), |
| 430 | ) |
| 431 | .await; |
| 432 | let error = result.err().expect("port is taken"); |
| 433 | assert!(error.to_string().contains("already in use"), "{error}"); |
| 434 | } |
| 435 | |
| 436 | #[tokio::test] |
| 437 | async fn meetings_and_transcripts_need_their_switches() { |
| 438 | let harness = Harness::start(true).await; |
| 439 | let client = harness.client().await; |
| 440 | let (is_error, text) = call(&client, "list_meetings", json!({})).await; |
| 441 | assert!(is_error); |
| 442 | assert!(text.contains("calendar access is turned off"), "{text}"); |
| 443 | let (is_error, text) = call( |
| 444 | &client, |
| 445 | "get_transcript", |
| 446 | json!({"meeting_chat_id": MEETING_CHAT}), |
| 447 | ) |
| 448 | .await; |
| 449 | assert!(is_error); |
| 450 | assert!(text.contains("transcripts are turned off"), "{text}"); |
| 451 | } |
| 452 | |
| 453 | #[tokio::test] |
| 454 | async fn list_meetings_returns_the_window() { |
| 455 | let harness = Harness::start_with(true, true, false).await; |
| 456 | let client = harness.client().await; |
| 457 | let (is_error, body) = call( |
| 458 | &client, |
| 459 | "list_meetings", |
| 460 | json!({"start": "2026-10-07T00:00:00Z", "end": "2026-10-08T00:00:00Z"}), |
| 461 | ) |
| 462 | .await; |
| 463 | assert!(!is_error, "{body}"); |
| 464 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 465 | assert_eq!(body["meetings"][0]["title"], "Sprint review"); |
| 466 | assert_eq!(body["meetings"][0]["meeting_chat_id"], MEETING_CHAT); |
| 467 | |
| 468 | let (_, empty) = call( |
| 469 | &client, |
| 470 | "list_meetings", |
| 471 | json!({"start": "2026-10-09T00:00:00Z", "end": "2026-10-10T00:00:00Z"}), |
| 472 | ) |
| 473 | .await; |
| 474 | let empty: Value = serde_json::from_str(&empty).unwrap(); |
| 475 | assert!(empty["meetings"].as_array().unwrap().is_empty()); |
| 476 | |
| 477 | let (is_error, text) = call( |
| 478 | &client, |
| 479 | "list_meetings", |
| 480 | json!({"start": "2026-10-09T00:00:00Z", "end": "2026-10-08T00:00:00Z"}), |
| 481 | ) |
| 482 | .await; |
| 483 | assert!(is_error); |
| 484 | assert!(text.contains("end must be after start"), "{text}"); |
| 485 | } |
| 486 | |
| 487 | #[tokio::test] |
| 488 | async fn get_transcript_returns_turns_and_live_captions() { |
| 489 | let harness = Harness::start_with(true, false, true).await; |
| 490 | let client = harness.client().await; |
| 491 | let (is_error, body) = call( |
| 492 | &client, |
| 493 | "get_transcript", |
| 494 | json!({"meeting_chat_id": MEETING_CHAT}), |
| 495 | ) |
| 496 | .await; |
| 497 | assert!(!is_error, "{body}"); |
| 498 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 499 | assert_eq!(body["turns"][0]["text"], "Welcome everyone"); |
| 500 | assert!(body["live_captions"].as_array().unwrap().is_empty()); |
| 501 | |
| 502 | let (is_error, text) = call( |
| 503 | &client, |
| 504 | "get_transcript", |
| 505 | json!({"meeting_chat_id": HIDDEN_MEETING_CHAT}), |
| 506 | ) |
| 507 | .await; |
| 508 | assert!(is_error); |
| 509 | assert!(text.contains("not found or not allowed"), "{text}"); |
| 510 | |
| 511 | let live_chat = LIVE_MEETING_CHAT; |
| 512 | let (is_error, text) = call( |
| 513 | &client, |
| 514 | "get_transcript", |
| 515 | json!({"meeting_chat_id": live_chat}), |
| 516 | ) |
| 517 | .await; |
| 518 | assert!(is_error); |
| 519 | assert!(text.contains("no finished recording"), "{text}"); |
| 520 | |
| 521 | harness.hub.push_caption(live_chat, "1", "Bo", "Hi all"); |
| 522 | let (is_error, body) = call( |
| 523 | &client, |
| 524 | "get_transcript", |
| 525 | json!({"meeting_chat_id": live_chat}), |
| 526 | ) |
| 527 | .await; |
| 528 | assert!(!is_error, "{body}"); |
| 529 | let body: Value = serde_json::from_str(&body).unwrap(); |
| 530 | assert!(body["turns"].as_array().unwrap().is_empty()); |
| 531 | assert_eq!(body["live_captions"][0]["speaker"], "Bo"); |
| 532 | assert_eq!(body["live_captions"][0]["text"], "Hi all"); |
| 533 | } |
| 534 | |
| 535 | #[tokio::test] |
| 536 | async fn propose_rejects_a_reply_target_from_another_conversation() { |
| 537 | let harness = Harness::start(true).await; |
| 538 | let client = harness.client().await; |
| 539 | let (is_error, text) = call( |
| 540 | &client, |
| 541 | "propose_message", |
| 542 | json!({"conversation_id": ALLOWED_CHAT, "text": "ok", "reply_to_message_id": "m3"}), |
| 543 | ) |
| 544 | .await; |
| 545 | assert!(is_error); |
| 546 | assert!(text.contains("is not a message of this conversation"), "{text}"); |
| 547 | let (is_error, body) = call( |
| 548 | &client, |
| 549 | "propose_message", |
| 550 | json!({"conversation_id": ALLOWED_CHAT, "text": "ok", "reply_to_message_id": "m1"}), |
| 551 | ) |
| 552 | .await; |
| 553 | assert!(!is_error, "{body}"); |
| 554 | } |