11import { env , SELF } from "cloudflare:test" ;
22import assert from "node:assert" ;
3- import { describe , test , expect , beforeEach , beforeAll } from "vitest" ;
3+ import { describe , test , expect , beforeAll } from "vitest" ;
44import {
55 D2JsonData ,
66 ReleaseArtifact ,
@@ -15,44 +15,14 @@ import {
1515} from "../src/select-zls-version" ;
1616import { SemanticVersion } from "../src/semantic-version" ;
1717
18- const defaultArtifacts : ReleaseArtifact [ ] = [
19- {
20- arch : "x86_64" ,
21- os : "linux" ,
22- version : "0.11.0" ,
23- extension : "tar.xz" ,
24- fileShasum :
25- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ,
26- fileSize : 12 ,
27- } ,
28- {
29- arch : "x86_64" ,
30- os : "linux" ,
31- version : "0.11.0" ,
32- extension : "tar.gz" ,
33- fileShasum :
34- "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ,
35- fileSize : 12 ,
36- } ,
37- {
38- arch : "aarch64" ,
39- os : "windows" ,
40- version : "0.11.0" ,
41- extension : "zip" ,
42- fileShasum :
43- "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" ,
44- fileSize : 12 ,
45- } ,
46- ] ;
47-
4818const samples : D2JsonData [ ] = [
4919 {
5020 date : 0 ,
5121 zlsVersion : "0.9.0-dev.3+aaaaaaaaa" ,
5222 zigVersion : "0.9.0-dev.20+aaaaaaaaa" ,
5323 minimumBuildZigVersion : "0.9.0-dev.25+aaaaaaaaa" ,
5424 minimumRuntimeZigVersion : "0.9.0-dev.15+aaaaaaaaa" ,
55- artifacts : defaultArtifacts ,
25+ artifacts : createExampleArtifacts ( "0.9.0-dev.3+aaaaaaaaa" ) ,
5626 testedZigVersions : {
5727 "0.9.0-dev.20+aaaaaaaaa" : VersionCompatibility . Full ,
5828 "0.9.0-dev.25+aaaaaaaaa" : VersionCompatibility . Full ,
@@ -65,7 +35,7 @@ const samples: D2JsonData[] = [
6535 zigVersion : "0.11.0" ,
6636 minimumBuildZigVersion : "0.11.0" ,
6737 minimumRuntimeZigVersion : "0.11.0" ,
68- artifacts : defaultArtifacts ,
38+ artifacts : createExampleArtifacts ( "0.11.0" ) ,
6939 testedZigVersions : { "0.11.0" : VersionCompatibility . Full } ,
7040 } ,
7141 {
@@ -74,7 +44,7 @@ const samples: D2JsonData[] = [
7444 zigVersion : "0.11.0" ,
7545 minimumBuildZigVersion : "0.11.0" ,
7646 minimumRuntimeZigVersion : "0.11.0" ,
77- artifacts : defaultArtifacts ,
47+ artifacts : createExampleArtifacts ( "0.12.0-dev.1+aaaaaaaaa" ) ,
7848 testedZigVersions : {
7949 "0.11.0" : VersionCompatibility . Full ,
8050 "0.12.0-dev.2+aaaaaaaaa" : VersionCompatibility . Full ,
@@ -89,7 +59,7 @@ const samples: D2JsonData[] = [
8959 zigVersion : "0.12.0-dev.7+aaaaaaaaa" ,
9060 minimumBuildZigVersion : "0.11.0" ,
9161 minimumRuntimeZigVersion : "0.12.0-dev.7+aaaaaaaaa" ,
92- artifacts : defaultArtifacts ,
62+ artifacts : createExampleArtifacts ( "0.12.0-dev.2+aaaaaaaaa" ) ,
9363 testedZigVersions : {
9464 "0.12.0-dev.7+aaaaaaaaa" : VersionCompatibility . Full ,
9565 "0.12.0-dev.8+aaaaaaaaa" : VersionCompatibility . Full ,
@@ -103,7 +73,7 @@ const samples: D2JsonData[] = [
10373 zigVersion : "0.12.0-dev.17+aaaaaaaaa" ,
10474 minimumBuildZigVersion : "0.11.0" ,
10575 minimumRuntimeZigVersion : "0.12.0-dev.14+aaaaaaaaa" ,
106- artifacts : defaultArtifacts ,
76+ artifacts : createExampleArtifacts ( "0.12.0-dev.3+aaaaaaaaa" ) ,
10777 testedZigVersions : {
10878 "0.12.0-dev.17+aaaaaaaaa" : VersionCompatibility . Full ,
10979 } ,
@@ -114,7 +84,7 @@ const samples: D2JsonData[] = [
11484 zigVersion : "0.12.0" ,
11585 minimumBuildZigVersion : "0.12.0" ,
11686 minimumRuntimeZigVersion : "0.12.0" ,
117- artifacts : defaultArtifacts ,
87+ artifacts : createExampleArtifacts ( "0.12.0" ) ,
11888 testedZigVersions : {
11989 "0.12.0" : VersionCompatibility . Full ,
12090 "0.12.1" : VersionCompatibility . Full ,
@@ -127,7 +97,7 @@ const samples: D2JsonData[] = [
12797 zigVersion : "0.12.0" ,
12898 minimumBuildZigVersion : "0.12.0" ,
12999 minimumRuntimeZigVersion : "0.12.0" ,
130- artifacts : defaultArtifacts ,
100+ artifacts : createExampleArtifacts ( "0.12.1" ) ,
131101 testedZigVersions : { "0.12.0" : VersionCompatibility . Full } ,
132102 } ,
133103 {
@@ -136,7 +106,7 @@ const samples: D2JsonData[] = [
136106 zigVersion : "0.13.0" ,
137107 minimumBuildZigVersion : "0.13.0" ,
138108 minimumRuntimeZigVersion : "0.13.0" ,
139- artifacts : defaultArtifacts ,
109+ artifacts : createExampleArtifacts ( "0.13.0" ) ,
140110 testedZigVersions : {
141111 "0.13.0" : VersionCompatibility . Full ,
142112 "0.14.0-dev.2+aaaaaaaaa" : VersionCompatibility . Full ,
@@ -145,9 +115,41 @@ const samples: D2JsonData[] = [
145115 } ,
146116] ;
147117
148- async function populateDatabase ( ) : Promise < void > {
149- shuffleArray ( samples ) ;
150- const statements = samples . map ( ( sample ) => {
118+ function createExampleArtifacts ( version : string ) : ReleaseArtifact [ ] {
119+ return [
120+ {
121+ arch : "x86_64" ,
122+ os : "linux" ,
123+ version : version ,
124+ extension : "tar.xz" ,
125+ fileShasum :
126+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ,
127+ fileSize : 12 ,
128+ } ,
129+ {
130+ arch : "x86_64" ,
131+ os : "linux" ,
132+ version : version ,
133+ extension : "tar.gz" ,
134+ fileShasum :
135+ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ,
136+ fileSize : 12 ,
137+ } ,
138+ {
139+ arch : "aarch64" ,
140+ os : "windows" ,
141+ version : version ,
142+ extension : "zip" ,
143+ fileShasum :
144+ "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" ,
145+ fileSize : 12 ,
146+ } ,
147+ ] ;
148+ }
149+
150+ async function populateDatabase ( entries : D2JsonData [ ] ) : Promise < void > {
151+ shuffleArray ( entries ) ;
152+ const statements = entries . map ( ( sample ) => {
151153 const zlsVersion = SemanticVersion . parse ( sample . zlsVersion ) ;
152154 assert ( zlsVersion !== null ) ;
153155
@@ -294,7 +296,9 @@ describe("/v1/zls/select-version", () => {
294296 } ) ;
295297
296298 describe ( "test on sample database" , ( ) => {
297- beforeAll ( populateDatabase ) ;
299+ beforeAll ( async ( ) => {
300+ await populateDatabase ( samples ) ;
301+ } ) ;
298302
299303 test ( "search for with Version 0.11.0" , async ( ) => {
300304 const response = await selectZLSVersion (
@@ -446,6 +450,41 @@ describe("/v1/zls/select-version", () => {
446450 ) ;
447451 } ) ;
448452
453+ test ( "target string has changed with begining with 0.15.0" , async ( ) => {
454+ await populateDatabase ( [
455+ {
456+ date : 0 ,
457+ zlsVersion : "0.15.0" ,
458+ zigVersion : "0.15.0" ,
459+ minimumBuildZigVersion : "0.15.0" ,
460+ minimumRuntimeZigVersion : "0.15.0" ,
461+ artifacts : createExampleArtifacts ( "0.15.0" ) ,
462+ testedZigVersions : {
463+ "0.15.0" : VersionCompatibility . Full ,
464+ } ,
465+ } ,
466+ ] ) ;
467+
468+ const response = await selectZLSVersion (
469+ "0.15.0" ,
470+ VersionCompatibility . Full ,
471+ ) ;
472+
473+ expect ( response ) . not . toHaveProperty ( "message" ) ;
474+ assert ( ! ( "message" in response ) ) ;
475+
476+ expect ( response ) . toHaveProperty ( "x86_64-linux" ) ;
477+ expect ( response ) . not . toHaveProperty ( "linux-x86_64" ) ;
478+
479+ const artifactEntry = response [ "x86_64-linux" ] ;
480+ expect ( artifactEntry ) . toHaveProperty ( "tarball" ) ;
481+ assert ( typeof artifactEntry == "object" ) ;
482+
483+ expect ( artifactEntry . tarball ) . toBe (
484+ `${ env . R2_PUBLIC_URL } /zls-x86_64-linux-0.15.0.tar.xz` ,
485+ ) ;
486+ } ) ;
487+
449488 test ( "explain query plan when searching all tagged releases" , async ( ) => {
450489 const response = await env . ZIGTOOLS_DB . prepare (
451490 "EXPLAIN QUERY PLAN SELECT ZLSVersion, JsonData FROM ZLSReleases WHERE IsRelease = 1 ORDER BY ZLSVersionMajor DESC, ZLSVersionMinor DESC, ZLSVersionPatch DESC" ,
0 commit comments