From 2e9f6621a37faa35611813d1098699acde10f9f8 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 4 May 2026 02:54:17 +0800 Subject: [PATCH] =?UTF-8?q?test(health):=20=E5=91=8A=E8=AD=A6=E9=99=8D?= =?UTF-8?q?=E5=99=AA=E9=9B=86=E6=88=90=E6=B5=8B=E8=AF=95=E9=AA=A8=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4 个 Testcontainers 测试用例(忽略状态)覆盖: 患者级升级阈值 + 系统级聚合窗口 + critical 不聚合 + 完整流程 --- .../tests/alert_noise_integration.rs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 crates/erp-health/tests/alert_noise_integration.rs diff --git a/crates/erp-health/tests/alert_noise_integration.rs b/crates/erp-health/tests/alert_noise_integration.rs new file mode 100644 index 0000000..466b267 --- /dev/null +++ b/crates/erp-health/tests/alert_noise_integration.rs @@ -0,0 +1,51 @@ +/// 告警降噪集成测试骨架。 +/// +/// 纯逻辑单元测试在 alert_noise_reducer::tests 中。 +/// 以下集成测试需要 Testcontainers PostgreSQL 环境。 +use erp_health::service::alert_noise_reducer; + +/// 验证 severity_rank 排序一致性 +#[test] +fn severity_rank_consistency_via_module() { + // 间接验证:alert_noise_reducer 模块可被外部 crate 引用 + // 实际逻辑测试在 lib 内的 tests 模块中 +} + +/// 验证患者级升级条件 +#[tokio::test] +#[ignore = "需要 Testcontainers 环境"] +async fn patient_escalation_requires_threshold_alerts() { + // 1. 创建患者和 2 条低级别告警 + // 2. 调用 apply_noise_reduction("medium") + // 3. 验证未升级 + // 4. 再创建 1 条低级别告警(达到阈值 3) + // 5. 调用 apply_noise_reduction("medium") + // 6. 验证升级为 "high" +} + +/// 验证系统级聚合 +#[tokio::test] +#[ignore = "需要 Testcontainers 环境"] +async fn system_aggregation_suppresses_within_window() { + // 1. 创建一条告警 + // 2. 立即调用 check_system_aggregation + // 3. 验证 should_suppress = true +} + +/// 验证 critical 告警不被聚合 +#[tokio::test] +#[ignore = "需要 Testcontainers 环境"] +async fn critical_alerts_never_suppressed() { + // 1. 创建多条告警(含 critical) + // 2. 调用 apply_noise_reduction("critical") + // 3. 验证 is_suppressed = false +} + +/// 验证完整降噪流程:低级告警多次触发后升级 + 聚合 +#[tokio::test] +#[ignore = "需要 Testcontainers 环境"] +async fn full_noise_reduction_flow() { + // 1. 创建 3 条低级告警 + // 2. 第 4 次触发 apply_noise_reduction("low") → 升级为 "medium" + // 3. 短时间内再次触发 → 被聚合抑制 +}