Files
hermes-agent/tests/gateway/test_warning_emission_boundary.py
Victor Kyriazakos cd3de040ab feat(notifications): opt-in suppression of user-channel warning notifications
Squash of the 54 commits on victor-kyriazakos:feat/user-channel-warning-suppression
(PR #112302, head f45c640e55) so the contributor's authorship survives a rebase-merge;
the commits interleave with a cron delivery-ledger rework that the salvage removes in
follow-up commits, so per-commit cherry-picks were not practical.

Adds display.suppress_warning_notifications (global + per-platform, default false):
one resolver (gateway/warning_notifications.py), BasePlatformAdapter.emit_warning /
emit_media_warning / warning_text, a notification_category classification carried
through wakes, queues and persistence, and render/present boundaries for CLI/TUI.
2026-09-18 01:43:35 +05:30

43 lines
2.1 KiB
Python

"""Shared channel warning boundary: policy, actual receipt, and stream isolation."""
import json
from unittest.mock import AsyncMock
import pytest
from gateway.platforms.base import SendResult
from tests.gateway.test_session_hygiene import HygieneCaptureAdapter
@pytest.mark.asyncio
@pytest.mark.parametrize("setting", [None, False, True])
async def test_emit_warning_preserves_transport_receipt_and_input_metadata(tmp_path, monkeypatch, setting):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
monkeypatch.setenv("HERMES_MANAGED_DIR", str(tmp_path / "managed"))
cfg = {} if setting is None else {"display": {"suppress_warning_notifications": setting}}
(tmp_path / "config.yaml").write_text(json.dumps(cfg))
adapter = HygieneCaptureAdapter()
failure = SendResult(success=False, error="fixture transport rejection")
adapter.send = AsyncMock(return_value=failure)
metadata = {"thread_id": "123"}
result = await adapter.emit_warning("chat", "diagnostic", reply_to="456", metadata=metadata)
assert metadata == {"thread_id": "123"}
if setting is True:
assert result is None # explicitly not a successful transport receipt
adapter.send.assert_not_awaited()
else:
assert result is failure
assert adapter.send.await_args.kwargs["metadata"] == {"thread_id": "123"}
assert adapter.send.await_args.kwargs["reply_to"] == "456"
@pytest.mark.asyncio
async def test_emit_warning_uses_logical_override_and_does_not_swallow_send_error(tmp_path, monkeypatch):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
monkeypatch.setenv("HERMES_MANAGED_DIR", str(tmp_path / "managed"))
(tmp_path / "config.yaml").write_text(json.dumps({"display": {
"suppress_warning_notifications": True,
"platforms": {"slack": {"suppress_warning_notifications": False}}}}))
adapter = HygieneCaptureAdapter()
adapter.send = AsyncMock(side_effect=RuntimeError("fixture transport failure"))
with pytest.raises(RuntimeError, match="fixture transport failure"):
await adapter.emit_warning("chat", "diagnostic", logical_platform="slack")