BlueGit

ict rusty-teams

fix(mcp): review findings - token restart, transcript allowlist, stale only for newer own messages, reply target check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-12 · 7 weeks ago

Hash
9d5e4305e72d885913728cbd9d21dbf9bbe8ca88
Parent
75ec82be
6 files changed +119 −35
README.md +7 −0
@@ -66,6 +66,12 @@
66 66 - Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer
67 67 - Organizer controls: lobby banner with Admit and Deny, tile menu (pin, spotlight, mute, remove), Mute all, live captions overlay, camera background blur
68 68
69 **Agents (MCP)**
70 - Local MCP server at `http://127.0.0.1:47615/mcp`, off by default: Settings > MCP
71 - Agents read allowed chats, channels, meetings and transcripts, and propose replies
72 - A proposal shows as a card above the composer: Send, Edit or Discard. Agents never send
73 - One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`
74
69 75 **App**
70 76 - Dark theme, opens instantly from the cache
71 77 - Self-update from an update folder
@@ -108,6 +114,7 @@ It signs you in through a real Teams web page and lets that page make the API ca
108 114 | graph Microsoft Graph: chats, channels, messages, people, sending |
109 115 | chatsvc Teams chat service: realtime, pins, folders, read receipts |
110 116 | session runs requests inside the Teams page, one Transport trait |
117 | mcp local MCP server for agents, permissions, config install |
111 118 +------------------------------------|-------------------------------------+
112 119 | DevTools protocol (CDP)
113 120 +------------------------------------v-------------------------------------+
@@ -66,6 +66,12 @@
66- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer
66- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer
67- Organizer controls: lobby banner with Admit and Deny, tile menu (pin, spotlight, mute, remove), Mute all, live captions overlay, camera background blur
67- Organizer controls: lobby banner with Admit and Deny, tile menu (pin, spotlight, mute, remove), Mute all, live captions overlay, camera background blur
68
68
69**Agents (MCP)**
70- Local MCP server at `http://127.0.0.1:47615/mcp`, off by default: Settings > MCP
71- Agents read allowed chats, channels, meetings and transcripts, and propose replies
72- A proposal shows as a card above the composer: Send, Edit or Discard. Agents never send
73- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`
74
69**App**
75**App**
70- Dark theme, opens instantly from the cache
76- Dark theme, opens instantly from the cache
71- Self-update from an update folder
77- Self-update from an update folder
@@ -108,6 +114,7 @@ It signs you in through a real Teams web page and lets that page make the API ca
108| graph Microsoft Graph: chats, channels, messages, people, sending |
114| graph Microsoft Graph: chats, channels, messages, people, sending |
109| chatsvc Teams chat service: realtime, pins, folders, read receipts |
115| chatsvc Teams chat service: realtime, pins, folders, read receipts |
110| session runs requests inside the Teams page, one Transport trait |
116| session runs requests inside the Teams page, one Transport trait |
117| mcp local MCP server for agents, permissions, config install |
111+------------------------------------|-------------------------------------+
118+------------------------------------|-------------------------------------+
112 | DevTools protocol (CDP)
119 | DevTools protocol (CDP)
113+------------------------------------v-------------------------------------+
120+------------------------------------v-------------------------------------+
crates/app/src/agent_api/bridge.rs +30 −22
@@ -14,6 +14,7 @@ use crate::runtime;
14 14
15 15 const PREVIEW_CHARACTERS: usize = 200;
16 16 const NEW_MESSAGE_BATCH: usize = 50;
17 const CLOCK_SKEW_ALLOWANCE: chrono::TimeDelta = chrono::TimeDelta::minutes(2);
17 18
18 19 pub fn drain_ui_events(
19 20 mut receiver: UnboundedReceiver<UiEvent>,
@@ -62,7 +63,7 @@ pub fn apply(proposals: &mut HashMap<String, ProposalEntry>, event: UiEvent) {
62 63 }
63 64
64 65 pub fn spawn_message_bridge(engine: Arc<Engine>, hub: Arc<AgentHub>, source: Arc<AppSource>) {
65 let started_at = Utc::now();
66 let started_at = Utc::now() - CLOCK_SKEW_ALLOWANCE;
66 67 drop(runtime::spawn(async move {
67 68 let mut receiver = engine.subscribe();
68 69 let mut watermarks: HashMap<String, DateTime<Utc>> = HashMap::new();
@@ -78,29 +79,36 @@ pub fn spawn_message_bridge(engine: Arc<Engine>, hub: Arc<AgentHub>, source: Arc
78 79 let watermark = watermarks
79 80 .entry(conversation_id.clone())
80 81 .or_insert(started_at);
81 let Ok(messages) =
82 store.messages_after(&conversation_id, *watermark, NEW_MESSAGE_BATCH)
83 else {
84 continue;
85 };
86 82 let my_id = mcp::TeamsSource::me_id(source.as_ref());
87 for message in messages {
88 *watermark = (*watermark).max(message.created_at);
89 if message.deleted {
90 continue;
83 loop {
84 let Ok(messages) =
85 store.messages_after(&conversation_id, *watermark, NEW_MESSAGE_BATCH)
86 else {
87 break;
88 };
89 let batch_full = messages.len() == NEW_MESSAGE_BATCH;
90 for message in messages {
91 *watermark = (*watermark).max(message.created_at);
92 if message.deleted {
93 continue;
94 }
95 let sender_is_me = my_id.is_some() && message.sender_id == my_id;
96 let preview: String = store::plain_text(&message.body_html)
97 .chars()
98 .take(PREVIEW_CHARACTERS)
99 .collect();
100 hub.message_arrived(
101 &conversation_id,
102 &message.message_id,
103 sender_is_me,
104 message.created_at,
105 message.sender_name,
106 &preview,
107 );
108 }
109 if !batch_full {
110 break;
91 111 }
92 let sender_is_me = my_id.is_some() && message.sender_id == my_id;
93 let preview: String = store::plain_text(&message.body_html)
94 .chars()
95 .take(PREVIEW_CHARACTERS)
96 .collect();
97 hub.message_arrived(
98 &conversation_id,
99 &message.message_id,
100 sender_is_me,
101 message.sender_name,
102 &preview,
103 );
104 112 }
105 113 }
106 114 }));
@@ -14,6 +14,7 @@ use crate::runtime;
14
14
15const PREVIEW_CHARACTERS: usize = 200;
15const PREVIEW_CHARACTERS: usize = 200;
16const NEW_MESSAGE_BATCH: usize = 50;
16const NEW_MESSAGE_BATCH: usize = 50;
17const CLOCK_SKEW_ALLOWANCE: chrono::TimeDelta = chrono::TimeDelta::minutes(2);
17
18
18pub fn drain_ui_events(
19pub fn drain_ui_events(
19 mut receiver: UnboundedReceiver<UiEvent>,
20 mut receiver: UnboundedReceiver<UiEvent>,
@@ -62,7 +63,7 @@ pub fn apply(proposals: &mut HashMap<String, ProposalEntry>, event: UiEvent) {
62}
63}
63
64
64pub fn spawn_message_bridge(engine: Arc<Engine>, hub: Arc<AgentHub>, source: Arc<AppSource>) {
65pub fn spawn_message_bridge(engine: Arc<Engine>, hub: Arc<AgentHub>, source: Arc<AppSource>) {
65 let started_at = Utc::now();
66 let started_at = Utc::now() - CLOCK_SKEW_ALLOWANCE;
66 drop(runtime::spawn(async move {
67 drop(runtime::spawn(async move {
67 let mut receiver = engine.subscribe();
68 let mut receiver = engine.subscribe();
68 let mut watermarks: HashMap<String, DateTime<Utc>> = HashMap::new();
69 let mut watermarks: HashMap<String, DateTime<Utc>> = HashMap::new();
@@ -78,29 +79,36 @@ pub fn spawn_message_bridge(engine: Arc<Engine>, hub: Arc<AgentHub>, source: Arc
78 let watermark = watermarks
79 let watermark = watermarks
79 .entry(conversation_id.clone())
80 .entry(conversation_id.clone())
80 .or_insert(started_at);
81 .or_insert(started_at);
81 let Ok(messages) =
82 store.messages_after(&conversation_id, *watermark, NEW_MESSAGE_BATCH)
83 else {
84 continue;
85 };
86 let my_id = mcp::TeamsSource::me_id(source.as_ref());
82 let my_id = mcp::TeamsSource::me_id(source.as_ref());
87 for message in messages {
83 loop {
88 *watermark = (*watermark).max(message.created_at);
84 let Ok(messages) =
89 if message.deleted {
85 store.messages_after(&conversation_id, *watermark, NEW_MESSAGE_BATCH)
90 continue;
86 else {
87 break;
88 };
89 let batch_full = messages.len() == NEW_MESSAGE_BATCH;
90 for message in messages {
91 *watermark = (*watermark).max(message.created_at);
92 if message.deleted {
93 continue;
94 }
95 let sender_is_me = my_id.is_some() && message.sender_id == my_id;
96 let preview: String = store::plain_text(&message.body_html)
97 .chars()
98 .take(PREVIEW_CHARACTERS)
99 .collect();
100 hub.message_arrived(
101 &conversation_id,
102 &message.message_id,
103 sender_is_me,
104 message.created_at,
105 message.sender_name,
106 &preview,
107 );
108 }
109 if !batch_full {
110 break;
91 }
111 }
92 let sender_is_me = my_id.is_some() && message.sender_id == my_id;
93 let preview: String = store::plain_text(&message.body_html)
94 .chars()
95 .take(PREVIEW_CHARACTERS)
96 .collect();
97 hub.message_arrived(
98 &conversation_id,
99 &message.message_id,
100 sender_is_me,
101 message.sender_name,
102 &preview,
103 );
104 }
112 }
105 }
113 }
106 }));
114 }));
crates/app/src/agent_api/mod.rs +1 −1
@@ -265,7 +265,7 @@ impl AgentApi {
265 265 if let Ok(token) = mcp::regenerate_token(&self.store) {
266 266 self.token = token;
267 267 self.reinstall_agent_configs(cx);
268 if self.server.is_some() {
268 if self.hub.policy().enabled {
269 269 self.start_server(cx);
270 270 }
271 271 cx.notify();
@@ -265,7 +265,7 @@ impl AgentApi {
265 if let Ok(token) = mcp::regenerate_token(&self.store) {
265 if let Ok(token) = mcp::regenerate_token(&self.store) {
266 self.token = token;
266 self.token = token;
267 self.reinstall_agent_configs(cx);
267 self.reinstall_agent_configs(cx);
268 if self.server.is_some() {
268 if self.hub.policy().enabled {
269 self.start_server(cx);
269 self.start_server(cx);
270 }
270 }
271 cx.notify();
271 cx.notify();
crates/mcp/src/hub.rs +10 −4
@@ -273,11 +273,17 @@ impl AgentHub {
273 273 conversation_id: &str,
274 274 message_id: &str,
275 275 sender_is_me: bool,
276 created_at: DateTime<Utc>,
276 277 sender: Option<String>,
277 278 preview: &str,
278 279 ) {
279 280 if sender_is_me {
280 self.stale_pending(conversation_id);
281 let answers_pending = self
282 .pending_proposal(conversation_id)
283 .is_some_and(|proposal| created_at >= proposal.created_at);
284 if answers_pending {
285 self.stale_pending(conversation_id);
286 }
281 287 return;
282 288 }
283 289 self.push(EventKind::NewMessage {
@@ -466,9 +472,9 @@ mod tests {
466 472 assert!(hub.pending_proposal("c1").is_none());
467 473 assert_eq!(ui.try_recv().unwrap(), UiEvent::ProposalStale(stale));
468 474 propose(&hub, "c2", "yo");
469 hub.message_arrived("c2", "m1", false, None, "other");
475 hub.message_arrived("c2", "m1", false, Utc::now(), None, "other");
470 476 assert!(hub.pending_proposal("c2").is_some());
471 hub.message_arrived("c2", "m2", true, None, "mine");
477 hub.message_arrived("c2", "m2", true, Utc::now(), None, "mine");
472 478 assert!(hub.pending_proposal("c2").is_none());
473 479 }
474 480
@@ -521,7 +527,7 @@ mod tests {
521 527 tokio::spawn(async move { hub.wait_events(None, Duration::from_secs(5)).await })
522 528 };
523 529 tokio::time::sleep(Duration::from_millis(20)).await;
524 hub.message_arrived("c1", "m1", false, Some("Ada".to_owned()), "hello");
530 hub.message_arrived("c1", "m1", false, Utc::now(), Some("Ada".to_owned()), "hello");
525 531 let (events, next) = waiter.await.unwrap();
526 532 assert_eq!(events.len(), 1);
527 533 assert_eq!(next, events[0].seq);
@@ -273,11 +273,17 @@ impl AgentHub {
273 conversation_id: &str,
273 conversation_id: &str,
274 message_id: &str,
274 message_id: &str,
275 sender_is_me: bool,
275 sender_is_me: bool,
276 created_at: DateTime<Utc>,
276 sender: Option<String>,
277 sender: Option<String>,
277 preview: &str,
278 preview: &str,
278 ) {
279 ) {
279 if sender_is_me {
280 if sender_is_me {
280 self.stale_pending(conversation_id);
281 let answers_pending = self
282 .pending_proposal(conversation_id)
283 .is_some_and(|proposal| created_at >= proposal.created_at);
284 if answers_pending {
285 self.stale_pending(conversation_id);
286 }
281 return;
287 return;
282 }
288 }
283 self.push(EventKind::NewMessage {
289 self.push(EventKind::NewMessage {
@@ -466,9 +472,9 @@ mod tests {
466 assert!(hub.pending_proposal("c1").is_none());
472 assert!(hub.pending_proposal("c1").is_none());
467 assert_eq!(ui.try_recv().unwrap(), UiEvent::ProposalStale(stale));
473 assert_eq!(ui.try_recv().unwrap(), UiEvent::ProposalStale(stale));
468 propose(&hub, "c2", "yo");
474 propose(&hub, "c2", "yo");
469 hub.message_arrived("c2", "m1", false, None, "other");
475 hub.message_arrived("c2", "m1", false, Utc::now(), None, "other");
470 assert!(hub.pending_proposal("c2").is_some());
476 assert!(hub.pending_proposal("c2").is_some());
471 hub.message_arrived("c2", "m2", true, None, "mine");
477 hub.message_arrived("c2", "m2", true, Utc::now(), None, "mine");
472 assert!(hub.pending_proposal("c2").is_none());
478 assert!(hub.pending_proposal("c2").is_none());
473 }
479 }
474
480
@@ -521,7 +527,7 @@ mod tests {
521 tokio::spawn(async move { hub.wait_events(None, Duration::from_secs(5)).await })
527 tokio::spawn(async move { hub.wait_events(None, Duration::from_secs(5)).await })
522 };
528 };
523 tokio::time::sleep(Duration::from_millis(20)).await;
529 tokio::time::sleep(Duration::from_millis(20)).await;
524 hub.message_arrived("c1", "m1", false, Some("Ada".to_owned()), "hello");
530 hub.message_arrived("c1", "m1", false, Utc::now(), Some("Ada".to_owned()), "hello");
525 let (events, next) = waiter.await.unwrap();
531 let (events, next) = waiter.await.unwrap();
526 assert_eq!(events.len(), 1);
532 assert_eq!(events.len(), 1);
527 assert_eq!(next, events[0].seq);
533 assert_eq!(next, events[0].seq);
crates/mcp/src/tools.rs +13 −1
@@ -299,6 +299,16 @@ impl TeamsTools {
299 299 if !self.hub.policy().propose {
300 300 return Err(PROPOSE_DISABLED.to_owned());
301 301 }
302 if let Some(message_id) = &params.reply_to_message_id {
303 let found = store
304 .messages_by_id(&params.conversation_id, std::slice::from_ref(message_id))
305 .map_err(failure)?;
306 if !found.contains_key(message_id) {
307 return Err(format!(
308 "reply_to_message_id {message_id} is not a message of this conversation"
309 ));
310 }
311 }
302 312 let text = params.text.trim();
303 313 if text.is_empty() || text.chars().count() > MAX_PROPOSAL_CHARACTERS {
304 314 return Err(format!(
@@ -321,7 +331,7 @@ impl TeamsTools {
321 331 }
322 332
323 333 #[tool(
324 description = "Wait up to timeout_seconds (default 25, max 50) for events in allowed conversations: new_message, user_typing, user_sent, proposal_resolved (outcome sent, edited, discarded, stale or superseded). Returns {events, next}. Call again with since set to next to continue without missing events. Without since, only events from now on are returned."
334 description = "Wait up to timeout_seconds (default 25, max 50) for events in allowed conversations: new_message, user_typing, user_sent, proposal_resolved (outcome sent = the user sent it unchanged and it is queued for delivery, edited, discarded, stale or superseded). Returns {events, next}. Call again with since set to next to continue without missing events. Without since, only events from now on are returned."
325 335 )]
326 336 async fn wait_for_event(
327 337 &self,
@@ -395,6 +405,8 @@ impl TeamsTools {
395 405 if !policy.enabled || !policy.transcripts {
396 406 return Err(TRANSCRIPTS_DISABLED.to_owned());
397 407 }
408 let store = self.store()?;
409 self.readable_kind(&store, &params.meeting_chat_id)?;
398 410 let live_captions = self.hub.live_captions(&params.meeting_chat_id);
399 411 match self.source.transcript(&params.meeting_chat_id).await {
400 412 Ok(transcript) => Ok(render(json!({
@@ -299,6 +299,16 @@ impl TeamsTools {
299 if !self.hub.policy().propose {
299 if !self.hub.policy().propose {
300 return Err(PROPOSE_DISABLED.to_owned());
300 return Err(PROPOSE_DISABLED.to_owned());
301 }
301 }
302 if let Some(message_id) = &params.reply_to_message_id {
303 let found = store
304 .messages_by_id(&params.conversation_id, std::slice::from_ref(message_id))
305 .map_err(failure)?;
306 if !found.contains_key(message_id) {
307 return Err(format!(
308 "reply_to_message_id {message_id} is not a message of this conversation"
309 ));
310 }
311 }
302 let text = params.text.trim();
312 let text = params.text.trim();
303 if text.is_empty() || text.chars().count() > MAX_PROPOSAL_CHARACTERS {
313 if text.is_empty() || text.chars().count() > MAX_PROPOSAL_CHARACTERS {
304 return Err(format!(
314 return Err(format!(
@@ -321,7 +331,7 @@ impl TeamsTools {
321 }
331 }
322
332
323 #[tool(
333 #[tool(
324 description = "Wait up to timeout_seconds (default 25, max 50) for events in allowed conversations: new_message, user_typing, user_sent, proposal_resolved (outcome sent, edited, discarded, stale or superseded). Returns {events, next}. Call again with since set to next to continue without missing events. Without since, only events from now on are returned."
334 description = "Wait up to timeout_seconds (default 25, max 50) for events in allowed conversations: new_message, user_typing, user_sent, proposal_resolved (outcome sent = the user sent it unchanged and it is queued for delivery, edited, discarded, stale or superseded). Returns {events, next}. Call again with since set to next to continue without missing events. Without since, only events from now on are returned."
325 )]
335 )]
326 async fn wait_for_event(
336 async fn wait_for_event(
327 &self,
337 &self,
@@ -395,6 +405,8 @@ impl TeamsTools {
395 if !policy.enabled || !policy.transcripts {
405 if !policy.enabled || !policy.transcripts {
396 return Err(TRANSCRIPTS_DISABLED.to_owned());
406 return Err(TRANSCRIPTS_DISABLED.to_owned());
397 }
407 }
408 let store = self.store()?;
409 self.readable_kind(&store, &params.meeting_chat_id)?;
398 let live_captions = self.hub.live_captions(&params.meeting_chat_id);
410 let live_captions = self.hub.live_captions(&params.meeting_chat_id);
399 match self.source.transcript(&params.meeting_chat_id).await {
411 match self.source.transcript(&params.meeting_chat_id).await {
400 Ok(transcript) => Ok(render(json!({
412 Ok(transcript) => Ok(render(json!({
crates/mcp/tests/http.rs +58 −7
@@ -21,6 +21,8 @@ const ALLOWED_CHAT: &str = "19:alpha@thread.v2";
21 21 const HIDDEN_CHAT: &str = "19:beta@thread.v2";
22 22 const CHANNEL: &str = "19:channel@thread.tacv2";
23 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";
24 26
25 27 struct FakeSource {
26 28 store: Arc<Store>,
@@ -89,7 +91,11 @@ impl Harness {
89 91 seed(&store);
90 92 let policy = AgentPolicy {
91 93 enabled: true,
92 chats: Access::Selected(BTreeSet::from([ALLOWED_CHAT.to_owned()])),
94 chats: Access::Selected(BTreeSet::from([
95 ALLOWED_CHAT.to_owned(),
96 MEETING_CHAT.to_owned(),
97 LIVE_MEETING_CHAT.to_owned(),
98 ])),
93 99 channels: Access::Selected(BTreeSet::from([CHANNEL.to_owned()])),
94 100 propose,
95 101 calendar,
@@ -123,15 +129,22 @@ impl Harness {
123 129
124 130 fn seed(store: &Store) {
125 131 let time = |minute: u32| Utc.with_ymd_and_hms(2026, 10, 6, 9, minute, 0).unwrap();
126 let chat = |id: &str, title: &str| ChatRecord {
132 let chat_of_kind = |id: &str, kind: &str, title: &str| ChatRecord {
127 133 id: id.to_owned(),
128 kind: "group".to_owned(),
134 kind: kind.to_owned(),
129 135 title: title.to_owned(),
130 136 last_message_at: Some(time(5)),
131 137 ..ChatRecord::default()
132 138 };
139 let chat = |id: &str, title: &str| chat_of_kind(id, "group", title);
133 140 store
134 .upsert_chats(&[chat(ALLOWED_CHAT, "Planning"), chat(HIDDEN_CHAT, "Secrets")])
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 ])
135 148 .unwrap();
136 149 store
137 150 .upsert_teams(&[TeamRecord {
@@ -267,8 +280,16 @@ async fn lists_only_allowed_conversations() {
267 280 let client = harness.client().await;
268 281 let (_, chats) = call(&client, "list_chats", json!({})).await;
269 282 let chats: Value = serde_json::from_str(&chats).unwrap();
270 assert_eq!(chats["chats"].as_array().unwrap().len(), 1);
271 assert_eq!(chats["chats"][0]["id"], ALLOWED_CHAT);
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);
272 293 let (_, channels) = call(&client, "list_channels", json!({})).await;
273 294 let channels: Value = serde_json::from_str(&channels).unwrap();
274 295 assert_eq!(channels["channels"][0]["team"], "Platform");
@@ -478,7 +499,16 @@ async fn get_transcript_returns_turns_and_live_captions() {
478 499 assert_eq!(body["turns"][0]["text"], "Welcome everyone");
479 500 assert!(body["live_captions"].as_array().unwrap().is_empty());
480 501
481 let live_chat = "19:meeting_live@thread.v2";
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;
482 512 let (is_error, text) = call(
483 513 &client,
484 514 "get_transcript",
@@ -501,3 +531,24 @@ async fn get_transcript_returns_turns_and_live_captions() {
501 531 assert_eq!(body["live_captions"][0]["speaker"], "Bo");
502 532 assert_eq!(body["live_captions"][0]["text"], "Hi all");
503 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 }
@@ -21,6 +21,8 @@ const ALLOWED_CHAT: &str = "19:alpha@thread.v2";
21const HIDDEN_CHAT: &str = "19:beta@thread.v2";
21const HIDDEN_CHAT: &str = "19:beta@thread.v2";
22const CHANNEL: &str = "19:channel@thread.tacv2";
22const CHANNEL: &str = "19:channel@thread.tacv2";
23const MEETING_CHAT: &str = "19:meeting_abc@thread.v2";
23const MEETING_CHAT: &str = "19:meeting_abc@thread.v2";
24const LIVE_MEETING_CHAT: &str = "19:meeting_live@thread.v2";
25const HIDDEN_MEETING_CHAT: &str = "19:meeting_hidden@thread.v2";
24
26
25struct FakeSource {
27struct FakeSource {
26 store: Arc<Store>,
28 store: Arc<Store>,
@@ -89,7 +91,11 @@ impl Harness {
89 seed(&store);
91 seed(&store);
90 let policy = AgentPolicy {
92 let policy = AgentPolicy {
91 enabled: true,
93 enabled: true,
92 chats: Access::Selected(BTreeSet::from([ALLOWED_CHAT.to_owned()])),
94 chats: Access::Selected(BTreeSet::from([
95 ALLOWED_CHAT.to_owned(),
96 MEETING_CHAT.to_owned(),
97 LIVE_MEETING_CHAT.to_owned(),
98 ])),
93 channels: Access::Selected(BTreeSet::from([CHANNEL.to_owned()])),
99 channels: Access::Selected(BTreeSet::from([CHANNEL.to_owned()])),
94 propose,
100 propose,
95 calendar,
101 calendar,
@@ -123,15 +129,22 @@ impl Harness {
123
129
124fn seed(store: &Store) {
130fn seed(store: &Store) {
125 let time = |minute: u32| Utc.with_ymd_and_hms(2026, 10, 6, 9, minute, 0).unwrap();
131 let time = |minute: u32| Utc.with_ymd_and_hms(2026, 10, 6, 9, minute, 0).unwrap();
126 let chat = |id: &str, title: &str| ChatRecord {
132 let chat_of_kind = |id: &str, kind: &str, title: &str| ChatRecord {
127 id: id.to_owned(),
133 id: id.to_owned(),
128 kind: "group".to_owned(),
134 kind: kind.to_owned(),
129 title: title.to_owned(),
135 title: title.to_owned(),
130 last_message_at: Some(time(5)),
136 last_message_at: Some(time(5)),
131 ..ChatRecord::default()
137 ..ChatRecord::default()
132 };
138 };
139 let chat = |id: &str, title: &str| chat_of_kind(id, "group", title);
133 store
140 store
134 .upsert_chats(&[chat(ALLOWED_CHAT, "Planning"), chat(HIDDEN_CHAT, "Secrets")])
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 ])
135 .unwrap();
148 .unwrap();
136 store
149 store
137 .upsert_teams(&[TeamRecord {
150 .upsert_teams(&[TeamRecord {
@@ -267,8 +280,16 @@ async fn lists_only_allowed_conversations() {
267 let client = harness.client().await;
280 let client = harness.client().await;
268 let (_, chats) = call(&client, "list_chats", json!({})).await;
281 let (_, chats) = call(&client, "list_chats", json!({})).await;
269 let chats: Value = serde_json::from_str(&chats).unwrap();
282 let chats: Value = serde_json::from_str(&chats).unwrap();
270 assert_eq!(chats["chats"].as_array().unwrap().len(), 1);
283 let mut ids: Vec<&str> = chats["chats"]
271 assert_eq!(chats["chats"][0]["id"], ALLOWED_CHAT);
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);
272 let (_, channels) = call(&client, "list_channels", json!({})).await;
293 let (_, channels) = call(&client, "list_channels", json!({})).await;
273 let channels: Value = serde_json::from_str(&channels).unwrap();
294 let channels: Value = serde_json::from_str(&channels).unwrap();
274 assert_eq!(channels["channels"][0]["team"], "Platform");
295 assert_eq!(channels["channels"][0]["team"], "Platform");
@@ -478,7 +499,16 @@ async fn get_transcript_returns_turns_and_live_captions() {
478 assert_eq!(body["turns"][0]["text"], "Welcome everyone");
499 assert_eq!(body["turns"][0]["text"], "Welcome everyone");
479 assert!(body["live_captions"].as_array().unwrap().is_empty());
500 assert!(body["live_captions"].as_array().unwrap().is_empty());
480
501
481 let live_chat = "19:meeting_live@thread.v2";
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;
482 let (is_error, text) = call(
512 let (is_error, text) = call(
483 &client,
513 &client,
484 "get_transcript",
514 "get_transcript",
@@ -501,3 +531,24 @@ async fn get_transcript_returns_turns_and_live_captions() {
501 assert_eq!(body["live_captions"][0]["speaker"], "Bo");
531 assert_eq!(body["live_captions"][0]["speaker"], "Bo");
502 assert_eq!(body["live_captions"][0]["text"], "Hi all");
532 assert_eq!(body["live_captions"][0]["text"], "Hi all");
503}
533}
534
535#[tokio::test]
536async 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}