c2cbccfed9
Co-authored-by: Panniantong <panniantong@users.noreply.github.com>
99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Tests for doctor module."""
|
|
|
|
import pytest
|
|
|
|
import agent_reach.doctor as doctor
|
|
from agent_reach.config import Config
|
|
|
|
|
|
class _StubChannel:
|
|
def __init__(self, name, description, tier, status, message, backends=None):
|
|
self.name = name
|
|
self.description = description
|
|
self.tier = tier
|
|
self._status = status
|
|
self._message = message
|
|
self.backends = backends or []
|
|
|
|
def check(self, config=None):
|
|
return self._status, self._message
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_config(tmp_path):
|
|
return Config(config_path=tmp_path / "config.yaml")
|
|
|
|
|
|
class TestDoctor:
|
|
def test_check_all_collects_channel_results(self, tmp_config, monkeypatch):
|
|
monkeypatch.setattr(
|
|
doctor,
|
|
"get_all_channels",
|
|
lambda: [
|
|
_StubChannel("web", "网页", 0, "ok", "可抓取网页", ["requests"]),
|
|
_StubChannel("github", "GitHub", 0, "warn", "gh 未安装", ["gh"]),
|
|
_StubChannel("exa_search", "全网语义搜索", 1, "off", "mcporter 未配置", ["Exa"]),
|
|
],
|
|
)
|
|
|
|
results = doctor.check_all(tmp_config)
|
|
|
|
assert results == {
|
|
"web": {
|
|
"status": "ok",
|
|
"name": "网页",
|
|
"message": "可抓取网页",
|
|
"tier": 0,
|
|
"backends": ["requests"],
|
|
},
|
|
"github": {
|
|
"status": "warn",
|
|
"name": "GitHub",
|
|
"message": "gh 未安装",
|
|
"tier": 0,
|
|
"backends": ["gh"],
|
|
},
|
|
"exa_search": {
|
|
"status": "off",
|
|
"name": "全网语义搜索",
|
|
"message": "mcporter 未配置",
|
|
"tier": 1,
|
|
"backends": ["Exa"],
|
|
},
|
|
}
|
|
|
|
def test_format_report(self):
|
|
report = doctor.format_report(
|
|
{
|
|
"web": {
|
|
"status": "ok",
|
|
"name": "网页",
|
|
"message": "可抓取网页",
|
|
"tier": 0,
|
|
"backends": ["requests"],
|
|
},
|
|
"exa_search": {
|
|
"status": "off",
|
|
"name": "全网语义搜索",
|
|
"message": "mcporter 未配置",
|
|
"tier": 1,
|
|
"backends": ["Exa"],
|
|
},
|
|
"xiaohongshu": {
|
|
"status": "warn",
|
|
"name": "小红书",
|
|
"message": "MCP 已配置,但健康检查超时",
|
|
"tier": 2,
|
|
"backends": ["mcporter"],
|
|
},
|
|
}
|
|
)
|
|
|
|
assert "Agent Reach" in report
|
|
assert "✅ 装好即用:" in report
|
|
assert "搜索(mcporter 即可解锁):" in report
|
|
assert "配置后可用:" in report
|
|
assert "状态:1/3 个渠道可用" in report
|
|
assert "运行 `agent-reach setup` 解锁更多渠道" in report
|