diff --git a/apps/desktop-shell/scripts/check-config.mjs b/apps/desktop-shell/scripts/check-config.mjs index 38b85641b..b0fb9d741 100644 --- a/apps/desktop-shell/scripts/check-config.mjs +++ b/apps/desktop-shell/scripts/check-config.mjs @@ -2495,6 +2495,9 @@ for (const snippet of [ 'PermissionState::Prompt | PermissionState::PromptWithRationale', 'desktop_notification_delivered_to_system_result', 'json!({"action": HOST_BRIDGE_LOCAL_NOTIFICATION_DELIVERED_TO_SYSTEM_ACTION})', + 'local_notification_payload_truncates_to_shared_contract_limits', + '"a".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_TITLE_MAX_LENGTH)', + '"b".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_BODY_MAX_LENGTH)', '"notification permission denied"', 'app.notification().builder()', ]) { diff --git a/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs b/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs index ddb502ced..0adee5ccb 100644 --- a/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs +++ b/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs @@ -158,6 +158,21 @@ mod tests { assert_eq!(body.as_deref(), Some("作品已准备好 可以试玩")); } + #[test] + fn local_notification_payload_truncates_to_shared_contract_limits() { + let mut request = request("notification.showLocal"); + request.payload = Some(json!({ + "title": "a".repeat(90), + "body": "b".repeat(250) + })); + + let (title, body) = local_notification_payload(&request).expect("payload"); + let expected_body = "b".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_BODY_MAX_LENGTH); + + assert_eq!(title, "a".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_TITLE_MAX_LENGTH)); + assert_eq!(body.as_deref(), Some(expected_body.as_str())); + } + #[test] fn local_notification_success_result_reports_system_delivery() { assert_eq!(