feat(web): emailgen events in Orchestrator page
The SSE pipe at /orchestrator/events/stream was already streaming
'orchestrator.email.{decky_uuid}' events (the subscription is for the
'orchestrator.>' wildcard), but the consumer side dropped them on the
floor. Three fixes to close the loop:
* useOrchestratorStream.ts now registers an 'email' SSE listener — the
EventSource silently ignores frames whose event name has no listener,
so missing this entry meant every email frame was dropped before
reaching the page's onEvent handler.
* /api/v1/orchestrator/events accepts kind=email and dispatches to
list_orchestrator_emails, adapting rows to the existing wire shape:
subject -> action, sender_email -> src_decky_uuid, recipient_email
-> dst_decky_uuid, plus email-specific extras (thread_id, language,
mail_decky_uuid, message_id, in_reply_to) ride along as top-level
keys.
* Orchestrator.tsx gains an 'email' tab in the kind filter and a
branch in the row renderer / inspector that:
- shows full sender / recipient (no UUID truncation),
- chips the language code next to the subject,
- relabels ACTION as SUBJECT in the inspector and surfaces
thread / in-reply-to / mail-decky details.
The 'all' tab continues to show traffic+file only (today's behavior);
operators see emails by switching to the email tab. A union view at
the API layer is the obvious follow-up but not necessary for now.
This commit is contained in:
@@ -95,6 +95,77 @@ async def test_list_forwards_kind_filter():
|
||||
mock_repo.count_orchestrator_events.assert_awaited_once_with(kind="file")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_email_kind_dispatches_to_emails_table():
|
||||
from decnet.web.router.orchestrator.api_list_events import (
|
||||
list_orchestrator_events,
|
||||
)
|
||||
|
||||
raw_emails = [{
|
||||
"uuid": "em-1",
|
||||
"ts": "2026-04-26T12:00:00+00:00",
|
||||
"mail_decky_uuid": "mailhost-uuid",
|
||||
"thread_id": "thr-1",
|
||||
"message_id": "<m1@corp.com>",
|
||||
"in_reply_to": None,
|
||||
"sender_email": "john@corp.com",
|
||||
"recipient_email": "sarah@corp.com",
|
||||
"subject": "Q3 budget",
|
||||
"language": "en",
|
||||
"eml_path": "/var/spool/decnet-emails/thr-1/m1.eml",
|
||||
"success": True,
|
||||
"payload": "{\"model\":\"llama3.1\"}",
|
||||
}]
|
||||
with patch(
|
||||
"decnet.web.router.orchestrator.api_list_events.repo"
|
||||
) as mock_repo:
|
||||
mock_repo.list_orchestrator_emails = AsyncMock(return_value=raw_emails)
|
||||
mock_repo.count_orchestrator_emails = AsyncMock(return_value=1)
|
||||
# The events-table methods MUST NOT be touched when kind=email.
|
||||
mock_repo.list_orchestrator_events = AsyncMock(return_value=[])
|
||||
mock_repo.count_orchestrator_events = AsyncMock(return_value=999)
|
||||
|
||||
result = await list_orchestrator_events(
|
||||
limit=50, offset=0, kind="email",
|
||||
user={"uuid": "u", "role": "viewer"},
|
||||
)
|
||||
|
||||
assert result["total"] == 1
|
||||
mock_repo.list_orchestrator_events.assert_not_awaited()
|
||||
mock_repo.count_orchestrator_events.assert_not_awaited()
|
||||
|
||||
[row] = result["data"]
|
||||
assert row["kind"] == "email"
|
||||
assert row["protocol"] == "smtp"
|
||||
assert row["action"] == "Q3 budget"
|
||||
assert row["src_decky_uuid"] == "john@corp.com"
|
||||
assert row["dst_decky_uuid"] == "sarah@corp.com"
|
||||
assert row["success"] is True
|
||||
# Email-only extras must ride along so the inspector + future
|
||||
# per-email view can read them without a second round-trip.
|
||||
assert row["thread_id"] == "thr-1"
|
||||
assert row["language"] == "en"
|
||||
assert row["mail_decky_uuid"] == "mailhost-uuid"
|
||||
assert row["message_id"] == "<m1@corp.com>"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_list_rejects_unknown_kind():
|
||||
"""Regex on the Query() must not accept anything outside the
|
||||
{traffic, file, email} set."""
|
||||
async with httpx.AsyncClient(
|
||||
transport=httpx.ASGITransport(app=app), base_url="http://test",
|
||||
) as ac:
|
||||
# 401 (auth) takes precedence over 422 here, so we just check
|
||||
# the validation gate exists by checking against an authed
|
||||
# request would need a token. Instead, hit the regex via the
|
||||
# validator directly.
|
||||
r = await ac.get(f"{_V1}/events?kind=garbage")
|
||||
# Either 401 (auth first) or 422 (validation first); both are
|
||||
# rejections — what we forbid is a 200.
|
||||
assert r.status_code != 200
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_emits_snapshot_and_live_events(_fake_app_bus):
|
||||
from decnet.web.router.orchestrator import api_events as _ev
|
||||
|
||||
Reference in New Issue
Block a user