@@ -19,26 +19,15 @@ describe('Pre-Receive Hook Execution', function () {
1919 addStep : function ( step ) {
2020 this . steps . push ( step ) ;
2121 } ,
22- setAllowAutoApprover : sinon . stub ( ) ,
22+ setAutoApproval : sinon . stub ( ) ,
23+ setAutoRejection : sinon . stub ( ) ,
2324 } ;
2425 } ) ;
2526
2627 afterEach ( ( ) => {
2728 sinon . restore ( ) ;
2829 } ) ;
2930
30- it ( 'should execute hook successfully and require manual approval' , async ( ) => {
31- const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-1.sh' ) ;
32-
33- const result = await exec ( req , action , scriptPath ) ;
34-
35- expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
36- expect ( result . steps [ 0 ] . error ) . to . be . false ;
37- expect ( result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Push requires manual approval.' ) ) ) . to . be
38- . true ;
39- expect ( action . setAllowAutoApprover . called ) . to . be . false ;
40- } ) ;
41-
4231 it ( 'should skip execution when hook file does not exist' , async ( ) => {
4332 const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/missing-hook.sh' ) ;
4433
@@ -51,7 +40,8 @@ describe('Pre-Receive Hook Execution', function () {
5140 log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
5241 ) ,
5342 ) . to . be . true ;
54- expect ( action . setAllowAutoApprover . called ) . to . be . false ;
43+ expect ( action . setAutoApproval . called ) . to . be . false ;
44+ expect ( action . setAutoRejection . called ) . to . be . false ;
5545 } ) ;
5646
5747 it ( 'should skip execution when hook directory does not exist' , async ( ) => {
@@ -66,30 +56,12 @@ describe('Pre-Receive Hook Execution', function () {
6656 log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
6757 ) ,
6858 ) . to . be . true ;
69- expect ( action . setAllowAutoApprover . called ) . to . be . false ;
70- } ) ;
71-
72- it ( 'should fail when hook execution returns an error' , async ( ) => {
73- const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-reject.sh' ) ;
74-
75- const result = await exec ( req , action , scriptPath ) ;
76-
77- expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
78-
79- const step = result . steps [ 0 ] ;
80-
81- expect ( step . error ) . to . be . true ;
82- expect ( step . logs . some ( ( log ) => log . includes ( 'Push rejected by pre-receive hook.' ) ) ) . to . be . true ;
83- expect ( step . logs . some ( ( log ) => log . includes ( 'Hook stderr:' ) ) ) . to . be . true ;
84-
85- expect ( step . errorMessage ) . to . exist ;
86-
87- expect ( action . steps ) . to . deep . include ( step ) ;
88- expect ( action . setAllowAutoApprover . called ) . to . be . false ;
59+ expect ( action . setAutoApproval . called ) . to . be . false ;
60+ expect ( action . setAutoRejection . called ) . to . be . false ;
8961 } ) ;
9062
9163 it ( 'should catch and handle unexpected errors' , async ( ) => {
92- const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-allow .sh' ) ;
64+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-0 .sh' ) ;
9365
9466 sinon . stub ( require ( 'fs' ) , 'existsSync' ) . throws ( new Error ( 'Unexpected FS error' ) ) ;
9567
@@ -100,11 +72,12 @@ describe('Pre-Receive Hook Execution', function () {
10072 expect (
10173 result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Hook execution error: Unexpected FS error' ) ) ,
10274 ) . to . be . true ;
103- expect ( action . setAllowAutoApprover . called ) . to . be . false ;
75+ expect ( action . setAutoApproval . called ) . to . be . false ;
76+ expect ( action . setAutoRejection . called ) . to . be . false ;
10477 } ) ;
10578
10679 it ( 'should approve push automatically when hook returns status 0' , async ( ) => {
107- const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-allow .sh' ) ;
80+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-0 .sh' ) ;
10881
10982 const result = await exec ( req , action , scriptPath ) ;
11083
@@ -115,6 +88,36 @@ describe('Pre-Receive Hook Execution', function () {
11588 log . includes ( 'Push automatically approved by pre-receive hook.' ) ,
11689 ) ,
11790 ) . to . be . true ;
118- expect ( action . setAllowAutoApprover . calledOnce ) . to . be . true ;
91+ expect ( action . setAutoApproval . calledOnce ) . to . be . true ;
92+ expect ( action . setAutoRejection . called ) . to . be . false ;
93+ } ) ;
94+
95+ it ( 'should reject push automatically when hook returns status 1' , async ( ) => {
96+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-1.sh' ) ;
97+
98+ const result = await exec ( req , action , scriptPath ) ;
99+
100+ expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
101+ expect ( result . steps [ 0 ] . error ) . to . be . false ;
102+ expect (
103+ result . steps [ 0 ] . logs . some ( ( log ) =>
104+ log . includes ( 'Push automatically rejected by pre-receive hook.' ) ,
105+ ) ,
106+ ) . to . be . true ;
107+ expect ( action . setAutoRejection . calledOnce ) . to . be . true ;
108+ expect ( action . setAutoApproval . called ) . to . be . false ;
109+ } ) ;
110+
111+ it ( 'should execute hook successfully and require manual approval' , async ( ) => {
112+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-2.sh' ) ;
113+
114+ const result = await exec ( req , action , scriptPath ) ;
115+
116+ expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
117+ expect ( result . steps [ 0 ] . error ) . to . be . false ;
118+ expect ( result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Push requires manual approval.' ) ) ) . to . be
119+ . true ;
120+ expect ( action . setAutoApproval . called ) . to . be . false ;
121+ expect ( action . setAutoRejection . called ) . to . be . false ;
119122 } ) ;
120123} ) ;
0 commit comments