@@ -25,20 +25,29 @@ assert.strictEqual(
2525) ;
2626
2727assert . strictEqual (
28- computeVersion ( "main" , "cli/v" ) ,
29- "0.0.0-main" ,
30- "CLI main branch should create pseudo version"
28+ computeVersion ( "main" , "cli/v" , {
29+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
30+ gitSha : "abcdef1234567890" ,
31+ } ) ,
32+ "0.0.0-main.20260303123456.abcdef123456" ,
33+ "CLI main branch should create unique pseudo version"
3134) ;
3235
3336assert . strictEqual (
34- computeVersion ( "releases/v0.1" , "cli/v" ) ,
35- "0.0.0-releases-v0.1" ,
37+ computeVersion ( "releases/v0.1" , "cli/v" , {
38+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
39+ gitSha : "abcdef1234567890" ,
40+ } ) ,
41+ "0.0.0-releases-v0.1.20260303123456.abcdef123456" ,
3642 "CLI release branch should create pseudo version"
3743) ;
3844
3945assert . strictEqual (
40- computeVersion ( "feature/my-branch" , "cli/v" ) ,
41- "0.0.0-feature-my-branch" ,
46+ computeVersion ( "feature/my-branch" , "cli/v" , {
47+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
48+ gitSha : "abcdef1234567890" ,
49+ } ) ,
50+ "0.0.0-feature-my-branch.20260303123456.abcdef123456" ,
4251 "CLI feature branch should sanitize slashes"
4352) ;
4453
@@ -60,14 +69,20 @@ assert.strictEqual(
6069) ;
6170
6271assert . strictEqual (
63- computeVersion ( "main" , "bindings/go/helm/v" ) ,
64- "0.0.0-main" ,
72+ computeVersion ( "main" , "bindings/go/helm/v" , {
73+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
74+ gitSha : "abcdef1234567890" ,
75+ } ) ,
76+ "0.0.0-main.20260303123456.abcdef123456" ,
6577 "Helm plugin main branch should create pseudo version"
6678) ;
6779
6880assert . strictEqual (
69- computeVersion ( "feat/new-feature" , "bindings/go/helm/v" ) ,
70- "0.0.0-feat-new-feature" ,
81+ computeVersion ( "feat/new-feature" , "bindings/go/helm/v" , {
82+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
83+ gitSha : "abcdef1234567890" ,
84+ } ) ,
85+ "0.0.0-feat-new-feature.20260303123456.abcdef123456" ,
7186 "Helm plugin feature branch should sanitize slashes"
7287) ;
7388
@@ -95,27 +110,39 @@ assert.strictEqual(
95110) ;
96111
97112assert . strictEqual (
98- computeVersion ( "pr/123/merge" , "cli/v" ) ,
99- "0.0.0-pr-123-merge" ,
113+ computeVersion ( "pr/123/merge" , "cli/v" , {
114+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
115+ gitSha : "abcdef1234567890" ,
116+ } ) ,
117+ "0.0.0-pr-123-merge.20260303123456.abcdef123456" ,
100118 "PR refs should be sanitized"
101119) ;
102120
103121assert . strictEqual (
104- computeVersion ( "refs/heads/main" , "cli/v" ) ,
105- "0.0.0-refs-heads-main" ,
122+ computeVersion ( "refs/heads/main" , "cli/v" , {
123+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
124+ gitSha : "abcdef1234567890" ,
125+ } ) ,
126+ "0.0.0-refs-heads-main.20260303123456.abcdef123456" ,
106127 "Full ref paths should be sanitized"
107128) ;
108129
109130// Special characters in branch names
110131assert . strictEqual (
111- computeVersion ( "feature/issue#123" , "cli/v" ) ,
112- "0.0.0-feature-issue-123" ,
132+ computeVersion ( "feature/issue#123" , "cli/v" , {
133+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
134+ gitSha : "abcdef1234567890" ,
135+ } ) ,
136+ "0.0.0-feature-issue-123.20260303123456.abcdef123456" ,
113137 "Branch with # should be preserved"
114138) ;
115139
116140assert . strictEqual (
117- computeVersion ( "hotfix/v1.2.3-fix" , "cli/v" ) ,
118- "0.0.0-hotfix-v1.2.3-fix" ,
141+ computeVersion ( "hotfix/v1.2.3-fix" , "cli/v" , {
142+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
143+ gitSha : "abcdef1234567890" ,
144+ } ) ,
145+ "0.0.0-hotfix-v1.2.3-fix.20260303123456.abcdef123456" ,
119146 "Branch that looks like version should not be treated as tag"
120147) ;
121148
@@ -170,14 +197,20 @@ console.log("Testing regex escaping for security...");
170197
171198// These should NOT match as tags even though they contain regex special chars
172199assert . strictEqual (
173- computeVersion ( "cli.*v1.2.3" , "cli/v" ) ,
174- "0.0.0-cli.*v1.2.3" ,
200+ computeVersion ( "cli.*v1.2.3" , "cli/v" , {
201+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
202+ gitSha : "abcdef1234567890" ,
203+ } ) ,
204+ "0.0.0-cli.-v1.2.3.20260303123456.abcdef123456" ,
175205 "Ref with regex chars should not match tag pattern"
176206) ;
177207
178208assert . strictEqual (
179- computeVersion ( "v1.2.3" , "cli/v" ) ,
180- "0.0.0-v1.2.3" ,
209+ computeVersion ( "v1.2.3" , "cli/v" , {
210+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
211+ gitSha : "abcdef1234567890" ,
212+ } ) ,
213+ "0.0.0-v1.2.3.20260303123456.abcdef123456" ,
181214 "Ref without correct prefix should not match"
182215) ;
183216
@@ -193,6 +226,17 @@ const result1a = computeVersion(ref1, prefix1);
193226const result1b = computeVersion ( ref1 , prefix1 ) ;
194227assert . strictEqual ( result1a , result1b , "Same inputs should produce same output" ) ;
195228
229+ // Same non-tag input should produce same output when deterministic options are provided
230+ const branchResultA = computeVersion ( "main" , "cli/v" , {
231+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
232+ gitSha : "abcdef1234567890" ,
233+ } ) ;
234+ const branchResultB = computeVersion ( "main" , "cli/v" , {
235+ now : new Date ( "2026-03-03T12:34:56Z" ) ,
236+ gitSha : "abcdef1234567890" ,
237+ } ) ;
238+ assert . strictEqual ( branchResultA , branchResultB , "Deterministic inputs should produce same output" ) ;
239+
196240// Different prefixes should not interfere
197241assert . notStrictEqual (
198242 computeVersion ( "cli/v1.2.3" , "cli/v" ) ,
0 commit comments