锁定桌面通知投递不可用响应

桌面通知投递失败转为稳定 host_error

桌面通知单测覆盖投递不可用 code 和 message

桌面壳配置检查反查通知投递不可用边界
This commit is contained in:
2026-06-20 13:05:21 +08:00
parent b6b428e531
commit 1f4d662054
2 changed files with 23 additions and 1 deletions
@@ -2563,6 +2563,7 @@ for (const snippet of [
'DesktopNotificationPermissionAction',
'desktop_notification_permission_action',
'notification_permission_unavailable_response',
'notification_delivery_unavailable_response',
'PermissionState::Granted',
'PermissionState::Denied',
'PermissionState::Prompt | PermissionState::PromptWithRationale',
@@ -2570,9 +2571,11 @@ for (const snippet of [
'json!({"action": HOST_BRIDGE_LOCAL_NOTIFICATION_DELIVERED_TO_SYSTEM_ACTION})',
'local_notification_payload_truncates_to_shared_contract_limits',
'notification_permission_unavailable_response_is_stable',
'notification_delivery_unavailable_response_is_stable',
'"a".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_TITLE_MAX_LENGTH)',
'"b".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_BODY_MAX_LENGTH)',
'"notification permission unavailable"',
'"notification delivery unavailable"',
'"notification permission denied"',
'app.notification().builder()',
]) {
@@ -97,6 +97,14 @@ fn notification_permission_unavailable_response(request: &HostBridgeRequest) ->
)
}
fn notification_delivery_unavailable_response(request: &HostBridgeRequest) -> HostBridgeResponse {
failed(
request.id.clone(),
"host_error",
"notification delivery unavailable",
)
}
pub(crate) fn show_desktop_local_notification(
app: &tauri::AppHandle,
request: &HostBridgeRequest,
@@ -142,7 +150,7 @@ pub(crate) fn show_desktop_local_notification(
request.id.clone(),
desktop_notification_delivered_to_system_result(),
),
Err(error) => failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => notification_delivery_unavailable_response(request),
}
}
@@ -200,6 +208,17 @@ mod tests {
assert_eq!(error.message, "notification permission unavailable");
}
#[test]
fn notification_delivery_unavailable_response_is_stable() {
let request = request("notification.showLocal");
let response = notification_delivery_unavailable_response(&request);
let error = response.error.expect("error");
assert_eq!(error.code, "host_error");
assert_eq!(error.message, "notification delivery unavailable");
}
#[test]
fn local_notification_payload_rejects_empty_and_control_text() {
let mut empty = request("notification.showLocal");