80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
from datetime import date, datetime
|
|
|
|
from app.core.config import Settings
|
|
from app.db.models import Topic
|
|
from app.llm.grok_client import GrokIntelligenceClient
|
|
from app.schemas.agent import SignalItem
|
|
|
|
|
|
class StubGrokClient(GrokIntelligenceClient):
|
|
def _chat_json(self, messages):
|
|
# 测试只验证提示词输入和结果契约,不访问真实模型服务。
|
|
assert "github_candidates" in messages[1]["content"]
|
|
assert '"source_type": "news"' in messages[1]["content"]
|
|
assert '"source_type": "github"' in messages[1]["content"]
|
|
return {
|
|
"title": "AI 情报日报 2026-07-08",
|
|
"signals": [
|
|
{
|
|
"source_type": "github",
|
|
"topic": "GitHub 热门项目",
|
|
"title": "example/agent-kit",
|
|
"summary": "该项目提供生产级 Agent 工作流能力。",
|
|
"source_url": "https://github.com/example/agent-kit",
|
|
"source_name": "GitHub",
|
|
"published_at": "2026-07-08T00:00:00",
|
|
"importance": 4,
|
|
"entities": ["example/agent-kit", "Agent"],
|
|
}
|
|
],
|
|
"report_markdown": "# AI 情报日报 2026-07-08",
|
|
"raw_response": {"notes": "基于模型检索和 GitHub 候选筛选。"},
|
|
}
|
|
|
|
|
|
def test_grok_client_returns_agent_result() -> None:
|
|
# Grok客户端是日报与结构化情报的唯一生成入口。
|
|
client = StubGrokClient(Settings(llm_api_key="test-key"))
|
|
result = client.collect_daily_intelligence(
|
|
topics=[
|
|
Topic(
|
|
id=1,
|
|
name="Open-source AI projects",
|
|
description="Agent frameworks and open-source AI tools.",
|
|
enabled=True,
|
|
)
|
|
],
|
|
news_candidates=[
|
|
SignalItem(
|
|
source_type="news",
|
|
topic="AI 新闻候选",
|
|
title="New model release",
|
|
summary="News candidate from example.com.",
|
|
source_url="https://example.com/model-release",
|
|
source_name="example.com",
|
|
published_at=datetime(2026, 7, 8),
|
|
importance=3,
|
|
entities=["example.com"],
|
|
)
|
|
],
|
|
github_projects=[
|
|
SignalItem(
|
|
source_type="github",
|
|
topic="GitHub 热门项目",
|
|
title="example/agent-kit",
|
|
summary="Agent framework.",
|
|
source_url="https://github.com/example/agent-kit",
|
|
source_name="GitHub",
|
|
published_at=datetime(2026, 7, 8),
|
|
importance=4,
|
|
entities=["Agent"],
|
|
)
|
|
],
|
|
run_date=date(2026, 7, 8),
|
|
)
|
|
|
|
assert result.title == "AI 情报日报 2026-07-08"
|
|
assert result.signals[0].source_type == "github"
|
|
assert result.signals[0].source_name == "GitHub"
|
|
assert result.report_markdown.startswith("# AI 情报日报")
|