Files
daily-robots/tests/test_github_search.py
yumao 6ea2a4e4c6 feat: 早报系统重构与功能增强
- 新增常驻调度器 daily/scheduler.py + run-scheduler.ps1(定时生成/推送)
- 新增 daily/bridge_manager.py:Windows 兼容的 Cursor SDK 桥接
- 新增 skills/daily-featured-pick 首推 Skill 与叙事轴/去重逻辑
- 新闻抓取窗口、GitHub 搜索、企微 delta 模式等多项改进
- 补充设计文档与 superpowers 计划/规范
- 新增对应测试(scheduler、featured_pick、github_search、news_fetch_window 等)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 18:12:00 +08:00

72 lines
2.6 KiB
Python

"""Tests for GitHub Search pagination / deep pool."""
from __future__ import annotations
import os
import unittest
from unittest.mock import MagicMock, patch
class SearchGithubReposPaginationTests(unittest.TestCase):
def test_search_paginates_beyond_first_page_of_30(self):
from daily.github.search import search_github_repos
def make_items(start: int, n: int) -> list[dict]:
return [
{
"full_name": f"org/repo{i}",
"html_url": f"https://github.com/org/repo{i}",
"description": f"desc {i}",
"language": "Python",
"stargazers_count": 1000 - i,
"created_at": "2026-01-01T00:00:00Z",
}
for i in range(start, start + n)
]
responses = [
MagicMock(status_code=200, json=lambda: {"items": make_items(1, 100)}),
MagicMock(status_code=200, json=lambda: {"items": make_items(101, 50)}),
]
client = MagicMock()
client.__enter__.return_value = client
client.__exit__.return_value = False
client.get.side_effect = responses
with patch.dict(os.environ, {"GITHUB_TOKEN": "test-token"}, clear=False):
with patch("daily.github.search.httpx.Client", return_value=client):
with patch("daily.github.search.github_token", return_value="test-token"):
repos = search_github_repos("stars:>50", 120, require_token=True)
self.assertEqual(len(repos), 120)
self.assertEqual(repos[0]["repo"], "org/repo1")
self.assertEqual(repos[119]["repo"], "org/repo120")
self.assertEqual(client.get.call_count, 2)
first_params = client.get.call_args_list[0].kwargs["params"]
self.assertEqual(first_params["per_page"], 100)
self.assertEqual(first_params["page"], 1)
class GithubBoardDeepPoolTests(unittest.TestCase):
def test_board_select_fills_ten_when_deep_pool_has_fresh_repos(self):
from daily.board_select import board_select
recent = {f"old/r{i}" for i in range(1, 33)}
items = [{"repo": f"old/r{i}"} for i in range(1, 31)] + [
{"repo": f"fresh/r{i}"} for i in range(1, 20)
]
selected = board_select(
board="github_trending",
items=items,
recent_keys=recent,
limit=10,
pool_size=100,
kind="github",
)
self.assertEqual(len(selected), 10)
self.assertTrue(all(r["repo"].startswith("fresh/") for r in selected))
if __name__ == "__main__":
unittest.main()