| 1 | import { IndexTag } from ".."; |
| 2 | import { tagToString } from "./utils"; |
| 3 | |
| 4 | test("tagToString returns full tag string when under length limit", () => { |
| 5 | const tag: IndexTag = { |
| 6 | directory: "/normal/path/to/repo", |
| 7 | branch: "main", |
| 8 | artifactId: "12345", |
| 9 | }; |
| 10 | |
| 11 | expect(tagToString(tag)).toBe("/normal/path/to/repo::main::12345"); |
| 12 | }); |
| 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) |
| 16 | const longPrefix = "/very/long/path/that/will/be/truncated/"; |
| 17 | const importantSuffix = "/user/important-project/src/feature"; |
| 18 | const longPath = longPrefix + "x".repeat(200) + importantSuffix; |
| 19 | |
| 20 | const tag: IndexTag = { |
| 21 | directory: longPath, |
| 22 | branch: "feature-branch", |
| 23 | artifactId: "67890", |
| 24 | }; |
| 25 | |
| 26 | const result = tagToString(tag); |
| 27 | |
| 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 | expect(result).toContain("::feature-branch::67890"); |
| 34 | // The result should be within the MAX_TABLE_NAME_LENGTH limit (240) |
| 35 | expect(result.length).toBeLessThanOrEqual(240); |
| 36 | }); |
| 37 | |
| 38 | test("tagToString preserves branch and artifactId exactly, even when truncating", () => { |
| 39 | const longPath = "/a".repeat(300); // Much longer than MAX_DIR_LENGTH |
| 40 | const tag: IndexTag = { |
| 41 | directory: longPath, |
| 42 | branch: "release-v2.0", |
| 43 | artifactId: "build-123", |
| 44 | }; |
| 45 | |
| 46 | const result = tagToString(tag); |
| 47 | |
| 48 | // Should contain the exact branch and artifactId |
| 49 | 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 |
| 57 | expect(result.length).toBeLessThanOrEqual(240); |
| 58 | }); |