diff --git a/lib/config/validation.spec.ts b/lib/config/validation.spec.ts index 7e564265a2bc20..7a480fbc0d73a3 100644 --- a/lib/config/validation.spec.ts +++ b/lib/config/validation.spec.ts @@ -1,3 +1,4 @@ +import * as httpMock from '../../test/http-mock'; import type { RenovateConfig } from './types'; import * as configValidation from './validation'; @@ -629,7 +630,24 @@ describe('config/validation', () => { it('validates preset values', async () => { const config = { - extends: ['foo', 'bar', 42] as never, + extends: ['config:base', ':pinVersions', 42] as never, + }; + const { warnings, errors } = await configValidation.validateConfig( + config, + true + ); + expect(warnings).toHaveLength(0); + expect(errors).toHaveLength(1); + }); + + it('validates if presets exist', async () => { + httpMock + .scope('https://registry.npmjs.org') + .get('/renovate-config-doesntExist') + .reply(500); + + const config = { + extends: ['config:base', 'doesntExist'] as never, }; const { warnings, errors } = await configValidation.validateConfig( config, diff --git a/lib/config/validation.ts b/lib/config/validation.ts index a9ba6d08d85c34..e33ac92bae0295 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -1,4 +1,5 @@ import is from '@sindresorhus/is'; +import { logger } from '../logger'; import { getLanguageList, getManagerList } from '../modules/manager'; import { configRegexPredicate, isConfigRegex, regEx } from '../util/regex'; import * as template from '../util/template'; @@ -8,7 +9,7 @@ import { } from '../workers/repository/update/branch/schedule'; import { migrateConfig } from './migration'; import { getOptions } from './options'; -import { resolveConfigPresets } from './presets'; +import { getPreset, resolveConfigPresets } from './presets'; import type { RenovateConfig, RenovateOptions, @@ -271,6 +272,18 @@ export async function validateConfig( if (key === 'extends') { for (const subval of val) { if (is.string(subval)) { + try { + await getPreset(subval, config); + } catch (err) { + logger.debug( + { err, preset: subval }, + `Could not resolve preset during config validation` + ); + errors.push({ + topic: 'Configuration Warning', + message: `Invalid Preset ${subval}`, + }); + } if ( parentName === 'packageRules' && subval.startsWith('group:')