Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test: match lifecycle receipts at published webhook precision

pulse-triage[bot]ad9877e28d9f
diff --git a/tests/qualification/alert-lifecycle/README.md b/tests/qualification/alert-lifecycle/README.md
index 16cc2bc93d..93fa8399b0 100644
--- a/tests/qualification/alert-lifecycle/README.md
+++ b/tests/qualification/alert-lifecycle/README.md
@@ -78,8 +78,11 @@ HTTP redirects are disabled for the authenticated client.
4. Actual operator-owned restart; require retained incident ID and terminal
audit. Keep this occurrence firing for the operator Retry.
5. Global terminal Retry; require the **original terminal notification ID** to
- gain a sent audit **before resolution**. Then low CPU clears and high CPU
- creates a distinct recurrence; require its exact start time at the recipient.
+ gain a sent audit **before resolution** and require its firing receipt. Then
+ low CPU clears and high CPU creates a distinct recurrence; require its alert
+ ID and start time at the recipient, projected to the published webhook’s
+ whole-second RFC3339 precision. Fail closed if old and new starts share that
+ second; full-precision API timestamps remain unchanged in incident queries.
Retain old and current timelines separately. Resolution deliberately cancels
obsolete terminal firing rows, so do not expect Retry to resurrect them.
6. Disable agent alerts; ingest a fresh high-CPU identity for 30s and require
diff --git a/tests/qualification/alert-lifecycle/acceptance.py b/tests/qualification/alert-lifecycle/acceptance.py
index f15277a781..16ac5a206c 100644
--- a/tests/qualification/alert-lifecycle/acceptance.py
+++ b/tests/qualification/alert-lifecycle/acceptance.py
@@ -38,6 +38,19 @@ def loopback_url(url):
return url.rstrip("/")
+def webhook_start(alert):
+ # Published prepareWebhookData uses time.RFC3339, not RFC3339Nano.
+ # Keep the full API value for incident queries; only project recipient matching.
+ start = datetime.datetime.fromisoformat(alert["startTime"].replace("Z", "+00:00"))
+ check(start.tzinfo is not None, "occurrence start lacks timezone")
+ return start.isoformat(timespec="seconds").replace("+00:00", "Z")
+
+
+def distinct_webhook_occurrences(old, current):
+ check(webhook_start(old) != webhook_start(current),
+ "occurrences indistinguishable at webhook timestamp precision")
+
+
def report(name, cpu):
return {"agent": {"id": name, "type": "unified", "intervalSeconds": 5,
"commandsEnabled": False},
@@ -190,6 +203,11 @@ class Driver:
return [e for e in entries if alert["id"] in (e["alertIds"] or [])
and e["outcome"] == outcome]
+ def received_occurrence(self, name, alert):
+ return any(r["payload"].get("id") == alert["id"]
+ and r["payload"].get("start") == webhook_start(alert)
+ for r in self.recipient.matching(name))
+
def retry_terminal(self, alert, terminal_ids):
retry = self.api("/api/notifications/terminal-failures/retry", {})
# Preserve the returned result even when the assertion fails.
@@ -265,15 +283,15 @@ class Driver:
# cancels obsolete terminal firing rows; a later recurrence cannot revive them.
self.recipient.mode(0)
self.retry_terminal(old, terminal_ids)
+ self.wait("terminal-retry-recipient", lambda: self.received_occurrence(terminal, old))
self.snapshot("old-occurrence-after-retry", old)
self.wait("resolved", lambda: not self.active(terminal),
tick=lambda: self.ingest(terminal, 10))
current = self.wait("recurrence", lambda: self.active(terminal),
tick=lambda: self.ingest(terminal, 95))
check(current["startTime"] != old["startTime"], "recurrence reused old start")
- self.wait("recurrence-recipient", lambda: any(
- r["payload"]["start"] == current["startTime"]
- for r in self.recipient.matching(terminal)))
+ distinct_webhook_occurrences(old, current)
+ self.wait("recurrence-recipient", lambda: self.received_occurrence(terminal, current))
self.snapshot("old-occurrence-after-recurrence", old)
self.snapshot("current-occurrence-after-recurrence", current)
# Occurrence-side-effect correctness requires review of both retained timelines.
diff --git a/tests/qualification/alert-lifecycle/test_acceptance.py b/tests/qualification/alert-lifecycle/test_acceptance.py
index 15df21919c..7b44a3f35b 100644
--- a/tests/qualification/alert-lifecycle/test_acceptance.py
+++ b/tests/qualification/alert-lifecycle/test_acceptance.py
@@ -80,6 +80,37 @@ class AcceptanceContractTests(unittest.TestCase):
with patch.dict(os.environ, {"PULSE_ACCEPTANCE_TOKEN": "synthetic-secret"}):
return a.Driver(args, self.evidence, a.Recipient(self.evidence))
+ def test_recipient_matches_fractional_api_start_at_webhook_precision(self):
+ driver = self.driver()
+ alert = {"id": "cpu", "startTime": "2026-09-10T15:30:02.123456789Z"}
+ driver.recipient.accept({"id": "cpu", "resource": "x", "event": "alert",
+ "start": "2026-09-10T15:30:02Z"})
+ self.assertTrue(driver.received_occurrence("x", alert))
+
+ def test_recipient_rejects_old_occurrence_and_wrong_alert(self):
+ driver = self.driver()
+ alert = {"id": "cpu", "startTime": "2026-09-10T15:30:02.123456789Z"}
+ for identity, start in (("cpu", "2026-09-10T15:30:01Z"),
+ ("other", "2026-09-10T15:30:02Z")):
+ driver.recipient.accept({"id": identity, "resource": "x", "event": "alert",
+ "start": start})
+ self.assertFalse(driver.received_occurrence("x", alert))
+
+ def test_same_second_occurrences_fail_closed(self):
+ with self.assertRaisesRegex(AssertionError, "indistinguishable"):
+ a.distinct_webhook_occurrences(
+ {"startTime": "2026-09-10T15:30:02.123456789Z"},
+ {"startTime": "2026-09-10T15:30:02.987654321Z"})
+ a.distinct_webhook_occurrences(
+ {"startTime": "2026-09-10T15:30:02.123456789Z"},
+ {"startTime": "2026-09-10T15:30:03.123456789Z"})
+
+ def test_webhook_projection_preserves_offset_and_requires_timezone(self):
+ self.assertEqual(a.webhook_start({"startTime": "2026-09-10T16:30:02.123+01:00"}),
+ "2026-09-10T16:30:02+01:00")
+ with self.assertRaisesRegex(AssertionError, "timezone"):
+ a.webhook_start({"startTime": "2026-09-10T15:30:02"})
+
def test_retry_precedes_resolution_in_scenario(self):
# Guard scenario ordering separately from the recipient/identity proof.
tree = ast.parse(textwrap.dedent(inspect.getsource(a.Driver.run)))