feat: memory_write enqueues embedding job after each memory_written (T97.2)
This commit is contained in:
@@ -540,3 +540,49 @@ def test_record_turn_memory_you_present_false_requires_guest(tmp_path):
|
||||
narrative_text="invalid",
|
||||
you_present=False,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# T97: embedding-worker enqueue hook.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_record_turn_memory_enqueues_embedding_job(tmp_path):
|
||||
"""When ``app.state.embedding_worker`` is wired, every per-witness
|
||||
write enqueues an :class:`EmbeddingJob` carrying the freshly-projected
|
||||
memory id and the narrative text. Two-bot turn -> two jobs."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from chat.services.embedding_worker import EmbeddingJob
|
||||
|
||||
db = tmp_path / "t.db"
|
||||
apply_migrations(db)
|
||||
_seed_two_bots(db)
|
||||
|
||||
captured: list[EmbeddingJob] = []
|
||||
|
||||
class _StubWorker:
|
||||
def enqueue(self, job: EmbeddingJob) -> None:
|
||||
captured.append(job)
|
||||
|
||||
fake_app = SimpleNamespace(
|
||||
state=SimpleNamespace(embedding_worker=_StubWorker())
|
||||
)
|
||||
|
||||
with open_db(db) as conn:
|
||||
result = record_turn_memory_for_present(
|
||||
conn,
|
||||
chat_id="chat_ab",
|
||||
host_bot_id="bot_a",
|
||||
guest_bot_id="bot_b",
|
||||
narrative_text="Both bots witness this beat.",
|
||||
app=fake_app,
|
||||
)
|
||||
|
||||
# One job per witness — host first, then guest (matches result dict
|
||||
# insertion order in record_turn_memory_for_present).
|
||||
assert len(captured) == 2
|
||||
expected_ids = {result["bot_a"][1], result["bot_b"][1]}
|
||||
assert {job.memory_id for job in captured} == expected_ids
|
||||
for job in captured:
|
||||
assert job.text == "Both bots witness this beat."
|
||||
|
||||
Reference in New Issue
Block a user