fix(reddit): detect auth status in doctor check (#261)
fix(reddit): detect auth status in doctor check, show recovery paths
This commit is contained in:
+67
-3
@@ -7,9 +7,9 @@ import subprocess
|
||||
from urllib.error import URLError
|
||||
|
||||
from agent_reach.channels import get_all_channels, get_channel
|
||||
from agent_reach.channels.v2ex import V2EXChannel
|
||||
from agent_reach.channels.xiaohongshu import XiaoHongShuChannel
|
||||
from agent_reach.channels.xueqiu import XueqiuChannel
|
||||
from agent_reach.channels.v2ex import V2EXChannel
|
||||
|
||||
|
||||
class TestChannelRegistry:
|
||||
@@ -223,8 +223,6 @@ class TestV2EXChannel:
|
||||
},
|
||||
]
|
||||
|
||||
call_count = {"n": 0}
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, payload):
|
||||
self._payload = payload
|
||||
@@ -648,6 +646,72 @@ class TestXueqiuChannel:
|
||||
assert "agent-reach" not in captured["ua"]
|
||||
|
||||
|
||||
class TestRedditChannel:
|
||||
def test_reports_off_when_not_installed(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: None)
|
||||
from agent_reach.channels.reddit import RedditChannel
|
||||
status, msg = RedditChannel().check()
|
||||
assert status == "off"
|
||||
assert "rdt-cli" in msg
|
||||
assert "public-clis/rdt-cli" in msg
|
||||
|
||||
def test_reports_ok_when_authenticated(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/rdt")
|
||||
fake_output = json.dumps({
|
||||
"ok": True,
|
||||
"schema_version": "1",
|
||||
"data": {"authenticated": True, "username": "testuser", "cookie_count": 1},
|
||||
})
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
return subprocess.CompletedProcess(cmd, 0, fake_output, "")
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
from agent_reach.channels.reddit import RedditChannel
|
||||
status, msg = RedditChannel().check()
|
||||
assert status == "ok"
|
||||
assert "testuser" in msg
|
||||
|
||||
def test_reports_warn_when_not_authenticated(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/rdt")
|
||||
fake_output = json.dumps({
|
||||
"ok": True,
|
||||
"schema_version": "1",
|
||||
"data": {"authenticated": False, "username": None, "cookie_count": 0},
|
||||
})
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
return subprocess.CompletedProcess(cmd, 0, fake_output, "")
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
from agent_reach.channels.reddit import RedditChannel
|
||||
status, msg = RedditChannel().check()
|
||||
assert status == "warn"
|
||||
assert "403" in msg
|
||||
assert "rdt login" in msg
|
||||
assert "Cookie-Editor" in msg
|
||||
assert "chromewebstore.google.com" in msg
|
||||
|
||||
def test_reports_warn_when_status_check_fails(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/rdt")
|
||||
|
||||
def fake_run(cmd, **kwargs):
|
||||
return subprocess.CompletedProcess(cmd, 1, "not valid json{{{", "")
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
from agent_reach.channels.reddit import RedditChannel
|
||||
status, msg = RedditChannel().check()
|
||||
assert status == "warn"
|
||||
|
||||
def test_can_handle_reddit_urls(self):
|
||||
from agent_reach.channels.reddit import RedditChannel
|
||||
ch = RedditChannel()
|
||||
assert ch.can_handle("https://www.reddit.com/r/python/comments/abc123/")
|
||||
assert ch.can_handle("https://redd.it/abc123")
|
||||
assert not ch.can_handle("https://github.com/user/repo")
|
||||
assert not ch.can_handle("https://v2ex.com/t/123")
|
||||
|
||||
|
||||
class TestXiaoHongShuChannel:
|
||||
def test_reports_ok_when_cli_authenticated(self, monkeypatch):
|
||||
monkeypatch.setattr(shutil, "which", lambda _: "/usr/local/bin/xhs")
|
||||
|
||||
Reference in New Issue
Block a user