feat(ai_news): router forwards mapping stats to telegram

This commit is contained in:
2026-05-14 02:13:06 +09:00
parent 19aed304cb
commit b3fac4f442
2 changed files with 5 additions and 4 deletions

View File

@@ -309,6 +309,7 @@ async def post_refresh_news_sentiment(asof: Optional[str] = None):
top_pos=summary["top_pos"], top_neg=summary["top_neg"], top_pos=summary["top_pos"], top_neg=summary["top_neg"],
tokens_input=summary["tokens_input"], tokens_input=summary["tokens_input"],
tokens_output=summary["tokens_output"], tokens_output=summary["tokens_output"],
mapping=summary.get("mapping"),
) )
return summary return summary

View File

@@ -20,17 +20,17 @@ def test_refresh_news_sentiment_weekday_invokes_pipeline():
"asof": "2026-05-13", "updated": 3, "failures": [], "asof": "2026-05-13", "updated": 3, "failures": [],
"duration_sec": 1.0, "tokens_input": 100, "tokens_output": 20, "duration_sec": 1.0, "tokens_input": 100, "tokens_output": 20,
"top_pos": [], "top_neg": [], "model": "m", "top_pos": [], "top_neg": [], "model": "m",
"mapping": {"total_articles": 5, "matched_pairs": 8, "hit_tickers": 3},
} }
with patch("app.screener.router._ai_pipeline") as mp, \ with patch("app.screener.router._ai_pipeline") as mp, \
patch("app.screener.router._ai_telegram") as mt: patch("app.screener.router._ai_telegram") as mt:
mp.refresh_daily = AsyncMock(return_value=fake_summary) mp.refresh_daily = AsyncMock(return_value=fake_summary)
mt.build_message = lambda **kw: "BUILT_TEXT" mt.build_message = lambda **kw: f"TEXT_with_mapping={kw.get('mapping')}"
client = TestClient(app) client = TestClient(app)
resp = client.post( resp = client.post(
"/api/stock/screener/snapshot/refresh-news-sentiment?asof=2026-05-13" "/api/stock/screener/snapshot/refresh-news-sentiment?asof=2026-05-13"
) )
assert resp.status_code == 200 assert resp.status_code == 200
body = resp.json() body = resp.json()
assert body["asof"] == "2026-05-13" assert body["mapping"]["hit_tickers"] == 3
assert body["updated"] == 3 assert "mapping=" in body["telegram_text"]
assert body["telegram_text"] == "BUILT_TEXT"