修正北京时间并更换新闻候选源

This commit is contained in:
Codex
2026-07-08 23:08:55 +08:00
parent 3ece2327c8
commit 88e1cf4b7a
10 changed files with 178 additions and 55 deletions
+2
View File
@@ -23,3 +23,5 @@ def test_github_client_maps_repository_to_signal() -> None:
assert signal.source_url == "https://github.com/example/agent-kit"
assert "2400 stars" in signal.summary
assert "2026-05-01" in signal.summary
assert signal.published_at is not None
assert signal.published_at.hour == 17
+10 -6
View File
@@ -5,18 +5,22 @@ from app.integrations.news_search_client import NewsSearchClient
def test_news_search_client_maps_article_to_candidate() -> None:
# 新闻搜索结果会先转为候选信号,再交给模型筛选成最终情报。
client = NewsSearchClient(Settings())
signal = client._article_to_signal(
signal = client._story_to_signal(
{
"title": "AI agent platform launches",
"title": "Show HN: AI agent platform launches",
"url": "https://example.com/ai-agent-platform",
"domain": "example.com",
"sourcecountry": "US",
"seendate": "20260708T120000Z",
"author": "builder",
"points": 128,
"num_comments": 24,
"created_at": "2026-07-08T12:00:00Z",
"objectID": "123",
}
)
assert signal is not None
assert signal.topic == "AI 新闻候选"
assert signal.source_name == "example.com"
assert signal.source_name == "Hacker News"
assert signal.published_at is not None
assert signal.published_at.year == 2026
assert signal.published_at.hour == 20
assert "128 points" in signal.summary
+23
View File
@@ -0,0 +1,23 @@
from datetime import datetime, timezone
from app.core.timezone import beijing_now, beijing_today, to_beijing_naive
def test_beijing_now_returns_naive_business_time() -> None:
# 数据库存储无时区时间,业务层写入前统一生成北京时间。
current = beijing_now()
assert current.tzinfo is None
def test_beijing_today_returns_date() -> None:
# 日报业务日期只需要日期部分,由北京时间统一决定。
assert beijing_today().isoformat()
def test_to_beijing_naive_converts_utc_time() -> None:
# 外部UTC时间进入数据库前要先换算成北京时间,避免前端显示少8小时。
current = to_beijing_naive(datetime(2026, 7, 8, 14, 46, tzinfo=timezone.utc))
assert current.tzinfo is None
assert current.hour == 22