feat(journal): closeout catch-up on startup when slot already passed
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -202,3 +202,48 @@ async def test_update_user_schedule_does_not_register_closeout_when_disabled(mon
|
||||
|
||||
added = [c.kwargs.get("id") for c in fake_scheduler.add_job.call_args_list]
|
||||
assert "journal_closeout_7" not in added
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_closeout_catchup_skips_when_already_have_entry(monkeypatch):
|
||||
from fabledassistant.services import journal_scheduler as sched
|
||||
|
||||
monkeypatch.setattr(sched, "get_user_timezone", AsyncMock(return_value="UTC"))
|
||||
monkeypatch.setattr(sched, "get_journal_config", AsyncMock(return_value={
|
||||
"closeout_enabled": True,
|
||||
"day_rollover_hour": 0, # slot has always passed
|
||||
}))
|
||||
yesterday = (datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1)).date()
|
||||
fake_profile = SimpleNamespace(observations_raw=[{"date": yesterday.isoformat(), "bullets": "..."}])
|
||||
|
||||
from fabledassistant.services import user_profile as up
|
||||
monkeypatch.setattr(up, "get_profile", AsyncMock(return_value=fake_profile))
|
||||
|
||||
run_mock = AsyncMock()
|
||||
from fabledassistant.services import journal_closeout as jc
|
||||
monkeypatch.setattr(jc, "run_for_user", run_mock)
|
||||
|
||||
await sched._closeout_catchup(user_id=7)
|
||||
run_mock.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_closeout_catchup_runs_when_no_entry_yet(monkeypatch):
|
||||
from fabledassistant.services import journal_scheduler as sched
|
||||
|
||||
monkeypatch.setattr(sched, "get_user_timezone", AsyncMock(return_value="UTC"))
|
||||
monkeypatch.setattr(sched, "get_journal_config", AsyncMock(return_value={
|
||||
"closeout_enabled": True,
|
||||
"day_rollover_hour": 0,
|
||||
}))
|
||||
fake_profile = SimpleNamespace(observations_raw=[])
|
||||
|
||||
from fabledassistant.services import user_profile as up
|
||||
monkeypatch.setattr(up, "get_profile", AsyncMock(return_value=fake_profile))
|
||||
|
||||
run_mock = AsyncMock()
|
||||
from fabledassistant.services import journal_closeout as jc
|
||||
monkeypatch.setattr(jc, "run_for_user", run_mock)
|
||||
|
||||
await sched._closeout_catchup(user_id=7)
|
||||
run_mock.assert_awaited_once()
|
||||
|
||||
Reference in New Issue
Block a user