Buckets:

download
raw
37.2 kB
"""Tests for MCP Server radar_search, radar_diff, and parameter extensions.""" import json import sys from pathlib import Path from unittest.mock import patch import pytest pytest.importorskip("mcp", reason="mcp package not installed") # Add project root to path PROJECT_ROOT = Path(__file__).parent.parent sys.path.insert(0, str(PROJECT_ROOT / "mcp_server")) sys.path.insert(0, str(PROJECT_ROOT / "src")) @pytest.fixture def rich_report(): """Create a detailed mock report with all data sources.""" return { "generated_at": "2024-02-01T10:00:00", "period": {"days": 7, "start": "2024-01-25", "end": "2024-02-01"}, "summary": { "total_datasets": 5, "total_github_orgs": 3, "total_github_repos": 20, "total_github_repos_high_relevance": 4, "total_papers": 8, "total_blog_posts": 6, }, "datasets": [ { "id": "openai/gsm8k", "category": "evaluation", "description": "Grade school math", "downloads": 50000, "all_categories": ["evaluation", "math"], }, { "id": "meta/llama-sft", "category": "sft", "description": "SFT training data for Llama", "downloads": 30000, "all_categories": ["sft"], }, { "id": "nvidia/helpsteer2", "category": "preference", "description": "RLHF preference dataset", "downloads": 10000, "all_categories": ["preference", "rlhf"], }, { "id": "openai/webgpt", "category": "preference", "description": "WebGPT comparison data", "downloads": 5000, "all_categories": ["preference"], }, { "id": "bigcode/starcoderdata", "category": "code", "description": "Code pretraining data", "downloads": 80000, "all_categories": ["code"], }, ], "github_activity": [ { "org": "argilla-io", "repos_count": 3, "repos_updated": [ { "name": "argilla", "full_name": "argilla-io/argilla", "description": "Collaboration tool for AI datasets", "stars": 4800, "relevance": "high", "relevance_signals": ["dataset", "rlhf"], "topics": ["annotation", "llm"], "signals": ["dataset", "rlhf", "annotation"], }, { "name": "distilabel", "full_name": "argilla-io/distilabel", "description": "Synthetic data framework", "stars": 3000, "relevance": "high", "relevance_signals": ["dataset"], "topics": ["synthetic-data"], "signals": ["synthetic-data"], }, ], "has_activity": True, }, { "org": "scaleapi", "repos_count": 2, "repos_updated": [ { "name": "llm-engine", "full_name": "scaleapi/llm-engine", "description": "LLM fine-tuning engine", "stars": 500, "relevance": "medium", "relevance_signals": ["fine-tuning"], "topics": [], "signals": ["fine-tuning"], }, ], "has_activity": True, }, ], "papers": [ { "title": "RLHF at Scale", "url": "https://arxiv.org/abs/2401.001", "abstract": "Scaling RLHF training", "source": "arxiv", "categories": ["cs.CL"], }, { "title": "Synthetic Data Generation", "url": "https://arxiv.org/abs/2401.002", "abstract": "Methods for synthetic data", "source": "arxiv", "categories": ["cs.AI"], }, { "title": "Dataset Deduplication", "url": "https://hf.co/papers/123", "abstract": "Deduplication techniques", "source": "huggingface", "categories": [], }, ], "blog_posts": [ { "source": "OpenAI Blog", "articles": [ { "title": "GPT-5 Training Data", "url": "https://openai.com/blog/gpt5-data", "date": "2024-01-30", "signals": ["dataset", "training data"], "snippet": "We describe our data pipeline", }, { "title": "Safety Updates", "url": "https://openai.com/blog/safety", "date": "2024-01-28", "signals": ["alignment"], }, ], }, { "source": "Microsoft Research", "articles": [ { "title": "Phi-4 Synthetic Data", "url": "https://msft.com/phi4", "date": "2024-01-29", "signals": ["synthetic data"], "snippet": "Using synthetic data for Phi-4", }, ], }, ], "x_activity": { "accounts": [ { "username": "OpenAI", "total_tweets": 5, "relevant_tweets": [ { "username": "OpenAI", "text": "We're releasing a new dataset for RLHF research", "url": "https://x.com/OpenAI/status/123", "date": "2024-01-30", }, ], "has_activity": True, }, ], "search_results": [], }, } @pytest.fixture def older_report(): """Create an older mock report for diff testing.""" return { "generated_at": "2024-01-25T10:00:00", "summary": { "total_datasets": 3, "total_github_orgs": 2, "total_github_repos": 15, "total_github_repos_high_relevance": 2, "total_papers": 5, "total_blog_posts": 4, }, "datasets": [ {"id": "openai/gsm8k"}, {"id": "meta/llama-sft"}, {"id": "removed/old-dataset"}, ], "github_activity": [ { "org": "argilla-io", "repos_updated": [ {"full_name": "argilla-io/argilla"}, ], }, ], "papers": [ {"title": "RLHF at Scale"}, {"title": "Old Paper About Transformers"}, ], "blog_posts": [ { "source": "OpenAI Blog", "articles": [ {"url": "https://openai.com/blog/old-post"}, ], }, ], } def _write_report(tmp_path, date_str, report): """Helper to write a report to tmp_path.""" reports_dir = tmp_path / "data" / "reports" reports_dir.mkdir(parents=True, exist_ok=True) (reports_dir / f"intel_report_{date_str}.json").write_text(json.dumps(report)) # ─── radar_search tests ────────────────────────────────────────────────────── class TestSearchInReport: """Test the search_in_report helper function.""" def test_search_datasets_by_keyword(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "rlhf", ["datasets"], 10) assert "datasets" in results ids = [d["id"] for d in results["datasets"]] assert "nvidia/helpsteer2" in ids def test_search_github_by_keyword(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "synthetic", ["github"], 10) assert "github" in results names = [r["name"] for r in results["github"]] assert "argilla-io/distilabel" in names def test_search_papers_by_keyword(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "deduplication", ["papers"], 10) assert "papers" in results assert results["papers"][0]["title"] == "Dataset Deduplication" def test_search_blogs_by_keyword(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "synthetic", ["blogs"], 10) assert "blogs" in results assert results["blogs"][0]["source"] == "Microsoft Research" def test_search_x_by_keyword(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "RLHF", ["x"], 10) assert "x" in results assert results["x"][0]["username"] == "OpenAI" def test_search_all_sources(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "dataset", [], 10) # Should find matches in datasets, github, papers, blogs, x assert len(results) >= 3 def test_search_no_match(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "xyznonexistent", [], 10) assert results == {} def test_search_regex_pattern(self, rich_report): from server import search_in_report results = search_in_report(rich_report, r"llama|Llama", ["datasets"], 10) assert "datasets" in results ids = [d["id"] for d in results["datasets"]] assert "meta/llama-sft" in ids def test_search_invalid_regex_fallback(self, rich_report): from server import search_in_report # Invalid regex should fall back to literal search results = search_in_report(rich_report, "[invalid(regex", [], 10) assert isinstance(results, dict) def test_search_limit_respected(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "data", ["datasets"], 2) if "datasets" in results: assert len(results["datasets"]) <= 2 def test_search_case_insensitive(self, rich_report): from server import search_in_report results = search_in_report(rich_report, "OPENAI", ["datasets"], 10) assert "datasets" in results # ─── radar_diff tests ──────────────────────────────────────────────────────── class TestDiffReports: """Test the diff_reports helper function.""" def test_diff_summary_changes(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) assert diff["summary_changes"]["total_datasets"]["before"] == 3 assert diff["summary_changes"]["total_datasets"]["after"] == 5 assert diff["summary_changes"]["total_datasets"]["delta"] == 2 def test_diff_new_datasets(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) new_ds = diff["new_items"].get("datasets", []) assert "nvidia/helpsteer2" in new_ds assert "openai/webgpt" in new_ds assert "bigcode/starcoderdata" in new_ds def test_diff_removed_datasets(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) removed_ds = diff["removed_items"].get("datasets", []) assert "removed/old-dataset" in removed_ds def test_diff_new_repos(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) new_repos = diff["new_items"].get("github_repos", []) assert "argilla-io/distilabel" in new_repos assert "scaleapi/llm-engine" in new_repos def test_diff_new_papers(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) new_papers = diff["new_items"].get("papers", []) assert "Synthetic Data Generation" in new_papers assert "Dataset Deduplication" in new_papers def test_diff_new_blog_articles(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) new_blogs = diff["new_items"].get("blog_articles", []) assert "https://openai.com/blog/gpt5-data" in new_blogs assert "https://openai.com/blog/safety" in new_blogs def test_diff_identical_reports(self, rich_report): from server import diff_reports diff = diff_reports(rich_report, rich_report) assert diff["summary_changes"] == {} assert diff["new_items"] == {} assert diff["removed_items"] == {} def test_diff_period_labels(self, older_report, rich_report): from server import diff_reports diff = diff_reports(older_report, rich_report) assert diff["period_a"] == "2024-01-25" assert diff["period_b"] == "2024-02-01" # ─── MCP tool execution tests ──────────────────────────────────────────────── class TestRadarSearchTool: """Test radar_search tool execution via call_tool.""" @pytest.mark.asyncio async def test_search_returns_results(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_search", {"query": "rlhf"}) text = result[0].text assert "搜索结果" in text assert "rlhf" in text.lower() or "RLHF" in text @pytest.mark.asyncio async def test_search_no_results(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_search", {"query": "xyznonexistent"}) text = result[0].text assert "未找到" in text @pytest.mark.asyncio async def test_search_with_source_filter(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_search", {"query": "data", "sources": ["github"]}) text = result[0].text assert "GitHub" in text @pytest.mark.asyncio async def test_search_no_report(self, tmp_path): from server import call_tool with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_search", {"query": "test"}) text = result[0].text assert "没有找到报告" in text @pytest.mark.asyncio async def test_search_empty_query(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_search", {"query": ""}) text = result[0].text assert "请提供" in text class TestRadarDiffTool: """Test radar_diff tool execution via call_tool.""" @pytest.mark.asyncio async def test_diff_two_reports(self, older_report, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-01-25", older_report) _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_diff", {}) text = result[0].text assert "报告对比" in text assert "新增" in text @pytest.mark.asyncio async def test_diff_by_date(self, older_report, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-01-25", older_report) _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_diff", {"date_a": "2024-01-25", "date_b": "2024-02-01"}) text = result[0].text assert "2024-01-25" in text assert "2024-02-01" in text @pytest.mark.asyncio async def test_diff_missing_date(self, older_report, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-01-25", older_report) _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_diff", {"date_a": "2099-01-01"}) text = result[0].text assert "未找到" in text @pytest.mark.asyncio async def test_diff_insufficient_reports(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_diff", {}) text = result[0].text assert "至少两份" in text # ─── Parameter extension tests ─────────────────────────────────────────────── class TestParameterExtensions: """Test new parameters on existing tools.""" @pytest.mark.asyncio async def test_radar_datasets_org_filter(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_datasets", {"org": "openai"}) text = result[0].text assert "gsm8k" in text assert "webgpt" in text assert "starcoderdata" not in text @pytest.mark.asyncio async def test_radar_datasets_org_and_category(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_datasets", {"org": "openai", "category": "preference"}) text = result[0].text assert "webgpt" in text assert "gsm8k" not in text @pytest.mark.asyncio async def test_radar_github_org_filter(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_github", {"org": "argilla", "relevance": "high"}) text = result[0].text assert "argilla" in text assert "scaleapi" not in text def test_radar_scan_has_sources_param(self): """Test radar_scan tool definition includes sources parameter.""" from server import list_tools import asyncio tools = asyncio.run(list_tools()) scan_tool = next(t for t in tools if t.name == "radar_scan") assert "sources" in scan_tool.inputSchema["properties"] def test_radar_search_tool_registered(self): """Test radar_search tool is registered.""" from server import list_tools import asyncio tools = asyncio.run(list_tools()) tool_names = {t.name for t in tools} assert "radar_search" in tool_names assert "radar_diff" in tool_names def test_all_19_tools_registered(self): """Test all 19 tools are registered.""" from server import list_tools import asyncio tools = asyncio.run(list_tools()) tool_names = {t.name for t in tools} expected = { "radar_scan", "radar_summary", "radar_datasets", "radar_github", "radar_papers", "radar_blogs", "radar_config", "radar_search", "radar_diff", "radar_trend", "radar_history", "radar_reddit", "radar_trends", "radar_matrix", "radar_lineage", "radar_org_graph", "radar_alerts", "radar_export", "radar_subscribe", } assert expected == tool_names # ─── Helper function tests ─────────────────────────────────────────────────── class TestHelperFunctions: """Test new helper functions.""" def test_get_report_by_date(self, tmp_path): from server import get_report_by_date reports_dir = tmp_path / "data" / "reports" reports_dir.mkdir(parents=True) (reports_dir / "intel_report_2024-02-01.json").write_text('{"test": true}') with patch("server.PROJECT_ROOT", tmp_path): result = get_report_by_date("2024-02-01") assert result == {"test": True} def test_get_report_by_date_not_found(self, tmp_path): from server import get_report_by_date with patch("server.PROJECT_ROOT", tmp_path): result = get_report_by_date("2099-01-01") assert result is None def test_get_all_reports_sorted(self, tmp_path): from server import get_all_reports_sorted reports_dir = tmp_path / "data" / "reports" reports_dir.mkdir(parents=True) (reports_dir / "intel_report_2024-01-01.json").write_text("{}") (reports_dir / "intel_report_2024-02-01.json").write_text("{}") (reports_dir / "intel_report_2024-01-15.json").write_text("{}") with patch("server.PROJECT_ROOT", tmp_path): paths = get_all_reports_sorted() assert len(paths) == 3 assert "2024-02-01" in str(paths[0]) # Most recent first def test_get_all_reports_empty(self, tmp_path): from server import get_all_reports_sorted with patch("server.PROJECT_ROOT", tmp_path): paths = get_all_reports_sorted() assert paths == [] # ─── radar_reddit execution tests ───────────────────────────────────────────── class TestRadarRedditTool: """Test radar_reddit tool execution via call_tool.""" @pytest.fixture def report_with_reddit(self, rich_report): rich_report["reddit_activity"] = { "posts": [ { "subreddit": "MachineLearning", "title": "New RLHF dataset released", "url": "https://reddit.com/r/MachineLearning/1", "score": 150, "date": "2024-01-30", "signals": ["rlhf", "dataset"], }, { "subreddit": "LocalLLaMA", "title": "Fine-tuning with synthetic data", "url": "https://reddit.com/r/LocalLLaMA/2", "score": 80, "date": "2024-01-29", "signals": ["synthetic"], }, { "subreddit": "MachineLearning", "title": "Low quality post", "url": "https://reddit.com/r/MachineLearning/3", "score": 5, "date": "2024-01-28", "signals": [], }, ], "metadata": {"subreddits_checked": 5, "total_posts": 3}, } return rich_report @pytest.mark.asyncio async def test_reddit_returns_posts(self, report_with_reddit, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_reddit) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_reddit", {}) text = result[0].text assert "Reddit" in text assert "RLHF" in text @pytest.mark.asyncio async def test_reddit_filter_subreddit(self, report_with_reddit, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_reddit) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_reddit", {"subreddit": "LocalLLaMA"}) text = result[0].text assert "LocalLLaMA" in text assert "MachineLearning" not in text.split("Reddit")[1] # not in post list @pytest.mark.asyncio async def test_reddit_filter_min_score(self, report_with_reddit, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_reddit) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_reddit", {"min_score": 100}) text = result[0].text assert "RLHF" in text assert "Low quality" not in text @pytest.mark.asyncio async def test_reddit_no_report(self, tmp_path): from server import call_tool with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_reddit", {}) text = result[0].text assert "没有找到报告" in text # ─── radar_trends execution tests ───────────────────────────────────────────── class TestRadarTrendsTool: """Test radar_trends tool execution via call_tool.""" @pytest.mark.asyncio async def test_trends_returns_table(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-01-25", { **rich_report, "generated_at": "2024-01-25T10:00:00", "summary": {**rich_report["summary"], "total_datasets": 3}, }) _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_trends", {}) text = result[0].text assert "历史趋势" in text assert "数据集" in text assert "2024-02-01" in text @pytest.mark.asyncio async def test_trends_shows_delta(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-01-25", { **rich_report, "generated_at": "2024-01-25T10:00:00", "summary": {**rich_report["summary"], "total_datasets": 3}, }) _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_trends", {}) text = result[0].text assert "变化趋势" in text assert "+2" in text # datasets: 3 → 5 @pytest.mark.asyncio async def test_trends_no_reports(self, tmp_path): from server import call_tool with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_trends", {}) text = result[0].text assert "没有找到" in text # ─── radar_matrix execution tests ───────────────────────────────────────────── class TestRadarMatrixTool: """Test radar_matrix tool execution via call_tool.""" @pytest.fixture def report_with_matrix(self, rich_report): rich_report["competitor_matrix"] = { "matrix": { "openai": {"sft": 2, "preference": 1, "repos": 5, "papers": 3, "blogs": 2}, "meta": {"sft": 3, "repos": 2, "papers": 1, "blogs": 1}, }, "top_orgs": [ {"org": "openai", "total": 13}, {"org": "meta", "total": 7}, ], "rankings": {}, } return rich_report @pytest.mark.asyncio async def test_matrix_returns_table(self, report_with_matrix, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_matrix) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_matrix", {}) text = result[0].text assert "竞品矩阵" in text assert "openai" in text assert "meta" in text @pytest.mark.asyncio async def test_matrix_no_data(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_matrix", {}) text = result[0].text assert "没有" in text # ─── radar_lineage execution tests ──────────────────────────────────────────── class TestRadarLineageTool: """Test radar_lineage tool execution via call_tool.""" @pytest.fixture def report_with_lineage(self, rich_report): rich_report["dataset_lineage"] = { "edges": [ {"source": "openai/gsm8k", "target": "meta/gsm8k-v2", "type": "derived"}, {"source": "openai/gsm8k", "target": "nvidia/gsm8k-chat", "type": "fine_tuned"}, ], "root_datasets": [ {"id": "openai/gsm8k", "count": 2}, ], "version_chains": { "gsm8k": ["gsm8k-v1", "gsm8k-v2", "gsm8k-v3"], }, "fork_trees": { "alpaca": ["alpaca-cleaned", "alpaca-gpt4"], }, "stats": {"total_edges": 2, "version_chains": 1, "fork_trees": 1}, } return rich_report @pytest.mark.asyncio async def test_lineage_returns_overview(self, report_with_lineage, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_lineage) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_lineage", {}) text = result[0].text assert "谱系" in text assert "版本链" in text assert "gsm8k" in text @pytest.mark.asyncio async def test_lineage_filter_by_dataset(self, report_with_lineage, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_lineage) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_lineage", {"dataset_id": "openai/gsm8k"}) text = result[0].text assert "openai/gsm8k" in text assert "meta/gsm8k-v2" in text @pytest.mark.asyncio async def test_lineage_no_data(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_lineage", {}) text = result[0].text assert "没有" in text # ─── radar_org_graph execution tests ────────────────────────────────────────── class TestRadarOrgGraphTool: """Test radar_org_graph tool execution via call_tool.""" @pytest.fixture def report_with_graph(self, rich_report): rich_report["org_graph"] = { "nodes": ["openai", "meta", "google", "anthropic"], "edges": [ {"source": "openai", "target": "meta", "type": "shared_topic", "weight": 3}, {"source": "google", "target": "anthropic", "type": "co_citation", "weight": 2}, {"source": "openai", "target": "google", "type": "shared_dataset_author", "weight": 1}, ], "clusters": [["openai", "meta", "google"], ["anthropic"]], "centrality": {"openai": 0.667, "meta": 0.333, "google": 0.667, "anthropic": 0.333}, } return rich_report @pytest.mark.asyncio async def test_org_graph_returns_overview(self, report_with_graph, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_graph) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_org_graph", {}) text = result[0].text assert "组织关系" in text assert "中心性" in text assert "openai" in text @pytest.mark.asyncio async def test_org_graph_filter_by_org(self, report_with_graph, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", report_with_graph) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_org_graph", {"org": "openai"}) text = result[0].text assert "openai" in text assert "meta" in text # connected to openai @pytest.mark.asyncio async def test_org_graph_no_data(self, rich_report, tmp_path): from server import call_tool _write_report(tmp_path, "2024-02-01", rich_report) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_org_graph", {}) text = result[0].text assert "没有" in text # ─── radar_alerts tests ───────────────────────────────────────────────────── class TestRadarAlertsTool: """Test radar_alerts tool execution via call_tool.""" def _write_alerts(self, tmp_path, date_str, alerts): d = tmp_path / "data" / "reports" / date_str d.mkdir(parents=True, exist_ok=True) (d / "alerts.json").write_text(json.dumps(alerts)) @pytest.mark.asyncio async def test_alerts_with_data(self, tmp_path): from server import call_tool alerts = [ {"rule": "zero_data_github", "severity": "critical", "title": "GitHub: 0 orgs", "detail": "Check API.", "timestamp": "2026-02-09T08:00:00", "fingerprint": "abc"}, {"rule": "trend_breakthrough", "severity": "info", "title": "Breakthrough: ds1", "detail": "Growth.", "timestamp": "2026-02-09T09:00:00", "fingerprint": "def"}, ] self._write_alerts(tmp_path, "2026-02-09", alerts) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_alerts", {}) text = result[0].text assert "告警记录" in text assert "GitHub: 0 orgs" in text assert "Breakthrough: ds1" in text assert "CRITICAL" in text @pytest.mark.asyncio async def test_alerts_severity_filter(self, tmp_path): from server import call_tool alerts = [ {"rule": "r1", "severity": "critical", "title": "Crit", "detail": "", "timestamp": "2026-02-09T08:00:00", "fingerprint": "a"}, {"rule": "r2", "severity": "info", "title": "Info", "detail": "", "timestamp": "2026-02-09T09:00:00", "fingerprint": "b"}, ] self._write_alerts(tmp_path, "2026-02-09", alerts) with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_alerts", {"severity": "critical"}) text = result[0].text assert "Crit" in text assert "Info" not in text @pytest.mark.asyncio async def test_alerts_empty(self, tmp_path): from server import call_tool with patch("server.PROJECT_ROOT", tmp_path): result = await call_tool("radar_alerts", {}) text = result[0].text assert "没有" in text
"""Tests for MCP Server radar_search, radar_diff, and parameter extensions."""
import json
import sys
from pathlib import Path
from unittest.mock import patch
import pytest
pytest.importorskip("mcp", reason="mcp package not installed")
# Add project root to path
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT / "mcp_server"))
sys.path.insert(0, str(PROJECT_ROOT / "src"))
@pytest.fixture
def rich_report():
"""Create a detailed mock report with all data sources."""
return {
"generated_at": "2024-02-01T10:00:00",
"period": {"days": 7, "start": "2024-01-25", "end": "2024-02-01"},
"summary": {
"total_datasets": 5,
"total_github_orgs": 3,
"total_github_repos": 20,
"total_github_repos_high_relevance": 4,
"total_papers": 8,
"total_blog_posts": 6,
},
"datasets": [
{
"id": "openai/gsm8k",
"category": "evaluation",
"description": "Grade school math",
"downloads": 50000,
"all_categories": ["evaluation", "math"],
},
{
"id": "meta/llama-sft",
"category": "sft",
"description": "SFT training data for Llama",
"downloads": 30000,
"all_categories": ["sft"],
},
{
"id": "nvidia/helpsteer2",
"category": "preference",
"description": "RLHF preference dataset",
"downloads": 10000,
"all_categories": ["preference", "rlhf"],
},
{
"id": "openai/webgpt",
"category": "preference",
"description": "WebGPT comparison data",
"downloads": 5000,
"all_categories": ["preference"],
},
{
"id": "bigcode/starcoderdata",
"category": "code",
"description": "Code pretraining data",
"downloads": 80000,
"all_categories": ["code"],
},
],
"github_activity": [
{
"org": "argilla-io",
"repos_count": 3,
"repos_updated": [
{
"name": "argilla",
"full_name": "argilla-io/argilla",
"description": "Collaboration tool for AI datasets",
"stars": 4800,
"relevance": "high",
"relevance_signals": ["dataset", "rlhf"],
"topics": ["annotation", "llm"],
"signals": ["dataset", "rlhf", "annotation"],
},
{
"name": "distilabel",
"full_name": "argilla-io/distilabel",
"description": "Synthetic data framework",
"stars": 3000,
"relevance": "high",
"relevance_signals": ["dataset"],
"topics": ["synthetic-data"],
"signals": ["synthetic-data"],
},
],
"has_activity": True,
},
{
"org": "scaleapi",
"repos_count": 2,
"repos_updated": [

Xet Storage Details

Size:
37.2 kB
·
Xet hash:
80da81c1071c7487acd1bdab673e7f1bbe008aa958436c34be7e56ea5a646f57

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.