552943d6c0
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""Tests for journal closeout extraction helpers."""
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
|
def _msg(role: str, content: str, kind: str | None = None):
|
|
"""Build a Message-like stand-in for the filter helpers."""
|
|
metadata = {"kind": kind} if kind else None
|
|
return SimpleNamespace(role=role, content=content, msg_metadata=metadata)
|
|
|
|
|
|
def test_filter_excludes_daily_prep_messages():
|
|
from fabledassistant.services.journal_closeout import _filter_messages
|
|
|
|
msgs = [
|
|
_msg("assistant", "Good morning — here is today's plan…", kind="daily_prep"),
|
|
_msg("user", "I want to focus on the auth refactor today."),
|
|
_msg("assistant", "Got it. I'll keep tool calls quiet."),
|
|
]
|
|
kept = _filter_messages(msgs)
|
|
contents = [m.content for m in kept]
|
|
assert "Good morning — here is today's plan…" not in contents
|
|
assert "I want to focus on the auth refactor today." in contents
|
|
assert "Got it. I'll keep tool calls quiet." in contents
|
|
|
|
|
|
def test_build_transcript_labels_roles_and_caps_content():
|
|
from fabledassistant.services.journal_closeout import _build_transcript
|
|
|
|
msgs = [
|
|
_msg("user", "hello"),
|
|
_msg("assistant", "hi"),
|
|
_msg("user", "x" * 600),
|
|
]
|
|
out = _build_transcript(msgs)
|
|
lines = out.splitlines()
|
|
assert lines[0] == "USER: hello"
|
|
assert lines[1] == "ASSISTANT: hi"
|
|
# Third line content truncated to 500 chars
|
|
assert lines[2].startswith("USER: ")
|
|
assert len(lines[2]) == len("USER: ") + 500
|
|
|
|
|
|
def test_build_transcript_keeps_only_last_20_messages():
|
|
from fabledassistant.services.journal_closeout import _build_transcript
|
|
|
|
msgs = [_msg("user", f"msg-{i}") for i in range(30)]
|
|
out = _build_transcript(msgs)
|
|
lines = out.splitlines()
|
|
assert len(lines) == 20
|
|
# Newest 20 means msg-10 through msg-29
|
|
assert lines[0] == "USER: msg-10"
|
|
assert lines[-1] == "USER: msg-29"
|
|
|
|
|
|
def test_system_prompt_lists_structured_fields_to_exclude():
|
|
"""The prompt must explicitly tell the LLM not to restate structured
|
|
fields, so the freeform learned_summary stays a narrow lane."""
|
|
from fabledassistant.services.journal_closeout import SYSTEM_PROMPT
|
|
|
|
text = SYSTEM_PROMPT.lower()
|
|
for field in ("name", "job title", "industry", "expertise", "response style", "tone", "interests"):
|
|
assert field in text, f"system prompt should mention '{field}'"
|
|
assert "(nothing to note)" in SYSTEM_PROMPT
|