fix(cron): validate failure_deliver at preflight and dashboard update lanes
Follow-up to the failure_deliver salvage (#100375): - _preflight_check_delivery also checks the failure lane, so a typo'd failure_deliver platform blocks at config-validation time instead of surfacing only when a failure occurs — exactly when the notice must not be lost. Duplicate lanes are checked once. - The dashboard cron-update normalizer treats failure_deliver like deliver (text normalization; empty clears the optional override instead of coalescing), closing the one update path that could write an unnormalized value into jobs.json. 4 guard tests; both fixes mutation-checked (neutralize -> red, restore -> green).
This commit is contained in:
+21
-10
@@ -5459,19 +5459,30 @@ def _preflight_check_delivery(job: dict) -> Optional[str]:
|
||||
the same source `cron_delivery_targets` uses). Gateway-config load
|
||||
failures fail OPEN so a transient config hiccup never wedges delivery
|
||||
that would have worked.
|
||||
|
||||
``failure_deliver`` is checked with the same rules: a typo'd failure
|
||||
platform would otherwise only surface when a failure occurs — exactly
|
||||
when the notice must not be lost (NS-788 follow-up).
|
||||
"""
|
||||
deliver_value = _normalize_deliver_value(job.get("deliver", "local"))
|
||||
failure_deliver_value = _normalize_deliver_value(
|
||||
_delivery_lane_value(job, for_failure=True)
|
||||
)
|
||||
lane_values = [deliver_value]
|
||||
if failure_deliver_value != deliver_value:
|
||||
lane_values.append(failure_deliver_value)
|
||||
platform_parts: list[str] = []
|
||||
for part in deliver_value.split(","):
|
||||
part = part.strip()
|
||||
if not part or part.lower() in {"local", "origin", "all"}:
|
||||
continue
|
||||
# bot-chat targets need no gateway credentials — they deliver via a
|
||||
# local chat subprocess. Unknown-profile failures surface per run in
|
||||
# last_delivery_error (and are validated at create time).
|
||||
if parse_bot_chat_deliver_token(part) is not None:
|
||||
continue
|
||||
platform_parts.append(part.split(":", 1)[0].strip())
|
||||
for lane_value in lane_values:
|
||||
for part in lane_value.split(","):
|
||||
part = part.strip()
|
||||
if not part or part.lower() in {"local", "origin", "all"}:
|
||||
continue
|
||||
# bot-chat targets need no gateway credentials — they deliver via a
|
||||
# local chat subprocess. Unknown-profile failures surface per run in
|
||||
# last_delivery_error (and are validated at create time).
|
||||
if parse_bot_chat_deliver_token(part) is not None:
|
||||
continue
|
||||
platform_parts.append(part.split(":", 1)[0].strip())
|
||||
if not platform_parts:
|
||||
return None
|
||||
|
||||
|
||||
@@ -12977,6 +12977,13 @@ def _normalize_dashboard_cron_updates(
|
||||
)
|
||||
if "deliver" in normalized:
|
||||
normalized["deliver"] = _cron_optional_text(normalized["deliver"]) or "local"
|
||||
if "failure_deliver" in normalized:
|
||||
# Same text normalization as deliver, but empty CLEARS the override
|
||||
# (failures fall back to deliver) rather than coalescing to a target
|
||||
# — the field is optional by design (NS-788).
|
||||
normalized["failure_deliver"] = _cron_optional_text(
|
||||
normalized["failure_deliver"]
|
||||
)
|
||||
if "context_from" in normalized:
|
||||
normalized["context_from"] = _cron_string_list(normalized["context_from"])
|
||||
if "enabled_toolsets" in normalized:
|
||||
|
||||
@@ -405,3 +405,58 @@ class TestOutcomeBookkeeping:
|
||||
|
||||
assert [c["chat_id"] for c in run_env["send"]] == ["D0MAIN"]
|
||||
assert self._outcome(run_env) == "delivered"
|
||||
|
||||
|
||||
class TestPreflightAndDashboardLanes:
|
||||
"""Follow-up (salvage): the failure lane is validated everywhere the
|
||||
deliver lane is — preflight config checks and the dashboard update
|
||||
normalizer — so a typo'd failure target is caught before a failure
|
||||
needs it."""
|
||||
|
||||
def test_preflight_blocks_unknown_failure_platform(self, monkeypatch):
|
||||
"""A bogus failure_deliver platform blocks at preflight, exactly
|
||||
like a bogus deliver platform would."""
|
||||
monkeypatch.setattr(s, "_is_known_delivery_platform", lambda _p: False)
|
||||
err = s._preflight_check_delivery({
|
||||
"id": "p1", "deliver": "local",
|
||||
"failure_deliver": "nonexistent-platform:C1",
|
||||
})
|
||||
assert err is not None and "not a known" in err
|
||||
|
||||
def test_preflight_failure_deliver_local_adds_no_platforms(self):
|
||||
"""failure_deliver: local adds nothing to check — a deliver=local
|
||||
job with suppressed failures stays zero-cost at preflight."""
|
||||
assert s._preflight_check_delivery({
|
||||
"id": "p2", "deliver": "local", "failure_deliver": "local",
|
||||
}) is None
|
||||
|
||||
def test_preflight_duplicate_lane_not_checked_twice(self, monkeypatch):
|
||||
"""failure_deliver equal to deliver must not double-check (or
|
||||
double-report) the same platform."""
|
||||
seen = []
|
||||
|
||||
def _known(p):
|
||||
seen.append(p)
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(s, "_is_known_delivery_platform", _known)
|
||||
s._preflight_check_delivery({
|
||||
"id": "p3", "deliver": "ghost:C1", "failure_deliver": "ghost:C1",
|
||||
})
|
||||
assert seen == ["ghost"]
|
||||
|
||||
def test_dashboard_update_normalizes_failure_deliver(self, tmp_path):
|
||||
"""The dashboard update lane normalizes failure_deliver like
|
||||
deliver: text stripped, empty clears (None) instead of
|
||||
coalescing to a target."""
|
||||
from hermes_cli.web_server import _normalize_dashboard_cron_updates
|
||||
|
||||
out = _normalize_dashboard_cron_updates(
|
||||
{"failure_deliver": " slack:D0ALERTS "}, tmp_path
|
||||
)
|
||||
assert out["failure_deliver"] == "slack:D0ALERTS"
|
||||
|
||||
cleared = _normalize_dashboard_cron_updates(
|
||||
{"failure_deliver": ""}, tmp_path
|
||||
)
|
||||
assert cleared["failure_deliver"] is None
|
||||
|
||||
Reference in New Issue
Block a user