Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(soup): chat owners filter (#1695)
Sean Aye3560e7336ef4
diff --git a/rust/cloud-storage/soup/examples/ai_tools_cli.rs b/rust/cloud-storage/soup/examples/ai_tools_cli.rsindex daa802cbdf..f01c0eaa3d 100644--- a/rust/cloud-storage/soup/examples/ai_tools_cli.rs+++ b/rust/cloud-storage/soup/examples/ai_tools_cli.rs@@ -1,3 +1,4 @@+#![recursion_limit = "256"]//! CLI example for testing soup AI tools interactively.//!//! This example creates a CLI interface to test the soup toolset with real database connections.diff --git a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rsindex 9d918595fc..d667fb8f38 100644--- a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs+++ b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs@@ -699,3 +699,82 @@ async fn it_parses_notification_and_task_filters() {})}++#[tokio::test]+async fn it_can_filter_chat_owners() {+ let json = r#"{+"channel_filters": {+"channel_ids": [+"00000000-0000-0000-0000-000000000000"+]+},+"document_filters": {+"document_ids": [+"00000000-0000-0000-0000-000000000000"+]+},+"email_filters": {+"recipients": [+"00000000-0000-0000-0000-000000000000"+]+},+"project_filters": {+"project_ids": [+"00000000-0000-0000-0000-000000000000"+]+},+"chat_filters": {+"owners": [+"macro|[email protected]"+]+},+"emailView": "all",+"limit": 100,+"sort_method": "updated_at"+}"#;++ let soup = MockSoup::new();+ let inner_counter = soup.called.clone();+ let router: Router = soup_router(SoupRouterState::new(+ soup,+ MockEmailLinkResult {+ get_link_result: Arc::new(|| Ok(None)),+ },+ ))+ .layer(Extension(UserContext {+ user_id: "macro|[email protected]".to_string(),+ fusion_user_id: "1234".to_string(),+ permissions: None,+ organization_id: None,+ }));++ let request = Request::builder()+ .uri("/soup")+ .method(Method::POST)+ .header("content-type", "application/json")+ .body(axum::body::Body::from(json))+ .unwrap();++ let _res = router.oneshot(request).await.unwrap();++ let arg = {+ let mut guard = inner_counter.lock().unwrap();+ guard.pop().unwrap()+ };++ assert_matches!(+ arg,+ SoupRequest {+ cursor: SoupQuery::Simple(SimpleQueryInner(Query::Sort(+ _,+ EntityFilters {+ chat_filters,+ ..+ },+ ))),+ ..+ } => {+ assert_eq!(chat_filters.owners, vec!["macro|[email protected]".to_string()]);+ }+ )+}diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rsindex 1da69dbfe4..4ab0d0c678 100644--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs@@ -379,7 +379,9 @@ fn build_chat_filter(ast: Option<&Expr<ChatLiteral>>) -> String {// todo? I'm not sure what a chat role filter looks likefilter_ast::ExprFrame::Literal(ChatLiteral::Role(_r)) => String::new(),filter_ast::ExprFrame::Literal(ChatLiteral::ChatId(i)) => format!("c.id = '{i}'"),- filter_ast::ExprFrame::Literal(ChatLiteral::Owner(o)) => format!("c.owner = '{o}'"),+ filter_ast::ExprFrame::Literal(ChatLiteral::Owner(o)) => {+ format!(r#"c."userId" = '{o}'"#)+ }filter_ast::ExprFrame::Literal(ChatLiteral::Importance(true)) => String::new(),// all chats are important, so if importance is false, exclude themfilter_ast::ExprFrame::Literal(ChatLiteral::Importance(false)) => "1=0".to_string(),@@ -408,7 +410,9 @@ fn build_project_filter(ast: Option<&Expr<ProjectLiteral>>) -> String {filter_ast::ExprFrame::Literal(ProjectLiteral::ProjectId(p)) => {format!(r#"p."parentId" = '{p}'"#)}- filter_ast::ExprFrame::Literal(ProjectLiteral::Owner(o)) => format!("p.owner = '{o}'"),+ filter_ast::ExprFrame::Literal(ProjectLiteral::Owner(o)) => {+ format!(r#"p."userId" = '{o}'"#)+ }filter_ast::ExprFrame::Literal(ProjectLiteral::Importance(true)) => String::new(),// all projects are important, so if importance is false, exclude themfilter_ast::ExprFrame::Literal(ProjectLiteral::Importance(false)) => "1=0".to_string(),diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rsindex 60ee44f158..1defca3245 100644--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs@@ -4591,3 +4591,66 @@ async fn test_dyn_all_types_filtered_to_empty(db: PgPool) -> anyhow::Result<()>Ok(())}++/// Reproduces a 500 error when all filter types are provided simultaneously.+/// The `chat_filters.owners` filter generates `c.owner` but the Chat table+/// uses `"userId"` as its owner column, not `owner`.+#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(+ path = "../../../../../macro_db_client/fixtures",+ scripts("dynamic_query_exhaustive")+ )+)]+async fn test_all_filter_types_combined(db: PgPool) -> anyhow::Result<()> {+ use item_filters::{+ ChannelFilters, ChatFilters, DocumentFilters, EmailFilters, EntityFilters, ProjectFilters,+ };++ let nil = "00000000-0000-0000-0000-000000000000".to_string();++ let entity_filters = EntityFilters {+ channel_filters: ChannelFilters {+ channel_ids: vec![nil.clone()],+ ..Default::default()+ },+ document_filters: DocumentFilters {+ document_ids: vec![nil.clone()],+ ..Default::default()+ },+ email_filters: EmailFilters {+ recipients: vec![nil.clone()],+ ..Default::default()+ },+ project_filters: ProjectFilters {+ project_ids: vec![nil.clone()],+ ..Default::default()+ },+ chat_filters: ChatFilters {+ owners: vec!["macro|[email protected]".to_string()],+ ..Default::default()+ },+ };++ let filters = EntityFilterAst::new_from_filters(entity_filters)?.unwrap();++ let items = dyn_fetch(+ &db,+ "macro|[email protected]",+ 100,+ SimpleSortMethod::UpdatedAt,+ filters,+ false,+ )+ .await?;++ // The query should execute without a SQL error.+ // With the nil UUID filters we expect no document/project matches,+ // but the chat owner filter should return chats owned by the user.+ assert!(+ items.iter().all(|i| matches!(i, SoupItem::Chat(_))),+ "Only chats should match (documents/projects filtered to nil UUID)"+ );++ Ok(())+}