@@ -63,13 +63,23 @@ describe("BunProc.install provider tracking", () => {
6363 . catch ( ( ) => false )
6464 }
6565
66+ // Official semver regex from semver.org (ECMA Script compatible)
67+ const SEMVER_REGEX =
68+ / ^ ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) (?: - ( (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) ) * ) ) ? (?: \+ ( [ 0 - 9 a - z A - Z - ] + (?: \. [ 0 - 9 a - z A - Z - ] + ) * ) ) ? $ /
69+
70+ function isExactVersion ( v : string ) {
71+ return typeof v === "string" && SEMVER_REGEX . test ( v )
72+ }
73+
6674 test ( "should track provider in opencode.providers section" , async ( ) => {
6775 const { BunProc } = await import ( "../src/bun" )
6876
6977 await BunProc . install ( "zod" , "latest" , "anthropic" )
7078
7179 const pkgJson = await readPkgJson ( )
7280 expect ( pkgJson . opencode ?. providers ?. anthropic ) . toBe ( "zod" )
81+ // Verify exact version is installed (not "latest")
82+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
7383 } )
7484
7585 test ( "should install package in node_modules" , async ( ) => {
@@ -78,18 +88,23 @@ describe("BunProc.install provider tracking", () => {
7888 await BunProc . install ( "zod" , "latest" , "anthropic" )
7989
8090 expect ( await pkgExists ( "zod" ) ) . toBe ( true )
91+ // Verify exact version is installed
92+ const pkgJson = await readPkgJson ( )
93+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
8194 } )
8295
8396 test ( "should update tracking when provider switches packages" , async ( ) => {
8497 const { BunProc } = await import ( "../src/bun" )
8598
8699 await BunProc . install ( "zod" , "latest" , "anthropic" )
87- let pkgJson = await readPkgJson ( )
88- expect ( pkgJson . opencode ?. providers ?. anthropic ) . toBe ( "zod" )
100+ const pkgJson1 = await readPkgJson ( )
101+ expect ( pkgJson1 . opencode ?. providers ?. anthropic ) . toBe ( "zod" )
102+ expect ( isExactVersion ( pkgJson1 . dependencies ?. zod ) ) . toBe ( true )
89103
90104 await BunProc . install ( "superstruct" , "latest" , "anthropic" )
91- pkgJson = await readPkgJson ( )
92- expect ( pkgJson . opencode ?. providers ?. anthropic ) . toBe ( "superstruct" )
105+ const pkgJson2 = await readPkgJson ( )
106+ expect ( pkgJson2 . opencode ?. providers ?. anthropic ) . toBe ( "superstruct" )
107+ expect ( isExactVersion ( pkgJson2 . dependencies ?. superstruct ) ) . toBe ( true )
93108 } )
94109
95110 test ( "should remove old package when provider switches" , async ( ) => {
@@ -151,6 +166,8 @@ describe("BunProc.install provider tracking", () => {
151166 const pkgJson = await readPkgJson ( )
152167 // No provider tracking when providerID not provided
153168 expect ( pkgJson . opencode ?. providers ) . toBeUndefined ( )
169+ // Verify exact version is installed
170+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
154171 } )
155172
156173 test ( "should track multiple providers independently" , async ( ) => {
@@ -165,6 +182,9 @@ describe("BunProc.install provider tracking", () => {
165182
166183 expect ( await pkgExists ( "zod" ) ) . toBe ( true )
167184 expect ( await pkgExists ( "superstruct" ) ) . toBe ( true )
185+ // Verify exact versions
186+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
187+ expect ( isExactVersion ( pkgJson . dependencies ?. superstruct ) ) . toBe ( true )
168188 } )
169189
170190 test ( "should not remove package if another provider still uses it" , async ( ) => {
@@ -197,6 +217,7 @@ describe("BunProc.install provider tracking", () => {
197217 const pkgJson = await readPkgJson ( )
198218 expect ( pkgJson . opencode ?. providers ?. anthropic ) . toBe ( "zod" )
199219 expect ( await pkgExists ( "zod" ) ) . toBe ( true )
220+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
200221 } )
201222
202223 test ( "should work when opencode section exists without providers" , async ( ) => {
@@ -210,5 +231,16 @@ describe("BunProc.install provider tracking", () => {
210231 const pkgJson = await readPkgJson ( )
211232 expect ( pkgJson . opencode ?. providers ?. anthropic ) . toBe ( "zod" )
212233 expect ( await pkgExists ( "zod" ) ) . toBe ( true )
234+ expect ( isExactVersion ( pkgJson . dependencies ?. zod ) ) . toBe ( true )
235+ } )
236+
237+ test ( "should install exact version when specific version provided" , async ( ) => {
238+ const { BunProc } = await import ( "../src/bun" )
239+
240+ await BunProc . install ( "zod" , "3.23.0" , "anthropic" )
241+
242+ const pkgJson = await readPkgJson ( )
243+ expect ( pkgJson . dependencies ?. zod ) . toBe ( "3.23.0" )
244+ expect ( await pkgExists ( "zod" ) ) . toBe ( true )
213245 } )
214246} )
0 commit comments