Update tests to expect warnings instead of errors for non-5xx cache failures

Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andLink- committed 2025-07-14 12:07:37 +00:00
1 parent 4b4a56d5f7
commit 0632db1508
3 files changed
+29 -18

No files matched your search

+9 -9
View File
@@ -50,7 +50,7 @@ test('save with large cache outputs should fail', async () => {
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logErrorMock = jest.spyOn(core, 'error') const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@@ -63,8 +63,8 @@ test('save with large cache outputs should fail', async () => {
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logErrorMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logErrorMock).toHaveBeenCalledWith( expect(logWarningMock).toHaveBeenCalledWith(
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.' 'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
) )
@@ -85,7 +85,7 @@ test('save with large cache outputs should fail in GHES with error message', asy
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logErrorMock = jest.spyOn(core, 'error') const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@@ -115,8 +115,8 @@ test('save with large cache outputs should fail in GHES with error message', asy
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logErrorMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logErrorMock).toHaveBeenCalledWith( expect(logWarningMock).toHaveBeenCalledWith(
'Failed to save: The cache filesize must be between 0 and 1073741824 bytes' 'Failed to save: The cache filesize must be between 0 and 1073741824 bytes'
) )
@@ -137,7 +137,7 @@ test('save with large cache outputs should fail in GHES without error message',
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logErrorMock = jest.spyOn(core, 'error') const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@@ -163,8 +163,8 @@ test('save with large cache outputs should fail in GHES without error message',
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logErrorMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logErrorMock).toHaveBeenCalledWith( expect(logWarningMock).toHaveBeenCalledWith(
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.' 'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.'
) )
+4 -4
View File
@@ -65,7 +65,7 @@ test('save with large cache outputs should fail using', async () => {
const cachePaths = [path.resolve(paths)] const cachePaths = [path.resolve(paths)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logErrorMock = jest.spyOn(core, 'error') const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@@ -78,7 +78,7 @@ test('save with large cache outputs should fail using', async () => {
const cacheId = await saveCache([paths], key) const cacheId = await saveCache([paths], key)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logErrorMock).toHaveBeenCalledWith( expect(logWarningMock).toHaveBeenCalledWith(
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.' 'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
) )
@@ -227,7 +227,7 @@ test('finalize save cache failure', async () => {
const paths = 'node_modules' const paths = 'node_modules'
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
const cachePaths = [path.resolve(paths)] const cachePaths = [path.resolve(paths)]
const logErrorMock = jest.spyOn(core, 'error') const logWarningMock = jest.spyOn(core, 'warning')
const signedUploadURL = 'https://blob-storage.local?signed=true' const signedUploadURL = 'https://blob-storage.local?signed=true'
const archiveFileSize = 1024 const archiveFileSize = 1024
const options: UploadOptions = { const options: UploadOptions = {
@@ -292,7 +292,7 @@ test('finalize save cache failure', async () => {
}) })
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logErrorMock).toHaveBeenCalledWith( expect(logWarningMock).toHaveBeenCalledWith(
`Failed to save: Unable to finalize cache with key ${key}, another job may be finalizing this cache.` `Failed to save: Unable to finalize cache with key ${key}, another job may be finalizing this cache.`
) )
}) })
+16 -5
View File
@@ -13,6 +13,8 @@ import {
GetCacheEntryDownloadURLRequest GetCacheEntryDownloadURLRequest
} from './generated/results/api/v1/cache' } from './generated/results/api/v1/cache'
import {CacheFileSizeLimit} from './internal/constants' import {CacheFileSizeLimit} from './internal/constants'
import {isServerErrorStatusCode} from './internal/requestUtils'
import {HttpClientError} from '@actions/http-client'
export class ValidationError extends Error { export class ValidationError extends Error {
constructor(message: string) { constructor(message: string) {
super(message) super(message)
@@ -29,6 +31,15 @@ export class ReserveCacheError extends Error {
} }
} }
function logCacheError(message: string, error: Error): void {
// Log server errors (5xx) as errors, all other errors as warnings
if (error instanceof HttpClientError && isServerErrorStatusCode(error.statusCode)) {
core.error(message)
} else {
core.warning(message)
}
}
function checkPaths(paths: string[]): void { function checkPaths(paths: string[]): void {
if (!paths || paths.length === 0) { if (!paths || paths.length === 0) {
throw new ValidationError( throw new ValidationError(
@@ -199,8 +210,8 @@ async function restoreCacheV1(
if (typedError.name === ValidationError.name) { if (typedError.name === ValidationError.name) {
throw error throw error
} else { } else {
// Log cache related errors // warn on cache restore failure and continue build
core.error(`Failed to restore: ${(error as Error).message}`) core.warning(`Failed to restore: ${(error as Error).message}`)
} }
} finally { } finally {
// Try to delete the archive to save space // Try to delete the archive to save space
@@ -318,7 +329,7 @@ async function restoreCacheV2(
throw error throw error
} else { } else {
// Log cache related errors // Log cache related errors
core.error(`Failed to restore: ${(error as Error).message}`) logCacheError(`Failed to restore: ${(error as Error).message}`, typedError)
} }
} finally { } finally {
try { try {
@@ -450,7 +461,7 @@ async function saveCacheV1(
} else if (typedError.name === ReserveCacheError.name) { } else if (typedError.name === ReserveCacheError.name) {
core.info(`Failed to save: ${typedError.message}`) core.info(`Failed to save: ${typedError.message}`)
} else { } else {
core.error(`Failed to save: ${typedError.message}`) core.warning(`Failed to save: ${typedError.message}`)
} }
} finally { } finally {
// Try to delete the archive to save space // Try to delete the archive to save space
@@ -589,7 +600,7 @@ async function saveCacheV2(
} else if (typedError.name === ReserveCacheError.name) { } else if (typedError.name === ReserveCacheError.name) {
core.info(`Failed to save: ${typedError.message}`) core.info(`Failed to save: ${typedError.message}`)
} else { } else {
core.error(`Failed to save: ${typedError.message}`) logCacheError(`Failed to save: ${typedError.message}`, typedError)
} }
} finally { } finally {
// Try to delete the archive to save space // Try to delete the archive to save space