@@ -11,8 +11,7 @@ test("tagToString returns full tag string when under length limit", () => {
1111 expect ( tagToString ( tag ) ) . toBe ( "/normal/path/to/repo::main::12345" ) ;
1212} ) ;
1313
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" , ( ) => {
1615 const longPrefix = "/very/long/path/that/will/be/truncated/" ;
1716 const importantSuffix = "/user/important-project/src/feature" ;
1817 const longPath = longPrefix + "x" . repeat ( 200 ) + importantSuffix ;
@@ -25,18 +24,14 @@ test("tagToString truncates beginning of directory when path is too long", () =>
2524
2625 const result = tagToString ( tag ) ;
2726
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
3327 expect ( result ) . toContain ( "::feature-branch::67890" ) ;
34- // The result should be within the MAX_TABLE_NAME_LENGTH limit (240)
3528 expect ( result . length ) . toBeLessThanOrEqual ( 240 ) ;
29+ expect ( result ) . toMatch ( / ^ [ a - f 0 - 9 ] { 8 } _ / ) ;
30+ expect ( result ) . toContain ( importantSuffix ) ;
3631} ) ;
3732
3833test ( "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 ) ;
4035 const tag : IndexTag = {
4136 directory : longPath ,
4237 branch : "release-v2.0" ,
@@ -45,14 +40,56 @@ test("tagToString preserves branch and artifactId exactly, even when truncating"
4540
4641 const result = tagToString ( tag ) ;
4742
48- // Should contain the exact branch and artifactId
4943 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 } _ / ) ;
5745 expect ( result . length ) . toBeLessThanOrEqual ( 240 ) ;
5846} ) ;
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