Files
DECNET/tests/orchestrator/emailgen/test_events.py
anti 0b9873982d refactor(realism): move emailgen LLM/personas/prompt into shared library
Lift the format-agnostic pieces from decnet/orchestrator/emailgen/
into the new decnet/realism/ library so file-class content generation
(stage 3 of the realism migration) can reuse them. Email-specific
delivery (RFC 2822 EML, IMAP/POP3 spool, thread chains) stays in
orchestrator/.

Renames (history-preserving git mv):
  emailgen/personas.py     -> realism/personas.py
  emailgen/prompt.py       -> realism/prompts/email.py
  emailgen/global_pool.py  -> realism/personas_pool.py
  emailgen/llm/            -> realism/llm/

Env-var clean break (pre-v1, no aliases):
  DECNET_EMAILGEN_LLM      -> DECNET_REALISM_LLM
  DECNET_EMAILGEN_MODEL    -> DECNET_REALISM_MODEL
  DECNET_EMAILGEN_TIMEOUT  -> DECNET_REALISM_TIMEOUT
  DECNET_EMAILGEN_PERSONAS -> DECNET_REALISM_PERSONAS
  DECNET_EMAILGEN_FAKE_OUTPUT -> DECNET_REALISM_FAKE_OUTPUT

Importers rewritten in: orchestrator/emailgen/scheduler.py,
orchestrator/drivers/email.py, web/router/{emailgen,topology}/
api_personas.py, cli/emailgen.py. Tests for moved modules relocated
to tests/realism/; tests for stay-put modules updated in place.

API URL `/api/v1/emailgen/personas` and CLI `decnet emailgen
import-personas` keep their public names until the service-collapse
commit (stage 5).
2026-04-27 16:05:43 -04:00

73 lines
2.2 KiB
Python

"""events.to_row / topic_for / event_type_for."""
from __future__ import annotations
from decnet.bus import topics as _topics
from decnet.orchestrator.drivers.base import ActivityResult
from decnet.orchestrator.emailgen import events
from decnet.realism.personas import EmailPersona
from decnet.orchestrator.emailgen.scheduler import EmailAction
def _persona(email="john@corp.com"):
return EmailPersona(
name="John", email=email, role="COO", tone="formal",
mannerisms=[], language="en",
)
def _action():
return EmailAction(
mail_decky_uuid="d1",
mail_decky_name="mailhost",
mail_decky_services=("imap",),
sender=_persona(),
recipient=_persona(email="sarah@corp.com"),
thread_id="thr1",
parent_message_id=None,
references="",
subject_hint=None,
parent_excerpt=None,
context_hint="Q3 budget",
is_reply=False,
)
def test_to_row_pulls_message_id_subject_from_payload():
res = ActivityResult(
success=True,
payload={
"message_id": "<m1@corp.com>",
"subject": "Q3 budget",
"language": "en",
"eml_path": "/var/spool/decnet-emails/thr1/m1.eml",
"model": "llama3.1",
},
)
row = events.to_row(_action(), res)
assert row["mail_decky_uuid"] == "d1"
assert row["thread_id"] == "thr1"
assert row["message_id"] == "<m1@corp.com>"
assert row["subject"] == "Q3 budget"
assert row["sender_email"] == "john@corp.com"
assert row["recipient_email"] == "sarah@corp.com"
assert row["language"] == "en"
assert row["eml_path"].endswith(".eml")
assert row["success"] is True
assert row["payload"]["model"] == "llama3.1"
def test_to_row_falls_back_to_persona_language():
res = ActivityResult(success=True, payload={})
row = events.to_row(_action(), res)
assert row["language"] == "en"
assert row["message_id"] == ""
def test_topic_for_uses_orchestrator_email_root():
topic = events.topic_for(_action())
assert topic == f"orchestrator.{_topics.ORCHESTRATOR_EMAIL}.d1"
def test_event_type_for_returns_email_constant():
assert events.event_type_for(_action()) == _topics.ORCHESTRATOR_EMAIL