@@ -43,7 +43,7 @@ def test_calls_correct_url_and_json_payload(self, mock_post):
4343 "https://gitlab.example.com/api/v4/projects/99/statuses/abc123def456" ,
4444 json = {
4545 "state" : "success" ,
46- "context" : "socket-security" ,
46+ "context" : "socket-security-commit-status " ,
4747 "description" : "No blocking issues" ,
4848 "ref" : "feature" ,
4949 "target_url" : "https://app.socket.dev/report/123" ,
@@ -111,6 +111,57 @@ def test_auth_fallback_on_401(self, mock_post):
111111 assert "PRIVATE-TOKEN" in fallback_headers
112112
113113
114+ class TestEnableMergePipelineCheck :
115+ """Test Gitlab.enable_merge_pipeline_check()"""
116+
117+ @patch ("socketsecurity.core.scm.gitlab.requests.put" )
118+ def test_calls_correct_url_and_payload (self , mock_put ):
119+ mock_put .return_value = MagicMock (status_code = 200 )
120+ config = _make_gitlab_config ()
121+ gl = Gitlab (client = MagicMock (), config = config )
122+
123+ gl .enable_merge_pipeline_check ()
124+
125+ mock_put .assert_called_once_with (
126+ "https://gitlab.example.com/api/v4/projects/99" ,
127+ json = {"only_allow_merge_if_pipeline_succeeds" : True },
128+ headers = config .headers ,
129+ )
130+
131+ @patch ("socketsecurity.core.scm.gitlab.requests.put" )
132+ def test_skipped_when_no_mr_project_id (self , mock_put ):
133+ config = _make_gitlab_config (mr_project_id = None )
134+ gl = Gitlab (client = MagicMock (), config = config )
135+
136+ gl .enable_merge_pipeline_check ()
137+
138+ mock_put .assert_not_called ()
139+
140+ @patch ("socketsecurity.core.scm.gitlab.requests.put" )
141+ def test_auth_fallback_on_401 (self , mock_put ):
142+ resp_401 = MagicMock (status_code = 401 )
143+ resp_200 = MagicMock (status_code = 200 )
144+ mock_put .side_effect = [resp_401 , resp_200 ]
145+
146+ config = _make_gitlab_config ()
147+ gl = Gitlab (client = MagicMock (), config = config )
148+
149+ gl .enable_merge_pipeline_check ()
150+
151+ assert mock_put .call_count == 2
152+ fallback_headers = mock_put .call_args_list [1 ].kwargs ["headers" ]
153+ assert "PRIVATE-TOKEN" in fallback_headers
154+
155+ @patch ("socketsecurity.core.scm.gitlab.requests.put" )
156+ def test_graceful_error_handling (self , mock_put ):
157+ mock_put .side_effect = Exception ("connection error" )
158+ config = _make_gitlab_config ()
159+ gl = Gitlab (client = MagicMock (), config = config )
160+
161+ # Should not raise
162+ gl .enable_merge_pipeline_check ()
163+
164+
114165class TestEnableCommitStatusCliArg :
115166 """Test --enable-commit-status CLI argument parsing"""
116167
0 commit comments