forked from Panniantong/Agent-Reach
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_channel_contracts.py
More file actions
51 lines (42 loc) · 2 KB
/
test_channel_contracts.py
File metadata and controls
51 lines (42 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""Contract tests for channel adapters."""
from agent_reach.channels import get_all_channels
from agent_reach.config import Config
def test_channel_registry_contract():
channels = get_all_channels()
assert channels, "channel registry must not be empty"
names = [ch.name for ch in channels]
assert len(names) == len(set(names)), "channel names must be unique"
for ch in channels:
assert isinstance(ch.name, str) and ch.name
assert isinstance(ch.description, str) and ch.description
assert isinstance(ch.backends, list)
assert ch.tier in {0, 1, 2}
def test_channel_check_contract_with_minimal_runtime(monkeypatch, tmp_path):
# Keep contract tests deterministic by simulating "deps mostly absent".
monkeypatch.setattr("shutil.which", lambda _cmd: None)
config = Config(config_path=tmp_path / "config.yaml")
for ch in get_all_channels():
status, message = ch.check(config)
assert status in {"ok", "warn", "off", "error"}
assert isinstance(message, str) and message.strip()
def test_channel_can_handle_contract():
url_samples = {
"github": "https://github.com/panniantong/agent-reach",
"twitter": "https://x.com/user/status/1",
"youtube": "https://youtube.com/watch?v=abc",
"reddit": "https://reddit.com/r/python",
"bilibili": "https://www.bilibili.com/video/BV1xx411",
"xiaohongshu": "https://www.xiaohongshu.com/explore/123",
"douyin": "https://www.douyin.com/video/123",
"linkedin": "https://www.linkedin.com/in/test",
"bosszhipin": "https://www.zhipin.com/web/geek/job?query=python",
"weibo": "https://weibo.com/u/1749127163",
"rss": "https://example.com/feed.xml",
"exa_search": "https://example.com",
"web": "https://example.com",
}
for ch in get_all_channels():
sample = url_samples.get(ch.name, "https://example.com")
result = ch.can_handle(sample)
assert isinstance(result, bool)