fix: make doctor checks resilient to slow mcporter calls (#103)

This commit is contained in:
Peter Xue
2026-03-08 22:25:50 +08:00
committed by GitHub
parent fedbf95f61
commit 7942f632e5
4 changed files with 173 additions and 39 deletions
+44 -1
View File
@@ -1,7 +1,12 @@
# -*- coding: utf-8 -*-
"""Tests for channel registry basics."""
"""Tests for channel registry basics and health checks."""
import shutil
import subprocess
from agent_reach.channels import get_all_channels, get_channel
from agent_reach.channels.bosszhipin import BossZhipinChannel
from agent_reach.channels.xiaohongshu import XiaoHongShuChannel
class TestChannelRegistry:
@@ -19,3 +24,41 @@ class TestChannelRegistry:
assert "web" in names
assert "github" in names
assert "twitter" in names
class TestBossZhipinChannel:
def test_reports_ok_when_configured_and_logged_in(self, monkeypatch):
monkeypatch.setattr(shutil, "which", lambda _: "/opt/homebrew/bin/mcporter")
def fake_run(cmd, **kwargs):
if cmd[:4] == ["/opt/homebrew/bin/mcporter", "config", "get", "bosszhipin"]:
return subprocess.CompletedProcess(cmd, 0, '{"name":"bosszhipin"}', "")
if cmd[:3] == ["/opt/homebrew/bin/mcporter", "call", "bosszhipin.get_login_info_tool"]:
return subprocess.CompletedProcess(cmd, 0, '{"is_logged_in": true}', "")
raise AssertionError(f"unexpected command: {cmd}")
monkeypatch.setattr(subprocess, "run", fake_run)
assert BossZhipinChannel().check() == (
"ok",
"完整可用(职位搜索、登录态检查、向 HR 打招呼)",
)
class TestXiaoHongShuChannel:
def test_reports_ok_when_server_health_is_ok(self, monkeypatch):
monkeypatch.setattr(shutil, "which", lambda _: "/opt/homebrew/bin/mcporter")
def fake_run(cmd, **kwargs):
if cmd[:4] == ["/opt/homebrew/bin/mcporter", "config", "get", "xiaohongshu"]:
return subprocess.CompletedProcess(cmd, 0, '{"name":"xiaohongshu"}', "")
if cmd[:4] == ["/opt/homebrew/bin/mcporter", "list", "xiaohongshu", "--json"]:
return subprocess.CompletedProcess(cmd, 0, '{"status": "ok"}', "")
raise AssertionError(f"unexpected command: {cmd}")
monkeypatch.setattr(subprocess, "run", fake_run)
assert XiaoHongShuChannel().check() == (
"ok",
"MCP 已连接(阅读、搜索、发帖、评论、点赞)",
)