@@ -38,15 +38,31 @@ describe('Pre-Receive Hook Execution', function () {
38
38
) . to . be . true ;
39
39
} ) ;
40
40
41
- it ( 'should fail when hook file does not exist' , async ( ) => {
41
+ it ( 'should skip execution when hook file does not exist' , async ( ) => {
42
42
const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/missing-hook.sh' ) ;
43
43
44
44
const result = await exec ( req , action , scriptPath ) ;
45
45
46
46
expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
47
- expect ( result . steps [ 0 ] . error ) . to . be . true ;
47
+ expect ( result . steps [ 0 ] . error ) . to . be . false ;
48
+ expect (
49
+ result . steps [ 0 ] . logs . some ( ( log ) =>
50
+ log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
51
+ ) ,
52
+ ) . to . be . true ;
53
+ } ) ;
54
+
55
+ it ( 'should skip execution when hook directory does not exist' , async ( ) => {
56
+ const scriptPath = path . resolve ( __dirname , 'non-existent-directory/pre-receive.sh' ) ;
57
+
58
+ const result = await exec ( req , action , scriptPath ) ;
59
+
60
+ expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
61
+ expect ( result . steps [ 0 ] . error ) . to . be . false ;
48
62
expect (
49
- result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Hook execution error: Hook file not found' ) ) ,
63
+ result . steps [ 0 ] . logs . some ( ( log ) =>
64
+ log . includes ( 'Pre-receive hook not found, skipping execution.' ) ,
65
+ ) ,
50
66
) . to . be . true ;
51
67
} ) ;
52
68
@@ -66,4 +82,18 @@ describe('Pre-Receive Hook Execution', function () {
66
82
67
83
expect ( action . steps ) . to . deep . include ( step ) ;
68
84
} ) ;
85
+
86
+ it ( 'should catch and handle unexpected errors' , async ( ) => {
87
+ const scriptPath = path . resolve ( __dirname , 'pre-receive-hooks/always-allow.sh' ) ;
88
+
89
+ sinon . stub ( require ( 'fs' ) , 'existsSync' ) . throws ( new Error ( 'Unexpected FS error' ) ) ;
90
+
91
+ const result = await exec ( req , action , scriptPath ) ;
92
+
93
+ expect ( result . steps ) . to . have . lengthOf ( 1 ) ;
94
+ expect ( result . steps [ 0 ] . error ) . to . be . true ;
95
+ expect (
96
+ result . steps [ 0 ] . logs . some ( ( log ) => log . includes ( 'Hook execution error: Unexpected FS error' ) ) ,
97
+ ) . to . be . true ;
98
+ } ) ;
69
99
} ) ;
0 commit comments