@@ -19,23 +19,24 @@ describe('Pre-Receive Hook Execution', function () {
19
19
addStep : function ( step ) {
20
20
this . steps . push ( step ) ;
21
21
} ,
22
+ setAllowAutoApprover : sinon . stub ( ) ,
22
23
} ;
23
24
} ) ;
24
25
25
26
afterEach ( ( ) => {
26
27
sinon . restore ( ) ;
27
28
} ) ;
28
29
29
- it ( 'should execute hook successfully' , async ( ) => {
30
- const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-allow .sh' ) ;
30
+ it ( 'should execute hook successfully and require manual approval ' , async ( ) => {
31
+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-exit-1 .sh' ) ;
31
32
32
33
const result = await exec ( req , action , scriptPath ) ;
33
34
34
35
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
35
36
expect ( result . steps [ 0 ] . error ) . to . be . false ;
36
- expect (
37
- result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Pre-receive hook executed successfully' ) ) ,
38
- ) . to . be . true ;
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 ;
39
40
} ) ;
40
41
41
42
it ( 'should skip execution when hook file does not exist' , async ( ) => {
@@ -50,6 +51,7 @@ describe('Pre-Receive Hook Execution', function () {
50
51
log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
51
52
) ,
52
53
) . to . be . true ;
54
+ expect ( action . setAllowAutoApprover . called ) . to . be . false ;
53
55
} ) ;
54
56
55
57
it ( 'should skip execution when hook directory does not exist' , async ( ) => {
@@ -64,6 +66,7 @@ describe('Pre-Receive Hook Execution', function () {
64
66
log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
65
67
) ,
66
68
) . to . be . true ;
69
+ expect ( action . setAllowAutoApprover . called ) . to . be . false ;
67
70
} ) ;
68
71
69
72
it ( 'should fail when hook execution returns an error' , async ( ) => {
@@ -76,11 +79,13 @@ describe('Pre-Receive Hook Execution', function () {
76
79
const step = result . steps [ 0 ] ;
77
80
78
81
expect ( step . error ) . to . be . true ;
82
+ expect ( step . logs . some ( ( log ) => log . includes ( 'Push rejected by pre-receive hook.' ) ) ) . to . be . true ;
79
83
expect ( step . logs . some ( ( log ) => log . includes ( 'Hook stderr:' ) ) ) . to . be . true ;
80
84
81
85
expect ( step . errorMessage ) . to . exist ;
82
86
83
87
expect ( action . steps ) . to . deep . include ( step ) ;
88
+ expect ( action . setAllowAutoApprover . called ) . to . be . false ;
84
89
} ) ;
85
90
86
91
it ( 'should catch and handle unexpected errors' , async ( ) => {
@@ -95,5 +100,21 @@ describe('Pre-Receive Hook Execution', function () {
95
100
expect (
96
101
result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Hook execution error: Unexpected FS error' ) ) ,
97
102
) . to . be . true ;
103
+ expect ( action . setAllowAutoApprover . called ) . to . be . false ;
104
+ } ) ;
105
+
106
+ it ( 'should approve push automatically when hook returns status 0' , async ( ) => {
107
+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-allow.sh' ) ;
108
+
109
+ const result = await exec ( req , action , scriptPath ) ;
110
+
111
+ expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
112
+ expect ( result . steps [ 0 ] . error ) . to . be . false ;
113
+ expect (
114
+ result . steps [ 0 ] . logs . some ( ( log ) =>
115
+ log . includes ( 'Push automatically approved by pre-receive hook.' ) ,
116
+ ) ,
117
+ ) . to . be . true ;
118
+ expect ( action . setAllowAutoApprover . calledOnce ) . to . be . true ;
98
119
} ) ;
99
120
} ) ;
0 commit comments