6
6
exec,
7
7
getCommitData,
8
8
getPackMeta,
9
+ parsePacketLines,
9
10
unpack
10
11
} = require ( '../src/proxy/processors/push-action/parsePush' ) ;
11
12
@@ -16,15 +17,18 @@ const {
16
17
* @param {number } type - Type of the object (1 for commit).
17
18
* @return {Buffer } - The generated PACK buffer.
18
19
*/
19
- function createSamplePackBuffer ( numEntries = 1 , commitContent = 'tree 123\nparent 456\nauthor A <a@a> 123 +0000\ncommitter C <c@c> 456 +0000\n\nmessage' , type = 1 ) {
20
+ function createSamplePackBuffer (
21
+ numEntries = 1 ,
22
+ commitContent = 'tree 123\nparent 456\nauthor A <a@a> 123 +0000\ncommitter C <c@c> 456 +0000\n\nmessage' ,
23
+ type = 1 ,
24
+ ) {
20
25
const header = Buffer . alloc ( 12 ) ;
21
26
header . write ( 'PACK' , 0 , 4 , 'utf-8' ) ; // Signature
22
27
header . writeUInt32BE ( 2 , 4 ) ; // Version
23
28
header . writeUInt32BE ( numEntries , 8 ) ; // Number of entries
24
29
25
30
const originalContent = Buffer . from ( commitContent , 'utf8' ) ;
26
- // Actual zlib used for setup
27
- const compressedContent = zlib . deflateSync ( originalContent ) ;
31
+ const compressedContent = zlib . deflateSync ( originalContent ) ; // actual zlib for setup
28
32
29
33
// Basic type/size encoding (assumes small sizes for simplicity)
30
34
// Real PACK files use variable-length encoding for size
@@ -34,10 +38,8 @@ function createSamplePackBuffer(numEntries = 1, commitContent = 'tree 123\nparen
34
38
}
35
39
const objectHeader = Buffer . from ( [ typeAndSize ] ) ; // Placeholder, actual size encoding is complex
36
40
37
- // Combine parts
41
+ // Combine parts and append checksum
38
42
const packContent = Buffer . concat ( [ objectHeader , compressedContent ] ) ;
39
-
40
- // Append checksum (dummy 20 bytes)
41
43
const checksum = Buffer . alloc ( 20 ) ;
42
44
43
45
return Buffer . concat ( [ header , packContent , checksum ] ) ;
@@ -164,7 +166,7 @@ describe('parsePackFile', () => {
164
166
const step = action . steps [ 0 ] ;
165
167
expect ( step . stepName ) . to . equal ( 'parsePackFile' ) ;
166
168
expect ( step . error ) . to . be . true ;
167
- expect ( step . errorMessage ) . to . include ( 'Unable to parse push ' ) ;
169
+ expect ( step . errorMessage ) . to . include ( 'PACK data is missing ' ) ;
168
170
169
171
expect ( action . branch ) . to . equal ( ref ) ;
170
172
expect ( action . setCommit . calledOnceWith ( oldCommit , newCommit ) ) . to . be . true ;
@@ -178,8 +180,8 @@ describe('parsePackFile', () => {
178
180
179
181
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
180
182
parent abcdef1234567890abcdef1234567890abcdef12
181
- author Test Author <test @example.com> 1678886400 +0000
182
- committer Test Committer <[email protected] > 1678886460 +0100
183
+ author Test Author <author @example.com> 1234567890 +0000
184
+ committer Test Committer <[email protected] > 1234567890 +0000
183
185
184
186
feat: Add new feature
185
187
@@ -217,9 +219,9 @@ describe('parsePackFile', () => {
217
219
expect ( parsedCommit . parent ) . to . equal ( 'abcdef1234567890abcdef1234567890abcdef12' ) ;
218
220
expect ( parsedCommit . author ) . to . equal ( 'Test Author' ) ;
219
221
expect ( parsedCommit . committer ) . to . equal ( 'Test Committer' ) ;
220
- expect ( parsedCommit . commitTimestamp ) . to . equal ( '1678886460 ' ) ;
222
+ expect ( parsedCommit . commitTimestamp ) . to . equal ( '1234567890 ' ) ;
221
223
expect ( parsedCommit . message ) . to . equal ( 'feat: Add new feature\n\nThis is the commit body.' ) ;
222
- expect ( parsedCommit . authorEmail ) . to . equal ( 'test @example.com' ) ;
224
+ expect ( parsedCommit . authorEmail ) . to . equal ( 'author @example.com' ) ;
223
225
224
226
expect ( step . content . meta ) . to . deep . equal ( {
225
227
sig : 'PACK' ,
@@ -236,8 +238,8 @@ describe('parsePackFile', () => {
236
238
237
239
// Commit content without a parent line
238
240
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
239
- author Test Author <[email protected] > 1678886400 +0000
240
- committer Test Committer <[email protected] > 1678886460 +0100
241
+ author Test Author <[email protected] > 1234567890 +0000
242
+ committer Test Committer <[email protected] > 1234567890 +0100
241
243
242
244
feat: Initial commit` ;
243
245
const parentFromCommit = '0' . repeat ( 40 ) ; // Expected parent hash
@@ -278,8 +280,8 @@ describe('parsePackFile', () => {
278
280
const commitContent = `tree 1234567890abcdef1234567890abcdef12345678
279
281
parent ${ parent1 }
280
282
parent ${ parent2 }
281
- author Test Author <[email protected] > 1678886400 +0000
282
- committer Test Committer <[email protected] > 1678886460 +0100
283
+ author Test Author <[email protected] > 1234567890 +0000
284
+ committer Test Committer <[email protected] > 1234567890 +0100
283
285
284
286
Merge branch 'feature'` ;
285
287
@@ -314,7 +316,7 @@ describe('parsePackFile', () => {
314
316
315
317
// Malformed commit content - missing tree line
316
318
const commitContent = `parent abcdef1234567890abcdef1234567890abcdef12
317
- author Test Author <test @example.com> 1678886400 +0000
319
+ author Test Author <author @example.com> 1678886400 +0000
318
320
committer Test Committer <[email protected] > 1678886460 +0100
319
321
320
322
feat: Missing tree` ;
0 commit comments