test: Phase 3 添加 smoke test、CI 与 run-daily 去重锁
离线 mock 测试 generate 产出,GitHub Actions 跑 pytest,30 分钟内重复调度自动 skip。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
66
tests/test_smoke.py
Normal file
66
tests/test_smoke.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
def _sample_github_repo() -> dict:
|
||||
return {
|
||||
"repo": "owner/sample",
|
||||
"url": "https://github.com/owner/sample",
|
||||
"description": "Sample repository for smoke tests.",
|
||||
"language": "Python",
|
||||
"stars_today_fmt": "120",
|
||||
"total_stars_fmt": "1.2K",
|
||||
"created_at": "2026-06-01",
|
||||
}
|
||||
|
||||
|
||||
def test_format_installs():
|
||||
from shared.skills_data import format_installs
|
||||
|
||||
assert format_installs(999) == "999"
|
||||
assert format_installs(18000) == "18.0K"
|
||||
assert format_installs(2_500_000) == "2.5M"
|
||||
|
||||
|
||||
def test_generate_report_offline(
|
||||
skills_feed,
|
||||
fixed_cst,
|
||||
isolated_output,
|
||||
offline_generate_env,
|
||||
monkeypatch,
|
||||
):
|
||||
import daily.generate as generate
|
||||
|
||||
monkeypatch.setattr(generate, "load_feed", lambda force=False: skills_feed)
|
||||
monkeypatch.setattr(generate, "fetch_github_trending", lambda n: [_sample_github_repo()])
|
||||
monkeypatch.setattr(generate, "fetch_emerging_repos", lambda n, exclude=None: [])
|
||||
monkeypatch.setattr(generate, "fetch_topic_hot_repos", lambda n, exclude=None: ("llm", []))
|
||||
monkeypatch.setattr(generate, "_now_cst", lambda: fixed_cst)
|
||||
|
||||
_, wecom_md, out_md, out_wecom = generate.generate_report()
|
||||
|
||||
assert out_md.exists()
|
||||
assert out_wecom.exists()
|
||||
assert "早报" in out_md.read_text(encoding="utf-8")
|
||||
assert wecom_md.strip()
|
||||
assert "📰" in wecom_md
|
||||
|
||||
data_path = isolated_output / "2026-07-03.data.json"
|
||||
assert data_path.exists()
|
||||
payload = json.loads(data_path.read_text(encoding="utf-8"))
|
||||
assert payload["meta"]["report_mode"] == "classic"
|
||||
assert payload["data"]["date"] == "2026-07-03"
|
||||
assert len(payload["data"]["skills_trending"]) >= 1
|
||||
assert len(payload["data"]["skills_hot"]) >= 1
|
||||
|
||||
|
||||
def test_rss_fixture_is_well_formed():
|
||||
xml = (FIXTURES / "sample-rss.xml").read_text(encoding="utf-8")
|
||||
assert "Sample AI headline" in xml
|
||||
assert "<item>" in xml
|
||||
Reference in New Issue
Block a user