fix: 关闭新闻放宽凑数并剥离放宽窗口文案

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-14 10:42:00 +08:00
parent dcd0608b5d
commit 4a128b0fa6
5 changed files with 712 additions and 92 deletions

62
tests/test_news_relax.py Normal file
View File

@@ -0,0 +1,62 @@
# tests/test_news_relax.py
from __future__ import annotations
import os
import unittest
from unittest.mock import patch
class NewsRelaxTests(unittest.TestCase):
def test_strip_relax_prefix(self):
from daily.news.sanitize import strip_relax_window_prefix
self.assertEqual(
strip_relax_window_prefix("放宽窗口:苹果起诉 OpenAI"),
"苹果起诉 OpenAI",
)
self.assertEqual(
strip_relax_window_prefix("放宽至48小时某新闻"),
"某新闻",
)
self.assertEqual(
strip_relax_window_prefix("正常摘要无前缀"),
"正常摘要无前缀",
)
def test_backfill_disabled_does_not_reinsert_pushed(self):
from daily.news.fetch import _apply_pushed_dedup_with_backfill
fresh_only = [
{
"link": "https://example.com/fresh",
"title": "fresh",
"source_name": "S",
"published_fmt": "07-14",
"desc_short": "",
"summary_plain": "",
}
]
picked = [
{
"link": "https://example.com/old",
"title": "old",
"source_name": "S",
"published": "2026-07-13T10:00:00+00:00",
"summary": "旧闻",
}
]
with patch("daily.news.pushed_links.filter_unpushed_items", return_value=list(fresh_only)):
with patch.dict(os.environ, {"DAILY_NEWS_BACKFILL": "0"}, clear=False):
out = _apply_pushed_dedup_with_backfill(
fresh_only + [{"link": "https://example.com/old", "title": "old"}],
picked,
date_str="2026-07-14",
limit=5,
)
links = [x.get("link") for x in out]
self.assertIn("https://example.com/fresh", links)
self.assertNotIn("https://example.com/old", links)
if __name__ == "__main__":
unittest.main()