Add outbound message opt-in for apprise

This commit is contained in:
Jack Kingsman
2026-06-11 20:42:29 -07:00
parent 907a0e4d14
commit fb848d2e8d
7 changed files with 199 additions and 11 deletions
+32 -3
View File
@@ -1017,7 +1017,7 @@ class TestAppriseModule:
assert mod.status == "connected"
@pytest.mark.asyncio
async def test_skips_outgoing_messages(self):
async def test_skips_outgoing_messages_by_default(self):
from unittest.mock import patch as _patch
from app.fanout.apprise_mod import AppriseModule
@@ -1027,6 +1027,19 @@ class TestAppriseModule:
await mod.on_message({"type": "PRIV", "text": "hi", "outgoing": True})
mock_send.assert_not_called()
@pytest.mark.asyncio
async def test_sends_outgoing_messages_when_enabled(self):
from unittest.mock import patch as _patch
from app.fanout.apprise_mod import AppriseModule
mod = AppriseModule("test", {"urls": "json://localhost", "include_outgoing": True})
with _patch("app.fanout.apprise_mod._send_sync", return_value=True) as mock_send:
await mod.on_message(
{"type": "PRIV", "text": "hi", "outgoing": True, "sender_name": "Me"}
)
mock_send.assert_called_once()
@pytest.mark.asyncio
async def test_sends_for_incoming_messages(self):
from unittest.mock import patch as _patch
@@ -1379,10 +1392,26 @@ class TestAppriseValidation:
_validate_apprise_config(config)
assert config["markdown_format"] is False
def test_validate_apprise_config_works_without_markdown_format(self):
def test_validate_apprise_config_defaults_markdown_format_true(self):
from app.routers.fanout import _validate_apprise_config
_validate_apprise_config({"urls": "discord://123/abc"})
config: dict = {"urls": "discord://123/abc"}
_validate_apprise_config(config)
assert config["markdown_format"] is True
def test_validate_apprise_config_defaults_include_outgoing_false(self):
from app.routers.fanout import _validate_apprise_config
config: dict = {"urls": "discord://123/abc"}
_validate_apprise_config(config)
assert config["include_outgoing"] is False
def test_validate_apprise_config_normalizes_include_outgoing(self):
from app.routers.fanout import _validate_apprise_config
config: dict = {"urls": "discord://123/abc", "include_outgoing": 1}
_validate_apprise_config(config)
assert config["include_outgoing"] is True
class TestAppriseMarkdownFormat:
+41 -2
View File
@@ -1247,8 +1247,8 @@ class TestFanoutAppriseIntegration:
assert "#general" in body_text
@pytest.mark.asyncio
async def test_apprise_skips_outgoing(self, apprise_capture_server, integration_db):
"""Apprise should NOT deliver outgoing messages."""
async def test_apprise_skips_outgoing_by_default(self, apprise_capture_server, integration_db):
"""Apprise should NOT deliver outgoing messages unless explicitly enabled."""
cfg = await FanoutConfigRepository.create(
config_type="apprise",
name="No Outgoing",
@@ -1280,6 +1280,45 @@ class TestFanoutAppriseIntegration:
assert len(apprise_capture_server.received) == 0
@pytest.mark.asyncio
async def test_apprise_delivers_outgoing_when_enabled(
self, apprise_capture_server, integration_db
):
"""Apprise can opt in to delivering RemoteTerm-originated messages."""
cfg = await FanoutConfigRepository.create(
config_type="apprise",
name="Include Outgoing",
config={
"urls": f"json://127.0.0.1:{apprise_capture_server.port}",
"include_outgoing": True,
},
scope={"messages": "all", "raw_packets": "none"},
enabled=True,
)
manager = FanoutManager()
try:
await manager.load_from_db()
assert cfg["id"] in manager._modules
await manager.broadcast_message(
{
"type": "PRIV",
"conversation_key": "pk1",
"text": "my outgoing",
"sender_name": "Me",
"outgoing": True,
}
)
results = await apprise_capture_server.wait_for(1)
finally:
await manager.stop_all()
assert len(results) >= 1
body_text = str(results[0])
assert "my outgoing" in body_text
@pytest.mark.asyncio
async def test_apprise_disabled_no_delivery(self, apprise_capture_server, integration_db):
"""Disabled Apprise module should not deliver anything."""