fix(telegram): count suppressed lifecycle receipts
This commit is contained in:
@@ -3578,6 +3578,99 @@ def test_runtime_telegram_receipt_queries_include_alert_notifications() -> None:
|
||||
assert "alert_notification_sent" in _RUNTIME_TELEGRAM_LATEST_SQL
|
||||
assert "controlled_apply_result" in _RUNTIME_TELEGRAM_COUNTS_SQL
|
||||
assert "controlled_apply_result" in _RUNTIME_TELEGRAM_LATEST_SQL
|
||||
assert "PARTITION BY CASE" in _RUNTIME_TELEGRAM_LATEST_SQL
|
||||
assert "receipt_kind_rank <= :limit" in _RUNTIME_TELEGRAM_LATEST_SQL
|
||||
|
||||
|
||||
def test_same_run_suppressed_controlled_apply_shadow_is_durable_receipt() -> None:
|
||||
candidate_op_id = "11111111-1111-4111-8111-111111111112"
|
||||
automation_run_id = candidate_op_id
|
||||
check_op_id = "22222222-2222-4222-8222-222222222223"
|
||||
apply_op_id = "33333333-3333-4333-8333-333333333334"
|
||||
incident_id = "INC-SUPPRESSED-TELEGRAM"
|
||||
readback = build_runtime_receipt_readback_from_rows(
|
||||
operation_latest_rows=[
|
||||
{
|
||||
"op_id": candidate_op_id,
|
||||
"operation_type": "ansible_candidate_matched",
|
||||
"status": "dry_run",
|
||||
"automation_run_id": automation_run_id,
|
||||
"incident_id": incident_id,
|
||||
},
|
||||
{
|
||||
"op_id": check_op_id,
|
||||
"parent_op_id": candidate_op_id,
|
||||
"operation_type": "ansible_check_mode_executed",
|
||||
"status": "success",
|
||||
"automation_run_id": automation_run_id,
|
||||
"incident_id": incident_id,
|
||||
},
|
||||
{
|
||||
"op_id": apply_op_id,
|
||||
"parent_op_id": check_op_id,
|
||||
"source_candidate_op_id": candidate_op_id,
|
||||
"check_mode_op_id": check_op_id,
|
||||
"operation_type": "ansible_apply_executed",
|
||||
"status": "success",
|
||||
"automation_run_id": automation_run_id,
|
||||
"incident_id": incident_id,
|
||||
},
|
||||
],
|
||||
verifier_latest_rows=[
|
||||
{
|
||||
"id": "verifier-suppressed-telegram",
|
||||
"apply_op_id": apply_op_id,
|
||||
"automation_run_id": automation_run_id,
|
||||
"verification_result": "success",
|
||||
}
|
||||
],
|
||||
km_latest_rows=[
|
||||
{
|
||||
"id": "km-suppressed-telegram",
|
||||
"path_type": f"ansible_apply_receipt:{apply_op_id[:8]}",
|
||||
"automation_run_id": automation_run_id,
|
||||
"status": "linked",
|
||||
}
|
||||
],
|
||||
telegram_latest_rows=[
|
||||
{
|
||||
"message_id": "telegram-shadow-same-run",
|
||||
"send_status": "shadow",
|
||||
"provider_message_id": None,
|
||||
"automation_run_id": automation_run_id,
|
||||
"incident_id": incident_id,
|
||||
"action": "controlled_apply_result",
|
||||
"notification_policy_version": (
|
||||
"telegram_posture_lifecycle_transition_v1"
|
||||
),
|
||||
"notification_disposition": "suppressed",
|
||||
"notification_provider_delivery": "state_transition",
|
||||
"notification_provider_send_suppressed": True,
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
closure = readback["latest_flow_closure"]
|
||||
assert closure["has_telegram_receipt"] is True
|
||||
assert closure["missing"] == []
|
||||
ledger = readback["autonomous_execution_loop_ledger"]
|
||||
telegram_stage = next(
|
||||
stage for stage in ledger["stages"] if stage["stage_id"] == "telegram_receipt"
|
||||
)
|
||||
assert telegram_stage["present"] is True
|
||||
assert telegram_stage["status"] == "shadow"
|
||||
assert telegram_stage["run_id_matches_expected"] is True
|
||||
|
||||
|
||||
def test_unclassified_shadow_cannot_satisfy_telegram_receipt() -> None:
|
||||
assert runtime_control_module._durable_controlled_apply_telegram_receipt(
|
||||
{
|
||||
"message_id": "telegram-shadow-unclassified",
|
||||
"send_status": "shadow",
|
||||
"provider_message_id": None,
|
||||
"action": "controlled_apply_result",
|
||||
}
|
||||
) is False
|
||||
|
||||
|
||||
def test_telegram_latest_dbapi_timeout_cannot_false_green_same_run_closure() -> None:
|
||||
@@ -4042,6 +4135,29 @@ def test_retry_rollback_terminal_closes_from_same_run_public_safe_receipts():
|
||||
] == 1
|
||||
|
||||
|
||||
def test_retry_terminal_accepts_policy_complete_suppressed_receipt() -> None:
|
||||
row = _closed_retry_terminal_row()
|
||||
row.update(
|
||||
{
|
||||
"telegram_send_status": "shadow",
|
||||
"telegram_provider_message_id": None,
|
||||
"telegram_notification_policy_version": (
|
||||
"telegram_failure_digest_v2"
|
||||
),
|
||||
"telegram_notification_disposition": "suppressed",
|
||||
"telegram_notification_provider_delivery": "digest",
|
||||
"telegram_provider_send_suppressed": True,
|
||||
}
|
||||
)
|
||||
|
||||
terminal = build_runtime_receipt_readback_from_rows(
|
||||
retry_terminal_latest_rows=[row]
|
||||
)["autonomous_retry_rollback_terminal"]
|
||||
|
||||
assert terminal["closed"] is True
|
||||
assert terminal["controls"]["telegram_receipt_same_run"] is True
|
||||
|
||||
|
||||
def test_retry_rollback_terminal_fails_closed_on_run_mismatch_or_missing_proof():
|
||||
row = _closed_retry_terminal_row()
|
||||
row["telegram_automation_run_id"] = "different-run"
|
||||
|
||||
@@ -289,6 +289,10 @@ def test_wazuh_posture_shadow_receipt_closes_without_provider_send() -> None:
|
||||
"telegram_execution_kind": "no_write_posture_readback",
|
||||
"telegram_notification_disposition": "suppressed",
|
||||
"telegram_provider_delivery": "shadow_only",
|
||||
"telegram_notification_policy_version": (
|
||||
"telegram_posture_state_digest_v1"
|
||||
),
|
||||
"telegram_provider_send_suppressed": True,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -310,6 +314,32 @@ def test_wazuh_posture_shadow_receipt_closes_without_provider_send() -> None:
|
||||
assert payload["boundaries"]["healthy_posture_notification_suppressed"] is True
|
||||
|
||||
|
||||
def test_wazuh_posture_duplicate_lifecycle_shadow_is_terminal_receipt() -> None:
|
||||
row = _complete_row()
|
||||
row.update(
|
||||
{
|
||||
"telegram_send_status": "shadow",
|
||||
"telegram_provider_message_id": None,
|
||||
"telegram_execution_kind": "no_write_posture_readback",
|
||||
"telegram_notification_disposition": "suppressed",
|
||||
"telegram_provider_delivery": "state_transition",
|
||||
"telegram_notification_policy_version": (
|
||||
"telegram_posture_lifecycle_transition_v1"
|
||||
),
|
||||
"telegram_provider_send_suppressed": True,
|
||||
}
|
||||
)
|
||||
|
||||
payload = build_iwooos_wazuh_controlled_executor_runtime_readback(
|
||||
row,
|
||||
executor_enabled=True,
|
||||
)
|
||||
|
||||
assert payload["summary"]["runtime_closed_count"] == 1
|
||||
assert payload["summary"]["telegram_receipt_count"] == 1
|
||||
assert payload["summary"]["telegram_provider_send_count"] == 0
|
||||
|
||||
|
||||
def test_wazuh_runtime_readback_prefers_ingress_convergence_semantics() -> None:
|
||||
row = _complete_row()
|
||||
row["catalog_id"] = "ansible:wazuh-alertmanager-integration"
|
||||
|
||||
Reference in New Issue
Block a user