-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_radar_scan.py
More file actions
133 lines (116 loc) · 3.7 KB
/
Copy pathtest_radar_scan.py
File metadata and controls
133 lines (116 loc) · 3.7 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from __future__ import annotations
from datetime import date
import pytest
from tools.radar_scan import (
FORBIDDEN_CANDIDATE_KEYS,
build_document,
merge_candidates,
parse_github_search,
parse_hn_search,
parse_pypi_updates,
)
def test_github_payload_maps_to_discovery_facts_only() -> None:
payload = {
"items": [
{
"html_url": "https://github.com/owner/repo",
"stargazers_count": 42,
"license": {"spdx_id": "MIT"},
"description": "A tool that should never be copied",
}
]
}
candidates = parse_github_search(payload, date(2026, 9, 12))
assert candidates == [
{
"source": "github-search",
"url": "https://github.com/owner/repo",
"first_seen": "2026-09-12",
"stars": 42,
"license": "MIT",
}
]
def test_pypi_feed_parses_latest_release() -> None:
document = (
'<?xml version="1.0"?><rss><channel>'
"<item><link>https://pypi.org/project/thing/</link>"
"<title>thing 2.1.0</title></item>"
"<item><link>https://example.com/not-pypi</link>"
"<title>skip 1.0</title></item>"
"</channel></rss>"
)
candidates = parse_pypi_updates(document, date(2026, 9, 12))
assert candidates == [
{
"source": "pypi-updates",
"url": "https://pypi.org/project/thing",
"first_seen": "2026-09-12",
"latest_release": "2.1.0",
}
]
def test_hn_payload_keeps_urls_and_points_only() -> None:
payload = {
"hits": [
{"url": "https://github.com/owner/repo", "points": 7, "title": "show hn"},
{"url": "javascript:void(0)", "points": 1},
]
}
candidates = parse_hn_search(payload, date(2026, 9, 12))
assert candidates == [
{
"source": "hn-latest",
"url": "https://github.com/owner/repo",
"first_seen": "2026-09-12",
"points": 7,
}
]
def test_merge_drops_reviewed_urls_and_preserves_first_seen() -> None:
reviewed = {"https://github.com/owner/reviewed"}
fresh = [
{
"source": "github-search",
"url": "https://github.com/owner/repo",
"first_seen": "2026-09-12",
},
{
"source": "github-search",
"url": "https://github.com/owner/reviewed",
"first_seen": "2026-09-12",
},
]
previous = [
{
"source": "github-search",
"url": "https://github.com/owner/repo",
"first_seen": "2026-08-01",
}
]
merged = merge_candidates(fresh, previous, reviewed, limit=10)
assert len(merged) == 1
assert merged[0]["first_seen"] == "2026-08-01"
def test_merge_enforces_per_source_limit() -> None:
fresh = [
{
"source": "github-search",
"url": f"https://github.com/owner/repo{i}",
"first_seen": "2026-09-12",
}
for i in range(5)
]
merged = merge_candidates(fresh, [], set(), limit=2)
assert len(merged) == 2
def test_no_candidate_ever_carries_a_verdict_field() -> None:
poisoned = [
{
"source": "github-search",
"url": "https://github.com/owner/repo",
"first_seen": "2026-09-12",
"description": "generated text must never survive",
}
]
with pytest.raises(ValueError):
merge_candidates(poisoned, [], set(), limit=10)
def test_document_carries_the_human_review_note() -> None:
document = build_document([])
assert FORBIDDEN_CANDIDATE_KEYS.isdisjoint(document)
assert "human-authored" in document["note"]