feat: 23:00 daily news recap; prompts drop futures
Summarizer still runs the 15-min analyst, plus a 24h breaking-news recap at 23:00 America/New_York. HUD pins kind=daily_recap. Prompts ignore futures/market tape.
This commit is contained in:
parent
d25ca8ed9c
commit
49ee5fe7a3
16 changed files with 431 additions and 75 deletions
11
news/summerizer/tests/conftest.py
Normal file
11
news/summerizer/tests/conftest.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"""Keep summarizer unit tests importable without Postgres drivers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
if "psycopg2" not in sys.modules:
|
||||
fake = ModuleType("psycopg2")
|
||||
fake.connect = lambda **kwargs: None # type: ignore[attr-defined]
|
||||
sys.modules["psycopg2"] = fake
|
||||
32
news/summerizer/tests/test_prompts.py
Normal file
32
news/summerizer/tests/test_prompts.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""Default prompts: breaking news, ignore futures/market tape."""
|
||||
|
||||
from summarizer import MAP_PROMPT_DEFAULT, RECAP_PROMPT_DEFAULT, SUMMARY_PROMPT_DEFAULT
|
||||
|
||||
|
||||
def _assert_breaking_not_futures(prompt: str) -> None:
|
||||
p = prompt.lower()
|
||||
assert "breaking" in p
|
||||
assert "futures" in p
|
||||
assert "ignore" in p or "do not" in p or "not" in p
|
||||
assert "es=f" not in p
|
||||
assert "yfinance" not in p
|
||||
|
||||
|
||||
def test_map_prompt_focuses_on_breaking_news_not_futures():
|
||||
_assert_breaking_not_futures(MAP_PROMPT_DEFAULT)
|
||||
|
||||
|
||||
def test_summary_prompt_focuses_on_breaking_news_not_futures():
|
||||
_assert_breaking_not_futures(SUMMARY_PROMPT_DEFAULT)
|
||||
p = SUMMARY_PROMPT_DEFAULT.lower()
|
||||
assert "commodity" in p or "market" in p
|
||||
|
||||
|
||||
def test_recap_prompt_is_daily_24h_breaking_news():
|
||||
p = RECAP_PROMPT_DEFAULT.lower()
|
||||
_assert_breaking_not_futures(RECAP_PROMPT_DEFAULT)
|
||||
assert "daily" in p
|
||||
assert "24" in p
|
||||
assert "summary_en" in p
|
||||
assert "ticker" in p
|
||||
assert "map_items" in p
|
||||
42
news/summerizer/tests/test_scheduler.py
Normal file
42
news/summerizer/tests/test_scheduler.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""Wall-clock scheduling: 15-min analyst + 23:00 America/New_York recap."""
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from run_news_summarizer import next_event, next_recap_datetime
|
||||
|
||||
TZ = ZoneInfo("America/New_York")
|
||||
|
||||
|
||||
def test_next_recap_is_11pm_same_day_before_2300():
|
||||
now = datetime(2026, 8, 28, 15, 4, tzinfo=TZ)
|
||||
got = next_recap_datetime(now)
|
||||
assert got == datetime(2026, 8, 28, 23, 0, tzinfo=TZ)
|
||||
|
||||
|
||||
def test_next_recap_is_11pm_next_day_at_or_after_2300():
|
||||
now = datetime(2026, 8, 28, 23, 0, tzinfo=TZ)
|
||||
got = next_recap_datetime(now)
|
||||
assert got == datetime(2026, 8, 29, 23, 0, tzinfo=TZ)
|
||||
|
||||
|
||||
def test_next_recap_honors_custom_hour():
|
||||
now = datetime(2026, 8, 28, 10, 0, tzinfo=TZ)
|
||||
got = next_recap_datetime(now, hour=22, minute=30)
|
||||
assert got == datetime(2026, 8, 28, 22, 30, tzinfo=TZ)
|
||||
|
||||
|
||||
def test_next_event_picks_recap_when_sooner_than_interval():
|
||||
now = datetime(2026, 8, 28, 22, 50, tzinfo=TZ)
|
||||
last_periodic = now - timedelta(seconds=100)
|
||||
when, kind = next_event(now, last_periodic=last_periodic, interval_s=900)
|
||||
assert kind == "recap"
|
||||
assert when == datetime(2026, 8, 28, 23, 0, tzinfo=TZ)
|
||||
|
||||
|
||||
def test_next_event_picks_interval_when_recap_is_hours_away():
|
||||
now = datetime(2026, 8, 28, 10, 0, tzinfo=TZ)
|
||||
last_periodic = now
|
||||
when, kind = next_event(now, last_periodic=last_periodic, interval_s=900)
|
||||
assert kind == "interval"
|
||||
assert when == now + timedelta(seconds=900)
|
||||
45
news/summerizer/tests/test_summarizer.py
Normal file
45
news/summerizer/tests/test_summarizer.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""Summarizer window, recap flag, and no futures injection into prompts."""
|
||||
|
||||
from summarizer import (
|
||||
build_map_prompt,
|
||||
build_master_prompt,
|
||||
effective_window_minutes,
|
||||
is_recap_run,
|
||||
)
|
||||
|
||||
|
||||
def test_interval_window_defaults_to_15_minutes(monkeypatch):
|
||||
monkeypatch.delenv("NEWS_RECAP", raising=False)
|
||||
monkeypatch.delenv("SUMMARY_WINDOW_HOURS", raising=False)
|
||||
monkeypatch.setenv("SUMMARY_WINDOW_MINUTES", "15")
|
||||
assert is_recap_run() is False
|
||||
assert effective_window_minutes() == 15
|
||||
|
||||
|
||||
def test_recap_window_is_24_hours(monkeypatch):
|
||||
monkeypatch.setenv("NEWS_RECAP", "1")
|
||||
monkeypatch.setenv("SUMMARY_WINDOW_MINUTES", "15")
|
||||
assert is_recap_run() is True
|
||||
assert effective_window_minutes() == 24 * 60
|
||||
|
||||
|
||||
def test_build_map_prompt_does_not_inject_futures():
|
||||
prompt = build_map_prompt(
|
||||
[{"title": "Blast", "domain": "ex.com", "url": "https://ex.com/1", "content": "x" * 120}]
|
||||
)
|
||||
assert "FUTURES PRICES" not in prompt
|
||||
assert "ES=F" not in prompt
|
||||
assert "Blast" in prompt
|
||||
|
||||
|
||||
def test_build_master_prompt_interval_uses_summary_not_recap():
|
||||
prompt = build_master_prompt("partial facts", recap=False)
|
||||
assert "partial facts" in prompt
|
||||
assert "daily recap" not in prompt.lower()
|
||||
|
||||
|
||||
def test_build_master_prompt_recap_uses_daily_template():
|
||||
prompt = build_master_prompt("partial facts", recap=True)
|
||||
assert "partial facts" in prompt
|
||||
assert "daily recap" in prompt.lower()
|
||||
assert "24" in prompt
|
||||
Loading…
Reference in a new issue