From 1e5b7a5c48abe9cf7f0d9ffe399ebb608c561543 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 20 Jun 2026 11:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=A1=8C=E9=9D=A2=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E8=BD=BD=E8=8D=B7=E6=88=AA=E6=96=AD=E5=A5=91=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面通知单测覆盖共享长度边界截断 桌面壳配置检查反查通知截断测试 --- apps/desktop-shell/scripts/check-config.mjs | 3 +++ .../src-tauri/src/host_bridge/notifications.rs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) 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!(