@@ -11,8 +11,7 @@ test("tagToString returns full tag string when under length limit", () => {
11
11
expect ( tagToString ( tag ) ) . toBe ( "/normal/path/to/repo::main::12345" ) ;
12
12
} ) ;
13
13
14
- test ( "tagToString truncates beginning of directory when path is too long" , ( ) => {
15
- // Create a very long directory path that exceeds MAX_DIR_LENGTH (200)
14
+ test ( "tagToString truncates beginning of directory when path is too long and adds hash for uniqueness" , ( ) => {
16
15
const longPrefix = "/very/long/path/that/will/be/truncated/" ;
17
16
const importantSuffix = "/user/important-project/src/feature" ;
18
17
const longPath = longPrefix + "x" . repeat ( 200 ) + importantSuffix ;
@@ -25,18 +24,14 @@ test("tagToString truncates beginning of directory when path is too long", () =>
25
24
26
25
const result = tagToString ( tag ) ;
27
26
28
- // The result should keep the important suffix part
29
- expect ( result ) . toContain ( importantSuffix ) ;
30
- // The result should NOT contain the beginning of the path
31
- expect ( result ) . not . toContain ( longPrefix ) ;
32
- // The result should include the branch and artifactId
33
27
expect ( result ) . toContain ( "::feature-branch::67890" ) ;
34
- // The result should be within the MAX_TABLE_NAME_LENGTH limit (240)
35
28
expect ( result . length ) . toBeLessThanOrEqual ( 240 ) ;
29
+ expect ( result ) . toMatch ( / ^ [ a - f 0 - 9 ] { 8 } _ / ) ;
30
+ expect ( result ) . toContain ( importantSuffix ) ;
36
31
} ) ;
37
32
38
33
test ( "tagToString preserves branch and artifactId exactly, even when truncating" , ( ) => {
39
- const longPath = "/a" . repeat ( 300 ) ; // Much longer than MAX_DIR_LENGTH
34
+ const longPath = "/a" . repeat ( 300 ) ;
40
35
const tag : IndexTag = {
41
36
directory : longPath ,
42
37
branch : "release-v2.0" ,
@@ -45,14 +40,56 @@ test("tagToString preserves branch and artifactId exactly, even when truncating"
45
40
46
41
const result = tagToString ( tag ) ;
47
42
48
- // Should contain the exact branch and artifactId
49
43
expect ( result ) . toContain ( "::release-v2.0::build-123" ) ;
50
- // Should contain the end of the path
51
- expect ( result ) . toContain ( "/a/a/a" ) ;
52
- // Should not contain the full original path (it should be truncated)
53
- expect ( result . length ) . toBeLessThan (
54
- longPath . length + "::release-v2.0::build-123" . length ,
55
- ) ;
56
- // The result should be within the MAX_TABLE_NAME_LENGTH limit
44
+ expect ( result ) . toMatch ( / ^ [ a - f 0 - 9 ] { 8 } _ / ) ;
57
45
expect ( result . length ) . toBeLessThanOrEqual ( 240 ) ;
58
46
} ) ;
47
+
48
+ test ( "tagToString ensures uniqueness for different long paths that would otherwise collide" , ( ) => {
49
+ const basePath = "/very/long/base/path/that/exceeds/limits/" ;
50
+ const commonSuffix = "/same/ending/path" ;
51
+
52
+ const tag1 : IndexTag = {
53
+ directory : basePath + "different1" + "x" . repeat ( 100 ) + commonSuffix ,
54
+ branch : "main" ,
55
+ artifactId : "12345" ,
56
+ } ;
57
+
58
+ const tag2 : IndexTag = {
59
+ directory : basePath + "different2" + "y" . repeat ( 100 ) + commonSuffix ,
60
+ branch : "main" ,
61
+ artifactId : "12345" ,
62
+ } ;
63
+
64
+ const fullString1 = `${ tag1 . directory } ::${ tag1 . branch } ::${ tag1 . artifactId } ` ;
65
+ const fullString2 = `${ tag2 . directory } ::${ tag2 . branch } ::${ tag2 . artifactId } ` ;
66
+
67
+ const result1 = tagToString ( tag1 ) ;
68
+ const result2 = tagToString ( tag2 ) ;
69
+
70
+ expect ( result1 ) . not . toBe ( result2 ) ;
71
+ expect ( result1 . length ) . toBeLessThanOrEqual ( 240 ) ;
72
+ expect ( result2 . length ) . toBeLessThanOrEqual ( 240 ) ;
73
+
74
+ if ( fullString1 . length > 240 ) {
75
+ expect ( result1 ) . toMatch ( / ^ [ a - f 0 - 9 ] { 8 } _ / ) ;
76
+ expect ( result2 ) . toMatch ( / ^ [ a - f 0 - 9 ] { 8 } _ / ) ;
77
+ } else {
78
+ expect ( result1 ) . toBe ( fullString1 ) ;
79
+ expect ( result2 ) . toBe ( fullString2 ) ;
80
+ }
81
+ } ) ;
82
+
83
+ test ( "tagToString produces consistent results for the same input" , ( ) => {
84
+ const tag : IndexTag = {
85
+ directory :
86
+ "/some/very/long/path/that/exceeds/the/maximum/length/limit/for/directory/names/in/the/system" ,
87
+ branch : "develop" ,
88
+ artifactId : "test-123" ,
89
+ } ;
90
+
91
+ const result1 = tagToString ( tag ) ;
92
+ const result2 = tagToString ( tag ) ;
93
+
94
+ expect ( result1 ) . toBe ( result2 ) ;
95
+ } ) ;
0 commit comments