From 020bd6614bde542278d5d2e3938615a4355f5a1a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 12 May 2026 14:34:58 -0400 Subject: [PATCH] test(journal): cover closeout skip paths (no conv / prep-only / sentinel) Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_journal_closeout.py | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/test_journal_closeout.py b/tests/test_journal_closeout.py index c7e81fd..3ef2be8 100644 --- a/tests/test_journal_closeout.py +++ b/tests/test_journal_closeout.py @@ -111,3 +111,54 @@ async def test_run_for_user_happy_path_appends_bullets(): await journal_closeout.run_for_user(user_id=42, yesterday=yesterday) mock_append.assert_awaited_once_with(42, "- User skips news section") + + +@pytest.mark.asyncio +async def test_run_for_user_skips_when_no_conversation(): + from fabledassistant.services import journal_closeout + + with ( + patch.object(journal_closeout, "async_session", return_value=_patch_db([], conv=None)), + patch.object(journal_closeout, "append_observations", new=AsyncMock()) as mock_append, + patch.object(journal_closeout, "generate_completion", new=AsyncMock()) as mock_llm, + ): + await journal_closeout.run_for_user(user_id=42, yesterday=datetime.date(2026, 5, 11)) + + mock_append.assert_not_awaited() + mock_llm.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_run_for_user_skips_when_only_prep_message_after_filter(): + """If only the daily_prep message exists, the in-Python filter pass + leaves zero messages and we short-circuit before the LLM.""" + from fabledassistant.services import journal_closeout + + msgs_post_sql = [ + _msg("assistant", "Daily prep block.", kind="daily_prep"), + ] + with ( + patch.object(journal_closeout, "async_session", return_value=_patch_db(msgs_post_sql, conv=_fake_conv())), + patch.object(journal_closeout, "append_observations", new=AsyncMock()) as mock_append, + patch.object(journal_closeout, "generate_completion", new=AsyncMock()) as mock_llm, + ): + await journal_closeout.run_for_user(user_id=42, yesterday=datetime.date(2026, 5, 11)) + + mock_append.assert_not_awaited() + mock_llm.assert_not_awaited() + + +@pytest.mark.asyncio +async def test_run_for_user_respects_nothing_to_note_sentinel(): + from fabledassistant.services import journal_closeout + + msgs = [_msg("user", "hi"), _msg("assistant", "hi back")] + with ( + patch.object(journal_closeout, "async_session", return_value=_patch_db(msgs, conv=_fake_conv())), + patch.object(journal_closeout, "get_setting", new=AsyncMock(return_value="bg-model")), + patch.object(journal_closeout, "generate_completion", new=AsyncMock(return_value="(nothing to note)")), + patch.object(journal_closeout, "append_observations", new=AsyncMock()) as mock_append, + ): + await journal_closeout.run_for_user(user_id=42, yesterday=datetime.date(2026, 5, 11)) + + mock_append.assert_not_awaited()