Elffuss BraidHub

kikocis/continue public

main · 2.9 KiBRawPermalink
1import { IndexTag } from "..";
2import { tagToString } from "./utils";
3
4test("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
14test("tagToString truncates beginning of directory when path is too long and adds hash for uniqueness", () => {
15 const longPrefix = "/very/long/path/that/will/be/truncated/";
16 const importantSuffix = "/user/important-project/src/feature";
17 const longPath = longPrefix + "x".repeat(200) + importantSuffix;
18
19 const tag: IndexTag = {
20 directory: longPath,
21 branch: "feature-branch",
22 artifactId: "67890",
23 };
24
25 const result = tagToString(tag);
26
27 expect(result).toContain("::feature-branch::67890");
28 expect(result.length).toBeLessThanOrEqual(240);
29 expect(result).toMatch(/^[a-f0-9]{8}_/);
30 expect(result).toContain(importantSuffix);
31});
32
33test("tagToString preserves branch and artifactId exactly, even when truncating", () => {
34 const longPath = "/a".repeat(300);
35 const tag: IndexTag = {
36 directory: longPath,
37 branch: "release-v2.0",
38 artifactId: "build-123",
39 };
40
41 const result = tagToString(tag);
42
43 expect(result).toContain("::release-v2.0::build-123");
44 expect(result).toMatch(/^[a-f0-9]{8}_/);
45 expect(result.length).toBeLessThanOrEqual(240);
46});
47
48test("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-f0-9]{8}_/);
76 expect(result2).toMatch(/^[a-f0-9]{8}_/);
77 } else {
78 expect(result1).toBe(fullString1);
79 expect(result2).toBe(fullString2);
80 }
81});
82
83test("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});