1- """Tests for the eyes- reaction dedup logic used to filter ignore comments for telemetry."""
1+ """Tests for the +1 reaction dedup logic used to filter ignore comments for telemetry."""
22
33from unittest .mock import Mock
44
55from socketsecurity .core .classes import Comment
66from socketsecurity .core .scm_comments import Comments
77
88
9- def _make_comment (body : str , eyes : int = 0 , comment_id : int = 1 , user : dict | None = None ) -> Comment :
9+ def _make_comment (body : str , thumbs_up : int = 0 , comment_id : int = 1 , user : dict | None = None ) -> Comment :
1010 return Comment (
1111 id = comment_id ,
1212 body = body ,
1313 body_list = body .split ("\n " ),
14- reactions = {"eyes" : eyes , " +1" : 1 },
14+ reactions = {"+1" : thumbs_up },
1515 user = user or {"login" : "test-user" , "id" : 123 },
1616 )
1717
1818
1919def _filter_unprocessed (comments : list [Comment ], scm = None ) -> list [Comment ]:
2020 """Mirrors the _is_unprocessed logic in socketcli.py."""
2121 def _is_unprocessed (c ):
22- if getattr (c , "reactions" , {}).get ("eyes " ):
22+ if getattr (c , "reactions" , {}).get ("+1 " ):
2323 return False
24- if hasattr (scm , "has_eyes_reaction " ) and scm .has_eyes_reaction (c .id ):
24+ if hasattr (scm , "has_thumbsup_reaction " ) and scm .has_thumbsup_reaction (c .id ):
2525 return False
2626 return True
2727
2828 return [c for c in comments if _is_unprocessed (c )]
2929
3030
3131class TestUnprocessedIgnoreFiltering :
32- def test_returns_comments_without_eyes (self ):
32+ def test_returns_comments_without_thumbsup (self ):
3333 comments = [
34- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 0 , comment_id = 1 ),
35- _make_comment ("SocketSecurity ignore npm/express@4.18.2" , eyes = 0 , comment_id = 2 ),
34+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 0 , comment_id = 1 ),
35+ _make_comment ("SocketSecurity ignore npm/express@4.18.2" , thumbs_up = 0 , comment_id = 2 ),
3636 ]
3737 result = _filter_unprocessed (comments )
3838 assert len (result ) == 2
3939
40- def test_excludes_comments_with_eyes (self ):
40+ def test_excludes_comments_with_thumbsup (self ):
4141 comments = [
42- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
43- _make_comment ("SocketSecurity ignore npm/express@4.18.2" , eyes = 0 , comment_id = 2 ),
42+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
43+ _make_comment ("SocketSecurity ignore npm/express@4.18.2" , thumbs_up = 0 , comment_id = 2 ),
4444 ]
4545 result = _filter_unprocessed (comments )
4646 assert len (result ) == 1
4747 assert result [0 ].id == 2
4848
4949 def test_returns_empty_when_all_processed (self ):
5050 comments = [
51- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
52- _make_comment ("SocketSecurity ignore-all" , eyes = 2 , comment_id = 2 ),
51+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
52+ _make_comment ("SocketSecurity ignore-all" , thumbs_up = 2 , comment_id = 2 ),
5353 ]
5454 result = _filter_unprocessed (comments )
5555 assert len (result ) == 0
@@ -66,58 +66,58 @@ def test_handles_empty_reactions_dict(self):
6666 result = _filter_unprocessed ([c ])
6767 assert len (result ) == 1
6868
69- def test_handles_reactions_with_eyes_zero (self ):
70- c = _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , eyes = 0 , comment_id = 1 )
69+ def test_handles_reactions_with_thumbsup_zero (self ):
70+ c = _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , thumbs_up = 0 , comment_id = 1 )
7171 result = _filter_unprocessed ([c ])
7272 assert len (result ) == 1
7373
7474
7575class TestUnprocessedIgnoreFilteringWithScmFallback :
76- """Tests for the has_eyes_reaction fallback path (GitLab)."""
76+ """Tests for the has_thumbsup_reaction fallback path (GitLab)."""
7777
7878 def test_scm_fallback_excludes_processed_comments (self ):
79- """When inline reactions.eyes is 0 but scm says it has eyes , exclude it."""
79+ """When inline reactions['+1'] is 0 but scm says it has thumbsup , exclude it."""
8080 comments = [
81- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 0 , comment_id = 1 ),
82- _make_comment ("SocketSecurity ignore npm/express@4.18.2" , eyes = 0 , comment_id = 2 ),
81+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 0 , comment_id = 1 ),
82+ _make_comment ("SocketSecurity ignore npm/express@4.18.2" , thumbs_up = 0 , comment_id = 2 ),
8383 ]
8484 scm = Mock ()
85- scm .has_eyes_reaction = Mock (side_effect = lambda cid : cid == 1 )
85+ scm .has_thumbsup_reaction = Mock (side_effect = lambda cid : cid == 1 )
8686
8787 result = _filter_unprocessed (comments , scm = scm )
8888 assert len (result ) == 1
8989 assert result [0 ].id == 2
9090
91- def test_scm_fallback_not_called_when_inline_eyes_present (self ):
92- """When inline reactions.eyes is truthy, scm.has_eyes_reaction should not be called."""
91+ def test_scm_fallback_not_called_when_inline_thumbsup_present (self ):
92+ """When inline reactions['+1'] is truthy, scm.has_thumbsup_reaction should not be called."""
9393 comments = [
94- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
94+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
9595 ]
9696 scm = Mock ()
97- scm .has_eyes_reaction = Mock (return_value = False )
97+ scm .has_thumbsup_reaction = Mock (return_value = False )
9898
9999 result = _filter_unprocessed (comments , scm = scm )
100100 assert len (result ) == 0
101- scm .has_eyes_reaction .assert_not_called ()
101+ scm .has_thumbsup_reaction .assert_not_called ()
102102
103- def test_scm_without_has_eyes_reaction_skips_fallback (self ):
104- """When scm doesn't have has_eyes_reaction (e.g. GitHub), only inline check runs."""
103+ def test_scm_without_has_thumbsup_reaction_skips_fallback (self ):
104+ """When scm doesn't have has_thumbsup_reaction (e.g. GitHub), only inline check runs."""
105105 comments = [
106- _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , eyes = 0 , comment_id = 1 ),
106+ _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , thumbs_up = 0 , comment_id = 1 ),
107107 ]
108108 scm = Mock (spec = []) # no methods at all
109109
110110 result = _filter_unprocessed (comments , scm = scm )
111111 assert len (result ) == 1
112112
113113 def test_scm_fallback_returns_all_unprocessed (self ):
114- """When scm says none have eyes , all are returned."""
114+ """When scm says none have thumbsup , all are returned."""
115115 comments = [
116- _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , eyes = 0 , comment_id = 1 ),
117- _make_comment ("SocketSecurity ignore npm/bar@2.0.0" , eyes = 0 , comment_id = 2 ),
116+ _make_comment ("SocketSecurity ignore npm/foo@1.0.0" , thumbs_up = 0 , comment_id = 1 ),
117+ _make_comment ("SocketSecurity ignore npm/bar@2.0.0" , thumbs_up = 0 , comment_id = 2 ),
118118 ]
119119 scm = Mock ()
120- scm .has_eyes_reaction = Mock (return_value = False )
120+ scm .has_thumbsup_reaction = Mock (return_value = False )
121121
122122 result = _filter_unprocessed (comments , scm = scm )
123123 assert len (result ) == 2
@@ -128,9 +128,9 @@ class TestUnprocessedIgnoreFilteringWithCommentsParsing:
128128
129129 def test_only_new_artifacts_are_parsed (self ):
130130 comments = [
131- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
132- _make_comment ("SocketSecurity ignore npm/express@4.18.2" , eyes = 0 , comment_id = 2 ),
133- _make_comment ("SocketSecurity ignore npm/axios@1.6.0" , eyes = 0 , comment_id = 3 ),
131+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
132+ _make_comment ("SocketSecurity ignore npm/express@4.18.2" , thumbs_up = 0 , comment_id = 2 ),
133+ _make_comment ("SocketSecurity ignore npm/axios@1.6.0" , thumbs_up = 0 , comment_id = 3 ),
134134 ]
135135 unprocessed = _filter_unprocessed (comments )
136136 unprocessed_comments = {"ignore" : unprocessed }
@@ -143,8 +143,8 @@ def test_only_new_artifacts_are_parsed(self):
143143
144144 def test_ignore_all_from_unprocessed (self ):
145145 comments = [
146- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
147- _make_comment ("SocketSecurity ignore-all" , eyes = 0 , comment_id = 2 ),
146+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
147+ _make_comment ("SocketSecurity ignore-all" , thumbs_up = 0 , comment_id = 2 ),
148148 ]
149149 unprocessed = _filter_unprocessed (comments )
150150 unprocessed_comments = {"ignore" : unprocessed }
@@ -154,8 +154,8 @@ def test_ignore_all_from_unprocessed(self):
154154
155155 def test_no_unprocessed_means_no_telemetry (self ):
156156 comments = [
157- _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , eyes = 1 , comment_id = 1 ),
158- _make_comment ("SocketSecurity ignore npm/express@4.18.2" , eyes = 2 , comment_id = 2 ),
157+ _make_comment ("SocketSecurity ignore npm/lodash@4.17.21" , thumbs_up = 1 , comment_id = 1 ),
158+ _make_comment ("SocketSecurity ignore npm/express@4.18.2" , thumbs_up = 2 , comment_id = 2 ),
159159 ]
160160 unprocessed = _filter_unprocessed (comments )
161161 assert len (unprocessed ) == 0
@@ -228,7 +228,7 @@ def test_gitlab_author_populates_sender(self):
228228 c = Comment (
229229 id = 1 , body = "SocketSecurity ignore npm/foo@1.0.0" ,
230230 body_list = ["SocketSecurity ignore npm/foo@1.0.0" ],
231- reactions = {"eyes " : 0 },
231+ reactions = {"+1 " : 0 },
232232 author = {"username" : "gitlab-dev" , "id" : 42 },
233233 )
234234 event = _build_event (c , artifact_input = "npm/foo@1.0.0" )
0 commit comments