diff --git a/packages/cache/__tests__/cacheHttpClient.test.ts b/packages/cache/__tests__/cacheHttpClient.test.ts index 90dd5cfc..efd859b8 100644 --- a/packages/cache/__tests__/cacheHttpClient.test.ts +++ b/packages/cache/__tests__/cacheHttpClient.test.ts @@ -7,7 +7,7 @@ jest.mock('../src/internal/downloadUtils') test('getCacheVersion with one path returns version', async () => { const paths = ['node_modules'] - const result = getCacheVersion(paths) + const result = getCacheVersion(paths, undefined, true) expect(result).toEqual( 'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985' ) @@ -15,7 +15,7 @@ test('getCacheVersion with one path returns version', async () => { test('getCacheVersion with multiple paths returns version', async () => { const paths = ['node_modules', 'dist'] - const result = getCacheVersion(paths) + const result = getCacheVersion(paths, undefined, true) expect(result).toEqual( '165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436' ) @@ -23,7 +23,7 @@ test('getCacheVersion with multiple paths returns version', async () => { test('getCacheVersion with zstd compression returns version', async () => { const paths = ['node_modules'] - const result = getCacheVersion(paths, CompressionMethod.Zstd) + const result = getCacheVersion(paths, CompressionMethod.Zstd, true) expect(result).toEqual( '273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24' @@ -32,13 +32,24 @@ test('getCacheVersion with zstd compression returns version', async () => { test('getCacheVersion with gzip compression does not change vesion', async () => { const paths = ['node_modules'] - const result = getCacheVersion(paths, CompressionMethod.Gzip) + const result = getCacheVersion(paths, CompressionMethod.Gzip, true) expect(result).toEqual( 'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985' ) }) +test('getCacheVersion with crossOsEnabled as false returns version on windows', async () => { + if (process.platform === 'win32') { + const paths = ['node_modules'] + const result = getCacheVersion(paths) + + expect(result).toEqual( + '2db19d6596dc34f51f0043120148827a264863f5c6ac857569c2af7119bad14e' + ) + } +}) + test('downloadCache uses http-client for non-Azure URLs', async () => { const downloadCacheHttpClientMock = jest.spyOn( downloadUtils, diff --git a/packages/cache/__tests__/restoreCache.test.ts b/packages/cache/__tests__/restoreCache.test.ts index 9cf45799..2b335686 100644 --- a/packages/cache/__tests__/restoreCache.test.ts +++ b/packages/cache/__tests__/restoreCache.test.ts @@ -142,7 +142,8 @@ test('restore with gzip compressed cache found', async () => { expect(cacheKey).toBe(key) expect(getCacheMock).toHaveBeenCalledWith([key], paths, { - compressionMethod: compression + compressionMethod: compression, + crossOsEnabled: false }) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(downloadCacheMock).toHaveBeenCalledWith( @@ -210,7 +211,8 @@ test('restore with zstd as default but gzip compressed cache found on windows', expect(cacheKey).toBe(key) expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, { - compressionMethod: compression + compressionMethod: compression, + crossOsEnabled: false }) expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, { compressionMethod: CompressionMethod.Gzip @@ -276,7 +278,8 @@ test('restore with zstd compressed cache found', async () => { expect(cacheKey).toBe(key) expect(getCacheMock).toHaveBeenCalledWith([key], paths, { - compressionMethod: compression + compressionMethod: compression, + crossOsEnabled: false }) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(downloadCacheMock).toHaveBeenCalledWith( @@ -333,7 +336,8 @@ test('restore with cache found for restore key', async () => { expect(cacheKey).toBe(restoreKey) expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, { - compressionMethod: compression + compressionMethod: compression, + crossOsEnabled: false }) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(downloadCacheMock).toHaveBeenCalledWith( diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 945b254f..3a8725eb 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -209,7 +209,9 @@ test('save with reserve cache failure should fail', async () => { expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { - compressionMethod: compression + cacheSize: undefined, + compressionMethod: compression, + crossOsEnabled: false }) expect(createTarMock).toHaveBeenCalledTimes(1) expect(saveCacheMock).toHaveBeenCalledTimes(0) @@ -253,7 +255,9 @@ test('save with server error should fail', async () => { expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { - compressionMethod: compression + cacheSize: undefined, + compressionMethod: compression, + crossOsEnabled: false }) const archiveFolder = '/foo/bar' const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) @@ -296,7 +300,9 @@ test('save with valid inputs uploads a cache', async () => { expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { - compressionMethod: compression + cacheSize: undefined, + compressionMethod: compression, + crossOsEnabled: false }) const archiveFolder = '/foo/bar' const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 098d6226..2c5bb75b 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -61,16 +61,16 @@ export function isFeatureAvailable(): boolean { * @param paths a list of file paths to restore from the cache * @param primaryKey an explicit key for restoring the cache * @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key - * @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform * @param downloadOptions cache download options + * @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform * @returns string returns the key for the cache hit, otherwise returns undefined */ export async function restoreCache( paths: string[], primaryKey: string, restoreKeys?: string[], - crossOsEnabled = false, - options?: DownloadOptions + options?: DownloadOptions, + crossOsEnabled = false ): Promise { checkPaths(paths) @@ -181,8 +181,8 @@ export async function restoreCache( export async function saveCache( paths: string[], key: string, - crossOsEnabled = false, - options?: UploadOptions + options?: UploadOptions, + crossOsEnabled = false ): Promise { checkPaths(paths) checkKey(key) diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts index 1d242b1c..9557218b 100644 --- a/packages/cache/src/internal/contracts.d.ts +++ b/packages/cache/src/internal/contracts.d.ts @@ -34,9 +34,9 @@ export interface ReserveCacheResponse { } export interface InternalCacheOptions { - cacheSize?: number compressionMethod?: CompressionMethod crossOsEnabled?: boolean + cacheSize?: number } export interface ArchiveTool {