fix(xiaohongshu): switch from Docker MCP to xhs-cli (pipx install) (#236)
Docker + Cookie import → `pipx install xiaohongshu-cli` + `xhs login`. Tier downgraded from 2 to 1. xhs-cli (1,477 stars) auto-extracts cookies from browser, supports search/read/comment/post/hot/feed. - xiaohongshu.py: check() detects `xhs` binary, parses `xhs status` - cli.py: install via pipx instead of Docker - skill/references/social.md: updated XHS commands - tests: 3 new tests for CLI-based check() - 77 tests passing Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+24
-11
@@ -649,19 +649,32 @@ class TestXueqiuChannel:
|
||||
|
||||
|
||||
class TestXiaoHongShuChannel:
|
||||
def test_reports_ok_when_server_health_is_ok(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/opt/homebrew/bin/mcporter")
|
||||
def test_reports_ok_when_cli_authenticated(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/xhs")
|
||||
|
||||
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}")
|
||||
return subprocess.CompletedProcess(cmd, 0, "ok: true\nusername: testuser\n", "")
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
|
||||
assert XiaoHongShuChannel().check() == (
|
||||
"ok",
|
||||
"MCP 已连接(阅读、搜索、发帖、评论、点赞)",
|
||||
)
|
||||
status, msg = XiaoHongShuChannel().check()
|
||||
assert status == "ok"
|
||||
assert "完整可用" in msg
|
||||
|
||||
def test_reports_warn_when_not_authenticated(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/xhs")
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
return subprocess.CompletedProcess(cmd, 1, "", "ok: false\nerror:\n code: not_authenticated\n")
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
|
||||
status, msg = XiaoHongShuChannel().check()
|
||||
assert status == "warn"
|
||||
assert "xhs login" in msg
|
||||
|
||||
def test_reports_off_when_not_installed(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: None)
|
||||
status, msg = XiaoHongShuChannel().check()
|
||||
assert status == "off"
|
||||
assert "xiaohongshu-cli" in msg
|
||||
|
||||
Reference in New Issue
Block a user