Files
toolkit/packages/cache/__tests__/config.test.ts
T
Philip GaiandCopilot App 3b3db3879e feat: backport cache read-denied + ACTIONS_CACHE_MODE handling (5.2.0)
Backport of the read-denied and ACTIONS_CACHE_MODE cache-mode gating from
the ESM v6.2.0 line (#2447) to the CommonJS v5 line, released as 5.2.0.
Mirrors the earlier write-denied backport (#2435, 5.1.0).

- Detect the `cache read denied:` prefix on download failures (v2 twirp
  path and v1 `_apis/artifactcache` path) and surface it as a core.warning
  without failing the run.
- Honor ACTIONS_CACHE_MODE: skip restore when the effective cache-mode does
  not permit reads (none, write-only) and skip save when it does not permit
  writes (none, read), logging a single non-fatal core.info line. Unset or
  unrecognized modes are unchanged.
- Add read-denied and cache-mode tests; bump to 5.2.0 with RELEASES entry.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: e96deec1-716e-4e14-acdf-a230139420a2
2026-07-13 15:19:29 -05:00

60 lines
1.7 KiB
TypeScript

import * as config from '../src/internal/config'
beforeEach(() => {
jest.resetModules()
})
test('isGhes returns false for github.com', async () => {
process.env.GITHUB_SERVER_URL = 'https://github.com'
expect(config.isGhes()).toBe(false)
})
test('isGhes returns false for ghe.com', async () => {
process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com'
expect(config.isGhes()).toBe(false)
})
test('isGhes returns true for enterprise URL', async () => {
process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com'
expect(config.isGhes()).toBe(true)
})
test('isGhes returns false for ghe.localhost', () => {
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost'
expect(config.isGhes()).toBe(false)
})
describe('cache-mode helpers', () => {
const original = process.env.ACTIONS_CACHE_MODE
afterEach(() => {
if (original === undefined) {
delete process.env.ACTIONS_CACHE_MODE
} else {
process.env.ACTIONS_CACHE_MODE = original
}
})
test('getCacheMode normalizes whitespace and case', () => {
process.env.ACTIONS_CACHE_MODE = ' Write-Only '
expect(config.getCacheMode()).toBe('write-only')
})
test('getCacheMode returns empty string when unset', () => {
delete process.env.ACTIONS_CACHE_MODE
expect(config.getCacheMode()).toBe('')
})
test.each([
['', true, true],
['read', true, false],
['write', true, true],
['write-only', false, true],
['none', false, false],
['garbage', true, true]
])("mode '%s' -> readable=%s writable=%s", (mode, readable, writable) => {
expect(config.isCacheReadable(mode)).toBe(readable)
expect(config.isCacheWritable(mode)).toBe(writable)
})
})