feat: 首推理由行加 DAILY_FEATURED_REASON 开关
pick_why 本已渲染,现加开关默认开,空则省略(T6)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import re
|
import re
|
||||||
from typing import Any
|
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.localize import LocalizeJob, localize_brief_descriptions, needs_chinese
|
||||||
from daily.skills_group import group_skills_by_source
|
from daily.skills_group import group_skills_by_source
|
||||||
from daily.text_utils import trim_brief
|
from daily.text_utils import trim_brief
|
||||||
@@ -1096,7 +1096,8 @@ def build_wecom_report(
|
|||||||
|
|
||||||
lines.append(f"{ICONS['pick']} **今日首推**")
|
lines.append(f"{ICONS['pick']} **今日首推**")
|
||||||
lines.append(_format_pick_link(pick_command, title=pick_title, url=pick_url))
|
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}")
|
lines.append(f"> {pick_why}")
|
||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|||||||
55
tests/test_featured_reason.py
Normal file
55
tests/test_featured_reason.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user