@@ -19,26 +19,15 @@ describe('Pre-Receive Hook Execution', function () {
19
19
addStep : function ( step ) {
20
20
this . steps . push ( step ) ;
21
21
} ,
22
- setAllowAutoApprover : sinon . stub ( ) ,
22
+ setAutoApproval : sinon . stub ( ) ,
23
+ setAutoRejection : sinon . stub ( ) ,
23
24
} ;
24
25
} ) ;
25
26
26
27
afterEach ( ( ) => {
27
28
sinon . restore ( ) ;
28
29
} ) ;
29
30
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
-
42
31
it ( 'should skip execution when hook file does not exist' , async ( ) => {
43
32
const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/missing-hook.sh' ) ;
44
33
@@ -51,7 +40,8 @@ describe('Pre-Receive Hook Execution', function () {
51
40
log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
52
41
) ,
53
42
) . 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 ;
55
45
} ) ;
56
46
57
47
it ( 'should skip execution when hook directory does not exist' , async ( ) => {
@@ -66,30 +56,12 @@ describe('Pre-Receive Hook Execution', function () {
66
56
log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
67
57
) ,
68
58
) . 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 ;
89
61
} ) ;
90
62
91
63
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' ) ;
93
65
94
66
sinon . stub ( require ( 'fs' ) , 'existsSync' ) . throws ( new Error ( 'Unexpected FS error' ) ) ;
95
67
@@ -100,11 +72,12 @@ describe('Pre-Receive Hook Execution', function () {
100
72
expect (
101
73
result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Hook execution error: Unexpected FS error' ) ) ,
102
74
) . 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 ;
104
77
} ) ;
105
78
106
79
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' ) ;
108
81
109
82
const result = await exec ( req , action , scriptPath ) ;
110
83
@@ -115,6 +88,36 @@ describe('Pre-Receive Hook Execution', function () {
115
88
log . includes ( 'Push automatically approved by pre-receive hook.' ) ,
116
89
) ,
117
90
) . 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 ;
119
122
} ) ;
120
123
} ) ;
0 commit comments