-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathtest_github.py
More file actions
119 lines (104 loc) · 3.56 KB
/
Copy pathtest_github.py
File metadata and controls
119 lines (104 loc) · 3.56 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
"""Tests for GitHub review normalization used by the PR approval agent."""
import pytest
from github import _normalize_pr_reactions, _normalize_reviews_for_prompt
def test_normalize_reviews_marks_current_head_and_preserves_stale_reviews() -> None:
head_sha = "072cdd75592bfd0bf0c016209385f20f85a45201"
current_review = {
"user": {"login": "stamphog", "type": "Bot"},
"state": "COMMENTED",
"body": "Current head concern",
"commit_id": head_sha,
"submitted_at": "2026-04-07T20:14:03Z",
"author_association": "BOT",
}
stale_review = {
"user": {"login": "greptile-apps", "type": "Bot"},
"state": "COMMENTED",
"body": "Older concern",
"commit_id": "3c51bb8de4c73929c5266986118a14b966cb6831",
"submitted_at": "2026-04-07T20:02:32Z",
"author_association": "BOT",
}
normalized = _normalize_reviews_for_prompt([current_review, stale_review], head_sha)
assert normalized == [
{
"user": "stamphog",
"state": "COMMENTED",
"body": "Current head concern",
"commit_id": head_sha,
"is_current_head": True,
"submitted_at": "2026-04-07T20:14:03Z",
},
{
"user": "greptile-apps",
"state": "COMMENTED",
"body": "Older concern",
"commit_id": "3c51bb8de4c73929c5266986118a14b966cb6831",
"is_current_head": False,
"submitted_at": "2026-04-07T20:02:32Z",
},
]
@pytest.mark.parametrize(
"author_association,user_type,expected_count",
[
pytest.param("MEMBER", "User", 1, id="member-reviewer"),
pytest.param("OWNER", "User", 1, id="owner-reviewer"),
pytest.param("COLLABORATOR", "User", 1, id="collaborator-reviewer"),
pytest.param("BOT", "User", 1, id="bot-association"),
pytest.param("NONE", "Bot", 1, id="bot-user-type"),
pytest.param("NONE", "User", 0, id="untrusted-reviewer"),
],
)
def test_normalize_reviews_filters_by_trust_source(
author_association: str, user_type: str, expected_count: int
) -> None:
normalized = _normalize_reviews_for_prompt(
[
{
"user": {"login": "reviewer", "type": user_type},
"state": "COMMENTED",
"body": "Review body",
"commit_id": "abc123",
"submitted_at": "2026-04-07T20:14:03Z",
"author_association": author_association,
}
],
"abc123",
)
assert len(normalized) == expected_count
def test_normalize_pr_reactions_keeps_trusted_reviewer_bots() -> None:
reactions = _normalize_pr_reactions(
[
{
"user": {"login": "posthog[bot]"},
"content": "+1",
"created_at": "2026-07-20T17:04:26Z",
}
],
"author",
)
assert reactions == [
{
"user": "posthog[bot]",
"emoji": "👍",
"created_at": "2026-07-20T17:04:26Z",
}
]
@pytest.mark.parametrize(
"login,author",
[
pytest.param("someone[bot]", "author", id="untrusted-bot"),
pytest.param("posthog[bot]", "posthog[bot]", id="author-self-reaction"),
],
)
def test_normalize_pr_reactions_rejects_untrusted_or_author_reactions(login: str, author: str) -> None:
reactions = _normalize_pr_reactions(
[
{
"user": {"login": login},
"content": "+1",
}
],
author,
)
assert reactions == []