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(ios) deliver all endpoints (#1374)
Sean Ayebb7126af7a05
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 16d58a9fa8..5c3e54c1c1 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -2509,12 +2509,12 @@ dependencies = [[[package]]name = "deranged"-version = "0.3.11"+version = "0.5.5"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"+checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587"dependencies = ["powerfmt",- "serde",+ "serde_core",][[package]]@@ -5857,6 +5857,7 @@ dependencies = ["aws-sdk-sqs","axum","chrono",+ "either","hex","itertools 0.14.0","macro_db_migrator",@@ -6003,9 +6004,9 @@ dependencies = [[[package]]name = "num-conv"-version = "0.1.0"+version = "0.2.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"+checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050"[[package]]name = "num-derive"@@ -8972,30 +8973,30 @@ dependencies = [[[package]]name = "time"-version = "0.3.37"+version = "0.3.47"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21"+checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"dependencies = ["deranged","itoa","num-conv","powerfmt",- "serde",+ "serde_core","time-core","time-macros",][[package]]name = "time-core"-version = "0.1.2"+version = "0.1.8"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"+checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"[[package]]name = "time-macros"-version = "0.2.19"+version = "0.2.27"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de"+checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215"dependencies = ["num-conv","time-core",diff --git a/rust/cloud-storage/notification/Cargo.toml b/rust/cloud-storage/notification/Cargo.tomlindex 569bd68028..7709ff295b 100644--- a/rust/cloud-storage/notification/Cargo.toml+++ b/rust/cloud-storage/notification/Cargo.toml@@ -6,7 +6,13 @@ version = "0.1.0"[features]-axum = ["dep:axum", "dep:model-error-response", "dep:model_user", "models_pagination/axum", "schema"]+axum = [+ "dep:axum",+ "dep:model-error-response",+ "dep:model_user",+ "models_pagination/axum",+ "schema",+]schema = ["dep:utoipa"][dependencies]@@ -15,6 +21,7 @@ aws-sdk-sns = { workspace = true }aws-sdk-sqs = { workspace = true }axum = { workspace = true, optional = true }chrono = { workspace = true }+either = { workspace = true }hex = { workspace = true }itertools = { workspace = true }macro_user_id = { path = "../macro_user_id" }diff --git a/rust/cloud-storage/notification/src/domain/service/egress.rs b/rust/cloud-storage/notification/src/domain/service/egress.rsindex 7c53d72388..b5b21eabbd 100644--- a/rust/cloud-storage/notification/src/domain/service/egress.rs+++ b/rust/cloud-storage/notification/src/domain/service/egress.rs@@ -11,6 +11,7 @@ use crate::domain::ports::{EmailSender, NotificationEgress, NotificationQueue, NotificationRepository, NotificationSender,RateLimitPort, WebSocketSender,};+use either::Either;use rootcause::prelude::ResultExt;use rootcause::{Report, report};@@ -93,18 +94,18 @@ wheremut recursion_tail: Vec<Result<DeliverySuccess, Report>>,) -> Vec<Result<DeliverySuccess, Report>> {let result = match &node.notif {- NotificationChannel::ConnGateway(conn) => self.deliver_conn_gateway(conn).await,- NotificationChannel::Ios(apns) => self.deliver_ios(apns).await,- NotificationChannel::Email(email) => self.deliver_email(email).await,+ NotificationChannel::ConnGateway(conn) => {+ Either::Left([self.deliver_conn_gateway(conn).await])+ }+ NotificationChannel::Email(email) => Either::Left([self.deliver_email(email).await]),+ NotificationChannel::Ios(apns) => Either::Right(self.deliver_ios(apns).await),};- recursion_tail.push(result);- let res = recursion_tail- .last()- .expect("we just pushed, this cannot fail");-- match (res, node.on_failure) {- (Ok(_), _) | (Err(_), None) => recursion_tail,- (Err(_), Some(fallback)) => {+ let all_failed = result.iter().all(Result::is_err);+ recursion_tail.extend(result.into_iter());++ match (all_failed, node.on_failure) {+ (false, _) | (true, None) => recursion_tail,+ (true, Some(fallback)) => {Box::pin(self.deliver_notification_inner(message_type, *fallback, recursion_tail)).await}@@ -126,13 +127,17 @@ whereasync fn deliver_ios(&self,apns: &crate::domain::models::queue_message::APNSTargets<serde_json::Value>,- ) -> Result<DeliverySuccess, Report> {+ ) -> Vec<Result<DeliverySuccess, Report>> {+ let mut out = Vec::with_capacity(apns.ios_device_endpoints.len());for endpoint in &apns.ios_device_endpoints {- self.mobile+ let res = self+ .mobile.send_ios_push_notification(endpoint, &apns.notif, &apns.attributes)- .await?;+ .await+ .map(|()| DeliverySuccess::Ios);+ out.push(res)}- Ok(DeliverySuccess::Ios)+ out}/// Deliver via email.@@ -173,16 +178,16 @@ where// Deliver the notification (body is already parsed as QueueMessage)let delivery_results = self.deliver_notification(message.body).await;- // Check if all deliveries succeeded- let all_succeeded = delivery_results.iter().all(Result::is_ok);+ // Check if any deliveries succeeded+ let any_succeeded = delivery_results.iter().any(Result::is_ok);// Add results (stripping the DeliveryFailure context for the trait return type)for result in delivery_results {results.push(result.map_err(Report::from));}- // Delete from queue only if all deliveries succeeded- if all_succeeded && let Err(e) = self.queue.delete_message(&receipt_handle).await {+ // Delete from queue if any deliveries succeeded+ if any_succeeded && let Err(e) = self.queue.delete_message(&receipt_handle).await {// if delete queue fails push it into the resultsresults.push(Err(e))}diff --git a/rust/cloud-storage/notification/src/domain/service/test.rs b/rust/cloud-storage/notification/src/domain/service/test.rsindex f5c7e4f4ae..003d749845 100644--- a/rust/cloud-storage/notification/src/domain/service/test.rs+++ b/rust/cloud-storage/notification/src/domain/service/test.rs@@ -1268,3 +1268,164 @@ async fn test_mark_undone_updates_db_no_push_clear() {"Should not clear push when marking undone");}++/// Mock mobile sender that tracks attempted endpoints and can fail specific ones.+struct TrackingMobileSender {+ /// Endpoints that were attempted (for verification).+ attempted_endpoints: Mutex<Vec<String>>,+ /// Endpoints that should fail when attempted.+ failing_endpoints: HashSet<String>,+}++impl TrackingMobileSender {+ fn new(failing_endpoints: HashSet<String>) -> Self {+ Self {+ attempted_endpoints: Mutex::new(Vec::new()),+ failing_endpoints,+ }+ }++ fn get_attempted_endpoints(&self) -> Vec<String> {+ self.attempted_endpoints.lock().unwrap().clone()+ }+}++impl NotificationSender for TrackingMobileSender {+ async fn send_ios_push_notification<T: Serialize + Send + Sync>(+ &self,+ endpoint_arn: &str,+ _notification: &crate::domain::models::apple::APNSPushNotification<T>,+ _attributes: &crate::domain::models::mobile::MessageAttributes,+ ) -> Result<(), Report> {+ // Track that this endpoint was attempted+ self.attempted_endpoints+ .lock()+ .unwrap()+ .push(endpoint_arn.to_string());++ // Fail if this endpoint is in the failing set+ if self.failing_endpoints.contains(endpoint_arn) {+ rootcause::bail!("Simulated APNS failure for endpoint: {}", endpoint_arn);+ }++ Ok(())+ }++ async fn send_android_push_notification<T: Serialize + Send + Sync>(+ &self,+ _endpoint_arn: &str,+ _notification: &crate::domain::models::android::FCMMessage<T>,+ _attributes: &crate::domain::models::mobile::MessageAttributes,+ ) -> Result<(), Report> {+ Ok(())+ }+}++#[tokio::test]+async fn test_egress_ios_attempts_all_endpoints_even_if_some_fail() {+ use crate::domain::models::apple::{APNSPushNotification, Aps};+ use crate::domain::models::mobile::{MessageAttributes, PushType};+ use crate::domain::models::queue_message::APNSTargets;++ let endpoint1 = "arn:aws:sns:us-east-1:111:endpoint/APNS/app/device1";+ let endpoint2 = "arn:aws:sns:us-east-1:111:endpoint/APNS/app/device2";+ let endpoint3 = "arn:aws:sns:us-east-1:111:endpoint/APNS/app/device3";+ let endpoint4 = "arn:aws:sns:us-east-1:111:endpoint/APNS/app/device4";++ // Configure endpoints 1 and 3 to fail+ let failing_endpoints: HashSet<String> = [endpoint1.to_string(), endpoint3.to_string()].into();++ let mobile_sender = std::sync::Arc::new(TrackingMobileSender::new(failing_endpoints));+ let service = NotificationEgressService::new(+ MockQueue::new(),+ MockRepository::new(),+ MockWebSocketSender,+ mobile_sender.clone(),+ MockEmailSender,+ MockRateLimiter::allowing(),+ );++ let message = QueueMessage {+ message_type: "test_notification".to_string(),+ rate_limit: None,+ content: Node {+ notif: NotificationChannel::Ios(Box::new(APNSTargets {+ notif: APNSPushNotification {+ aps: Aps::default(),+ push_notification_data: json!({"message": "Hello"}),+ },+ attributes: MessageAttributes {+ push_type: PushType::Alert,+ collapse_key: "test_collapse".to_string(),+ },+ ios_device_endpoints: vec![+ endpoint1.to_string(),+ endpoint2.to_string(),+ endpoint3.to_string(),+ endpoint4.to_string(),+ ],+ })),+ on_failure: None,+ },+ };++ let results = service.deliver_notification(message).await;++ // Verify ALL 4 endpoints were attempted+ let attempted = mobile_sender.get_attempted_endpoints();+ assert_eq!(+ attempted.len(),+ 4,+ "Should attempt delivery to all 4 endpoints, but only attempted: {:?}",+ attempted+ );+ assert!(+ attempted.contains(&endpoint1.to_string()),+ "Should attempt endpoint1"+ );+ assert!(+ attempted.contains(&endpoint2.to_string()),+ "Should attempt endpoint2"+ );+ assert!(+ attempted.contains(&endpoint3.to_string()),+ "Should attempt endpoint3"+ );+ assert!(+ attempted.contains(&endpoint4.to_string()),+ "Should attempt endpoint4"+ );++ // Verify we got 4 results (one per endpoint)+ assert_eq!(results.len(), 4, "Should have 4 results (one per endpoint)");++ // Verify 2 succeeded and 2 failed+ let successes = results.iter().filter(|r| r.is_ok()).count();+ let failures = results.iter().filter(|r| r.is_err()).count();+ assert_eq!(successes, 2, "Should have 2 successful deliveries");+ assert_eq!(failures, 2, "Should have 2 failed deliveries");+}++impl NotificationSender for std::sync::Arc<TrackingMobileSender> {+ async fn send_ios_push_notification<T: Serialize + Send + Sync>(+ &self,+ endpoint_arn: &str,+ notification: &crate::domain::models::apple::APNSPushNotification<T>,+ attributes: &crate::domain::models::mobile::MessageAttributes,+ ) -> Result<(), Report> {+ (**self)+ .send_ios_push_notification(endpoint_arn, notification, attributes)+ .await+ }++ async fn send_android_push_notification<T: Serialize + Send + Sync>(+ &self,+ endpoint_arn: &str,+ notification: &crate::domain::models::android::FCMMessage<T>,+ attributes: &crate::domain::models::mobile::MessageAttributes,+ ) -> Result<(), Report> {+ (**self)+ .send_android_push_notification(endpoint_arn, notification, attributes)+ .await+ }+}