@@ -74,11 +74,8 @@ describe('update plugin', () => {
7474
7575 it ( 'should not update - already on same version' , async ( ) => {
7676 clientRoot = await setupClientRoot ( { config} , '2.0.0' )
77- const platformRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } ` )
78- const manifestRegex = new RegExp ( `channels\\/stable\\/example-cli-${ config . platform } -${ config . arch } -buildmanifest` )
77+ const manifestRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } ` )
7978 nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
80- . get ( platformRegex )
81- . reply ( 200 , { version : '2.0.0' } )
8279 . get ( manifestRegex )
8380 . reply ( 200 , { version : '2.0.0' } )
8481
@@ -90,8 +87,7 @@ describe('update plugin', () => {
9087
9188 it ( 'should update to channel' , async ( ) => {
9289 clientRoot = await setupClientRoot ( { config} )
93- const platformRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } ` )
94- const manifestRegex = new RegExp ( `channels\\/stable\\/example-cli-${ config . platform } -${ config . arch } -buildmanifest` )
90+ const manifestRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } ` )
9591 const tarballRegex = new RegExp (
9692 `tarballs\\/example-cli\\/example-cli-v2.0.1\\/example-cli-v2.0.1-${ config . platform } -${ config . arch } gz` ,
9793 )
@@ -104,8 +100,6 @@ describe('update plugin', () => {
104100 const gzContents = zlib . gzipSync ( ' ' )
105101
106102 nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
107- . get ( platformRegex )
108- . reply ( 200 , { version : '2.0.1' } )
109103 . get ( manifestRegex )
110104 . reply ( 200 , { version : '2.0.1' } )
111105 . get ( tarballRegex )
@@ -267,8 +261,6 @@ describe('update plugin', () => {
267261
268262 it ( 'should update from local file' , async ( ) => {
269263 clientRoot = await setupClientRoot ( { config} )
270- const platformRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } ` )
271- const manifestRegex = new RegExp ( `channels\\/stable\\/example-cli-${ config . platform } -${ config . arch } -buildmanifest` )
272264 const tarballRegex = new RegExp (
273265 `tarballs\\/example-cli\\/example-cli-v2.0.0\\/example-cli-v2.0.1-${ config . platform } -${ config . arch } gz` ,
274266 )
@@ -282,10 +274,6 @@ describe('update plugin', () => {
282274 const gzContents = zlib . gzipSync ( ' ' )
283275
284276 nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
285- . get ( platformRegex )
286- . reply ( 200 , { version : '2.0.1' } )
287- . get ( manifestRegex )
288- . reply ( 200 , { version : '2.0.1' } )
289277 . get ( tarballRegex )
290278 . reply ( 200 , gzContents , {
291279 'Content-Encoding' : 'gzip' ,
@@ -298,4 +286,83 @@ describe('update plugin', () => {
298286 const stdout = stripAnsi ( collector . stdout . join ( ' ' ) )
299287 expect ( stdout ) . to . matches ( / U p d a t i n g t o a s p e c i f i c v e r s i o n w i l l n o t u p d a t e t h e c h a n n e l / )
300288 } )
289+
290+ describe ( 'custom S3 templates' , ( ) => {
291+ it ( 'should use config.s3Key() for manifest URL when custom templates are configured' , async ( ) => {
292+ clientRoot = await setupClientRoot ( { config} , '2.0.0' )
293+ // The example config has custom S3 templates with target.manifest:
294+ // "tarballs/<%- bin %>/<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>"
295+ // For channel=stable, this produces: tarballs/example-cli/{platform}-{arch}
296+ const customManifestRegex = new RegExp ( `tarballs\\/example-cli\\/${ config . platform } -${ config . arch } $` )
297+ // Verify the hardcoded format is NOT used
298+ const hardcodedManifestRegex = new RegExp (
299+ `channels\\/stable\\/example-cli-${ config . platform } -${ config . arch } -buildmanifest` ,
300+ )
301+ const interceptedPaths : string [ ] = [ ]
302+
303+ nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
304+ . get ( customManifestRegex )
305+ . reply ( function ( ) {
306+ interceptedPaths . push ( this . req . path )
307+ return [ 200 , { version : '2.0.0' } ]
308+ } )
309+
310+ updater = initUpdater ( config )
311+ await updater . runUpdate ( { autoUpdate : false } )
312+
313+ expect ( interceptedPaths ) . to . have . lengthOf ( 1 )
314+ expect ( interceptedPaths [ 0 ] ) . to . match ( customManifestRegex )
315+ expect ( interceptedPaths [ 0 ] ) . to . not . match ( hardcodedManifestRegex )
316+ } )
317+
318+ it ( 'should use hardcoded manifest key when no custom templates are configured' , async ( ) => {
319+ // Remove custom templates from the config
320+ const originalTemplates = config . pjson . oclif . update ! . s3 ! . templates
321+ delete ( config . pjson . oclif . update ! . s3 as Record < string , unknown > ) . templates
322+
323+ clientRoot = await setupClientRoot ( { config} , '2.0.0' )
324+ const hardcodedManifestRegex = new RegExp (
325+ `channels\\/stable\\/example-cli-${ config . platform } -${ config . arch } -buildmanifest` ,
326+ )
327+ const interceptedPaths : string [ ] = [ ]
328+
329+ nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
330+ . get ( hardcodedManifestRegex )
331+ . reply ( function ( ) {
332+ interceptedPaths . push ( this . req . path )
333+ return [ 200 , { version : '2.0.0' } ]
334+ } )
335+
336+ updater = initUpdater ( config )
337+ await updater . runUpdate ( { autoUpdate : false } )
338+
339+ expect ( interceptedPaths ) . to . have . lengthOf ( 1 )
340+ expect ( interceptedPaths [ 0 ] ) . to . match ( hardcodedManifestRegex )
341+
342+ // Restore templates
343+ config . pjson . oclif . update ! . s3 ! . templates = originalTemplates
344+ } )
345+
346+ it ( 'should use custom template manifest URL for non-stable channels' , async ( ) => {
347+ clientRoot = await setupClientRoot ( { config} , '2.0.0' )
348+ // For channel=beta, the template produces: tarballs/example-cli/channels/beta/{platform}-{arch}
349+ const betaManifestRegex = new RegExp (
350+ `tarballs\\/example-cli\\/channels\\/beta\\/${ config . platform } -${ config . arch } ` ,
351+ )
352+ const interceptedPaths : string [ ] = [ ]
353+
354+ nock ( / o c l i f - s t a g i n g .s 3 .a m a z o n a w s .c o m / )
355+ . get ( betaManifestRegex )
356+ . reply ( function ( ) {
357+ interceptedPaths . push ( this . req . path )
358+ return [ 200 , { version : '2.0.0' } ]
359+ } )
360+
361+ updater = initUpdater ( config )
362+ await updater . runUpdate ( { autoUpdate : false , channel : 'beta' } )
363+
364+ expect ( interceptedPaths ) . to . have . lengthOf ( 1 )
365+ expect ( interceptedPaths [ 0 ] ) . to . match ( betaManifestRegex )
366+ } )
367+ } )
301368} )
0 commit comments