From 3321a307a0fcf19e2d19de6ec2df80debe972404 Mon Sep 17 00:00:00 2001 From: yumao Date: Sat, 18 Jul 2026 16:53:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E6=8E=A8=E7=90=86=E7=94=B1?= =?UTF-8?q?=E8=A1=8C=E5=8A=A0=20DAILY=5FFEATURED=5FREASON=20=E5=BC=80?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pick_why 本已渲染,现加开关默认开,空则省略(T6)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- daily/format_wecom.py | 5 ++-- tests/test_featured_reason.py | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/test_featured_reason.py diff --git a/daily/format_wecom.py b/daily/format_wecom.py index b6bcc7e..e09486e 100644 --- a/daily/format_wecom.py +++ b/daily/format_wecom.py @@ -5,7 +5,7 @@ from __future__ import annotations import re from typing import Any -from daily.config import wecom_skill_desc_limit +from daily.config import env_bool, wecom_skill_desc_limit from daily.localize import LocalizeJob, localize_brief_descriptions, needs_chinese from daily.skills_group import group_skills_by_source from daily.text_utils import trim_brief @@ -1096,7 +1096,8 @@ def build_wecom_report( lines.append(f"{ICONS['pick']} **今日首推**") lines.append(_format_pick_link(pick_command, title=pick_title, url=pick_url)) - if pick_why: + # 首推「为什么值得点开」一句理由; DAILY_FEATURED_REASON=0 关闭, 空则省略 + if pick_why and env_bool("DAILY_FEATURED_REASON", True): lines.append(f"> {pick_why}") return "\n".join(lines) diff --git a/tests/test_featured_reason.py b/tests/test_featured_reason.py new file mode 100644 index 0000000..a36b366 --- /dev/null +++ b/tests/test_featured_reason.py @@ -0,0 +1,55 @@ +# tests/test_featured_reason.py +"""T6: 首推理由行(pick_why + DAILY_FEATURED_REASON 开关)测试。""" +from __future__ import annotations + +import unittest +from unittest import mock + +import daily.format_wecom as fw + + +def _build(pick_why: str) -> str: + return fw.build_wecom_report( + date_str="2026-07-18", + time_str="08:50 (UTC+8)", + updated="2026-07-18", + highlights=[], + theme_line="**今日主题**:测试", + ai_news=None, + cn_ai_news=None, + merged_ai_news=None, + merged_tech_ai_news=None, + trending=[], + hot=[], + repos=[], + emerging=[], + topic_name="t", + topic_repos=[], + pick_command="npx skills add src/alpha", + pick_why=pick_why, + pick_title="alpha", + pick_url="https://x/a", + include_boards=False, + ) + + +class FeaturedReasonTests(unittest.TestCase): + def test_reason_shown_when_present_and_enabled(self): + with mock.patch.object(fw, "env_bool", return_value=True): + md = _build("昨日 star 增速第一") + self.assertIn("> 昨日 star 增速第一", md) + + def test_reason_hidden_when_switch_off(self): + with mock.patch.object(fw, "env_bool", return_value=False): + md = _build("昨日 star 增速第一") + self.assertNotIn("> 昨日 star 增速第一", md) + + def test_reason_omitted_when_empty(self): + with mock.patch.object(fw, "env_bool", return_value=True): + md = _build("") + self.assertIn("今日首推", md) + self.assertNotIn("> \n", md) + + +if __name__ == "__main__": + unittest.main()