@@ -143,6 +143,14 @@ it('uses GH_TOKEN to publish the finished CI report and update comments on rerun
143143 vi . stubEnv ( 'SOCKET_CLI_DISABLE_OVERVIEW_COMMENT' , '' )
144144 vi . stubEnv ( 'SOCKET_CLI_DISABLE_SECURITY_COMMENT' , '' )
145145 vi . resetModules ( )
146+ vi . doMock ( '../../utils/spawn.mts' , ( ) => ( {
147+ spawn : vi . fn ( async ( _command : string , args : string [ ] ) => ( {
148+ stdout :
149+ args ?. [ 0 ] === 'symbolic-ref'
150+ ? 'feature-branch'
151+ : 'git@github.com:example/project.git' ,
152+ } ) ) ,
153+ } ) )
146154 vi . doMock ( './fetch-default-org-slug.mts' , ( ) => ( {
147155 getDefaultOrgSlug : async ( ) => ( { ok : true , data : 'example' } ) ,
148156 } ) )
@@ -169,7 +177,21 @@ it('uses GH_TOKEN to publish the finished CI report and update comments on rerun
169177 id : 'diff-id' ,
170178 before_full_scan : { id : 'base' } ,
171179 after_full_scan : { id : 'test-scan' } ,
172- artifacts : { added : [ ] , updated : [ ] , replaced : [ ] } ,
180+ artifacts : {
181+ added : [ ] ,
182+ updated : [ ] ,
183+ replaced : [ ] ,
184+ unchanged : [
185+ {
186+ type : 'npm' ,
187+ name : 'left-pad' ,
188+ version : '1.0.0' ,
189+ alerts : [
190+ { action : 'error' , type : 'test-alert' , key : 'alert-1' } ,
191+ ] ,
192+ } ,
193+ ] ,
194+ } ,
173195 html_url : null ,
174196 } ,
175197 } ,
@@ -191,7 +213,12 @@ it('uses GH_TOKEN to publish the finished CI report and update comments on rerun
191213 } ) ,
192214 } ) )
193215 const { handleCi } = await import ( './handle-ci.mts' )
216+ process . exitCode = 0
194217 await handleCi ( false )
218+ expect ( process . exitCode ) . toBe ( 0 )
219+ await handleCi ( false , false , true )
220+ expect ( process . exitCode ) . toBe ( 1 )
221+ process . exitCode = 0
195222 expect ( comments . map ( c => c . body ) ) . toEqual ( [
196223 expect . stringContaining ( 'API overview' ) ,
197224 expect . stringContaining ( 'API alerts' ) ,
@@ -201,13 +228,22 @@ it('uses GH_TOKEN to publish the finished CI report and update comments on rerun
201228 await handleCi ( false )
202229 vi . stubEnv ( 'GITHUB_REF' , 'refs/heads/main' )
203230 await handleCi ( false )
204- expect ( fetchComments ) . toHaveBeenCalledTimes ( 3 )
205- expect ( writes ) . toEqual ( [ 'POST' , 'POST' , 'PATCH' , 'PATCH' , 'PATCH' ] )
231+ expect ( fetchComments ) . toHaveBeenCalledTimes ( 4 )
232+ expect ( writes ) . toEqual ( [
233+ 'POST' ,
234+ 'POST' ,
235+ 'PATCH' ,
236+ 'PATCH' ,
237+ 'PATCH' ,
238+ 'PATCH' ,
239+ 'PATCH' ,
240+ ] )
206241 expect ( comments ) . toHaveLength ( 2 )
207242 } finally {
208243 vi . unstubAllEnvs ( )
209244 vi . doUnmock ( './fetch-default-org-slug.mts' )
210245 vi . doUnmock ( './select-baseline-scan.mts' )
246+ vi . doUnmock ( '../../utils/spawn.mts' )
211247 vi . doUnmock ( '../../utils/api.mts' )
212248 vi . doUnmock ( '../scan/fetch-diff-scan.mts' )
213249 vi . doUnmock ( '../scan/handle-scan-report.mts' )
0 commit comments