digest: factor tone clause; kw-only digest helper; empty-data test

This commit is contained in:
Giorgio Gilestro 2026-05-25 23:00:07 +02:00
parent ca6b174b51
commit 1391f15c28
2 changed files with 39 additions and 15 deletions

View file

@ -46,3 +46,19 @@ def test_prompts_return_strings():
sys_, usr = fn(tone="INTERMEDIATE", **_ctx())
assert isinstance(sys_, str) and isinstance(usr, str)
assert len(sys_) > 50 and len(usr) > 50
def test_prompts_tolerate_empty_data():
"""No quotes, no headlines — builders must still produce non-empty
prompts without raising. Guards the `if headlines_by_bucket` and
`if quotes_by_group` branches in _digest_user_prompt."""
empty_ctx = dict(
today=datetime(2026, 5, 25, 6, 30, tzinfo=timezone.utc),
quotes_by_group={},
headlines_by_bucket={},
reference_line="S&P 7,501 (ATH)",
)
for fn in (build_daily_digest_prompt, build_weekly_digest_prompt):
sys_, usr = fn(tone="INTERMEDIATE", **empty_ctx)
assert "S&P 7,501" in usr
assert len(sys_) > 50