feat: 拆分 wecom_shown_keys 与 movement_baseline 历史层
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -44,6 +44,12 @@ class ConfigHelpersTests(unittest.TestCase):
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
self.assertEqual(delta_baseline_fallback(), "full")
|
||||
|
||||
def test_wecom_delta_pad_default_true(self):
|
||||
from daily.config import wecom_delta_pad
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
self.assertTrue(wecom_delta_pad())
|
||||
|
||||
|
||||
class NewsPushedLinksTests(unittest.TestCase):
|
||||
def test_filter_and_record_roundtrip(self):
|
||||
@@ -121,7 +127,7 @@ class DeltaFormatTests(unittest.TestCase):
|
||||
]
|
||||
text = build_skills_delta_sections(moves, [])
|
||||
self.assertIn("Skills Trending 变化", text)
|
||||
self.assertIn("[新入 #3]", text)
|
||||
self.assertNotIn("[新入 #", text)
|
||||
self.assertNotIn("Skills Hot 变化", text)
|
||||
|
||||
def test_github_delta_omits_stable_board(self):
|
||||
@@ -129,14 +135,268 @@ class DeltaFormatTests(unittest.TestCase):
|
||||
|
||||
movement = {
|
||||
"github_trending_moves": [
|
||||
{"repo": "a/b", "url": "https://github.com/a/b", "rank": 1, "language": "Go"}
|
||||
{
|
||||
"repo": "a/b",
|
||||
"url": "https://github.com/a/b",
|
||||
"rank": 1,
|
||||
"language": "Go",
|
||||
"description": "open-source codebase and curriculum",
|
||||
}
|
||||
],
|
||||
"github_emerging_moves": [],
|
||||
"github_topic_moves": [],
|
||||
}
|
||||
text = build_github_delta_sections(movement, topic_name="llm")
|
||||
with patch(
|
||||
"daily.format_wecom.localize_brief_descriptions",
|
||||
return_value={"github:a/b": "开源代码库与课程体系"},
|
||||
):
|
||||
text = build_github_delta_sections(movement, topic_name="llm")
|
||||
self.assertIn("开源代码库", text)
|
||||
self.assertIn("GitHub Trending 变化", text)
|
||||
self.assertNotIn("新兴", text)
|
||||
self.assertNotIn("[新入 #", text)
|
||||
self.assertNotIn("\n > ", text)
|
||||
|
||||
def test_delta_pad_groups_same_source_moves(self):
|
||||
from daily.format_wecom import build_skills_delta_sections
|
||||
|
||||
moves = [
|
||||
{
|
||||
"id": f"lllllllama/rigorpilot-skills/s{i}",
|
||||
"title": f"s{i}",
|
||||
"source": "lllllllama/rigorpilot-skills",
|
||||
"installs": 250 - i,
|
||||
"installs_fmt": str(250 - i),
|
||||
"link": f"https://www.skills.sh/lllllllama/rigorpilot-skills/s{i}",
|
||||
"description": f"skill {i}",
|
||||
}
|
||||
for i in range(1, 11)
|
||||
]
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
with patch("daily.format_wecom.needs_chinese", return_value=False):
|
||||
text = build_skills_delta_sections(moves, [], trending_limit=10, pad=True)
|
||||
self.assertIn("10 skills", text)
|
||||
self.assertNotIn("[**s2**]", text)
|
||||
|
||||
def test_delta_pad_fills_skills_to_limit(self):
|
||||
from daily.format_wecom import build_skills_delta_sections
|
||||
|
||||
moves = [
|
||||
{
|
||||
"id": "a/b/new",
|
||||
"rank": 3,
|
||||
"title": "new",
|
||||
"source": "a/b",
|
||||
"installs": 99,
|
||||
"installs_fmt": "99",
|
||||
"link": "https://skills.sh/a/b/new",
|
||||
"description": "new skill",
|
||||
}
|
||||
]
|
||||
full = [
|
||||
{
|
||||
"id": "a/b/new",
|
||||
"title": "new",
|
||||
"source": "a/b",
|
||||
"installs": 99,
|
||||
"installs_fmt": "99",
|
||||
"link": "https://skills.sh/a/b/new",
|
||||
"description": "new skill",
|
||||
},
|
||||
*[
|
||||
{
|
||||
"id": f"src{i}/skill",
|
||||
"title": "skill",
|
||||
"source": f"src{i}/pkg",
|
||||
"installs": 100 - i,
|
||||
"installs_fmt": str(100 - i),
|
||||
"link": f"https://skills.sh/src{i}/pkg/skill",
|
||||
"description": f"skill from src{i}",
|
||||
}
|
||||
for i in range(1, 12)
|
||||
],
|
||||
]
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
with patch("daily.format_wecom.needs_chinese", return_value=False):
|
||||
text = build_skills_delta_sections(
|
||||
moves,
|
||||
[],
|
||||
trending_full=full,
|
||||
hot_full=[],
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
)
|
||||
self.assertIn("Skills Trending Top 10", text)
|
||||
self.assertNotIn("Skills Trending 变化", text)
|
||||
|
||||
def test_delta_pad_uses_large_pool_when_recent_excludes_top(self):
|
||||
from daily.format_wecom import build_skills_delta_sections
|
||||
|
||||
full_small = [
|
||||
{
|
||||
"id": f"seen/src/s{i}",
|
||||
"title": f"s{i}",
|
||||
"source": "seen/src",
|
||||
"installs": 100 - i,
|
||||
"installs_fmt": str(100 - i),
|
||||
"link": f"https://skills.sh/seen/src/s{i}",
|
||||
"description": f"seen {i}",
|
||||
}
|
||||
for i in range(1, 11)
|
||||
]
|
||||
full_large = [
|
||||
{
|
||||
"id": f"fresh/src{n}/skill",
|
||||
"title": "skill",
|
||||
"source": f"fresh/src{n}",
|
||||
"installs": 50 - n,
|
||||
"installs_fmt": str(50 - n),
|
||||
"link": f"https://skills.sh/fresh/src{n}/skill",
|
||||
"description": f"fresh {n}",
|
||||
}
|
||||
for n in range(1, 11)
|
||||
]
|
||||
recent = {f"seen/src/s{i}" for i in range(1, 11)}
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
with patch("daily.format_wecom.needs_chinese", return_value=False):
|
||||
small = build_skills_delta_sections(
|
||||
[],
|
||||
[],
|
||||
trending_full=full_small,
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
recent_trending=recent,
|
||||
)
|
||||
large = build_skills_delta_sections(
|
||||
[],
|
||||
[],
|
||||
trending_full=full_large,
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
recent_trending=recent,
|
||||
)
|
||||
self.assertNotIn("Skills Trending Top 10", small)
|
||||
self.assertIn("Skills Trending Top 10", large)
|
||||
self.assertIn("fresh/src1", large)
|
||||
|
||||
def test_delta_pad_fills_github_to_limit(self):
|
||||
from daily.format_wecom import build_github_delta_sections
|
||||
|
||||
movement = {"github_trending_moves": [], "github_emerging_moves": [], "github_topic_moves": []}
|
||||
full = [
|
||||
{
|
||||
"repo": f"org/r{i}",
|
||||
"url": f"https://github.com/org/r{i}",
|
||||
"language": "Go",
|
||||
"stars_today_fmt": "100",
|
||||
"total_stars_fmt": "1K",
|
||||
"description": f"repo {i}",
|
||||
"desc_short": f"repo {i}",
|
||||
}
|
||||
for i in range(1, 12)
|
||||
]
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
text = build_github_delta_sections(
|
||||
movement,
|
||||
topic_name="llm",
|
||||
github_trending=full,
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
)
|
||||
self.assertIn("GitHub Trending Top 10", text)
|
||||
self.assertNotIn("GitHub Trending 变化", text)
|
||||
|
||||
def test_delta_pad_skips_recent_skills(self):
|
||||
from daily.format_wecom import build_skills_delta_sections
|
||||
|
||||
full = [
|
||||
{
|
||||
"id": f"x/y/s{i}",
|
||||
"title": f"s{i}",
|
||||
"source": "x/y",
|
||||
"installs": 100 - i,
|
||||
"installs_fmt": str(100 - i),
|
||||
"link": f"https://skills.sh/x/y/s{i}",
|
||||
"description": f"skill {i}",
|
||||
}
|
||||
for i in range(4, 6)
|
||||
]
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
with patch("daily.format_wecom.needs_chinese", return_value=False):
|
||||
text = build_skills_delta_sections(
|
||||
[],
|
||||
[],
|
||||
trending_full=full,
|
||||
hot_full=[],
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
recent_trending={f"x/y/s{i}" for i in range(1, 4)},
|
||||
)
|
||||
self.assertIn("Skills Trending Top 1", text)
|
||||
self.assertIn("2 skills", text)
|
||||
|
||||
def test_delta_pad_skips_recent_github(self):
|
||||
from daily.format_wecom import build_github_delta_sections
|
||||
|
||||
movement = {"github_trending_moves": [], "github_emerging_moves": [], "github_topic_moves": []}
|
||||
full = [
|
||||
{
|
||||
"repo": f"org/r{i}",
|
||||
"url": f"https://github.com/org/r{i}",
|
||||
"language": "Go",
|
||||
"total_stars_fmt": "1K",
|
||||
"description": f"repo {i}",
|
||||
"desc_short": f"repo {i}",
|
||||
}
|
||||
for i in range(1, 6)
|
||||
]
|
||||
with patch("daily.format_wecom.localize_brief_descriptions", return_value={}):
|
||||
text = build_github_delta_sections(
|
||||
movement,
|
||||
topic_name="llm",
|
||||
github_trending=full,
|
||||
trending_limit=10,
|
||||
pad=True,
|
||||
recent_board_keys={"github_trending": {f"org/r{i}" for i in range(1, 4)}},
|
||||
)
|
||||
self.assertIn("GitHub Trending Top 2", text)
|
||||
self.assertIn("org/r4", text)
|
||||
self.assertNotIn("org/r1", text)
|
||||
|
||||
def test_load_recent_board_keys_from_data_json(self):
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from daily.delta import load_recent_board_keys
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
out = Path(tmp)
|
||||
payload = {
|
||||
"data": {
|
||||
"date": "2026-07-09",
|
||||
"movement_baseline": {
|
||||
"skills_trending": [
|
||||
{"id": "a/b/raw", "title": "raw", "source": "a/b"},
|
||||
],
|
||||
"skills_hot": [],
|
||||
"github_trending": [{"repo": "org/raw"}],
|
||||
"github_emerging": [],
|
||||
"github_topic": [],
|
||||
},
|
||||
"wecom_shown_keys": {
|
||||
"skills_trending": ["a/b/foo"],
|
||||
"github_trending": ["org/bar"],
|
||||
},
|
||||
}
|
||||
}
|
||||
(out / "2026-07-09.data.json").write_text(json.dumps(payload), encoding="utf-8")
|
||||
with patch("daily.board_history.OUTPUT_DIR", out):
|
||||
recent = load_recent_board_keys("2026-07-10", lookback_days=7)
|
||||
self.assertIn("a/b/foo", recent["skills_trending"])
|
||||
self.assertIn("org/bar", recent["github_trending"])
|
||||
self.assertNotIn("a/b/raw", recent["skills_trending"])
|
||||
self.assertNotIn("org/raw", recent["github_trending"])
|
||||
|
||||
|
||||
class PushGateTests(unittest.TestCase):
|
||||
@@ -243,6 +503,25 @@ class E2ESmokeTests(unittest.TestCase):
|
||||
trending=[],
|
||||
hot=[],
|
||||
topic_name="llm",
|
||||
pad=False,
|
||||
)
|
||||
self.assertIn("Skills Trending 变化", out)
|
||||
self.assertNotIn("Skills Trending Top", out)
|
||||
|
||||
|
||||
class SyncMovementGithubTests(unittest.TestCase):
|
||||
def test_sync_copies_localized_description(self):
|
||||
from daily.generate import _sync_movement_github_descriptions
|
||||
|
||||
movement = {
|
||||
"github_trending_moves": [{"repo": "a/b", "description": "english"}],
|
||||
"github_emerging_moves": [],
|
||||
"github_topic_moves": [],
|
||||
}
|
||||
_sync_movement_github_descriptions(
|
||||
movement,
|
||||
github_trending=[{"repo": "a/b", "description": "中文描述"}],
|
||||
github_emerging=[],
|
||||
github_topic=[],
|
||||
)
|
||||
self.assertEqual(movement["github_trending_moves"][0]["description"], "中文描述")
|
||||
|
||||
Reference in New Issue
Block a user