@@ -46,8 +46,11 @@ export class PluginTester {
4646 }
4747
4848 const plugin = new PluginProcess ( pluginPath ) ;
49+
4950 try {
5051 await this . initializeAndValidate ( plugin , configs ) ;
52+
53+ await this . validateExampleAndDefaultConfigs ( plugin , configs ) ;
5154
5255 console . info ( chalk . cyan ( 'Testing plan...' ) )
5356 const plans = await this . planConfigs ( plugin , configs ) ;
@@ -215,7 +218,79 @@ export class PluginTester {
215218
216219 const invalidConfigs = validate . resourceValidations . filter ( ( v ) => ! v . isValid )
217220 if ( invalidConfigs . length > 0 ) {
218- throw new Error ( `The following configs did not validate:\n ${ JSON . stringify ( invalidConfigs , null , 2 ) } ` )
221+ const invalidWithConfigs = invalidConfigs . map ( ( v ) => ( {
222+ config : configs . find ( ( c ) => c . type === v . resourceType && ( ! v . resourceName || c . name === v . resourceName ) ) ,
223+ validation : v ,
224+ } ) ) ;
225+ throw new Error ( `The following configs did not validate:\n ${ JSON . stringify ( invalidWithConfigs , null , 2 ) } ` )
226+ }
227+ }
228+
229+ private static async validateExampleAndDefaultConfigs (
230+ plugin : PluginProcess ,
231+ configs : ResourceConfig [ ] ,
232+ ) : Promise < void > {
233+ console . info ( chalk . cyan ( 'Validating examples and default config...' ) )
234+ const uniqueTypes = [ ...new Set ( configs . map ( ( c ) => c . type ) ) ] ;
235+
236+ const errors : string [ ] = [ ] ;
237+
238+ for ( const type of uniqueTypes ) {
239+ const { defaultConfig, exampleConfigs } = await plugin . getResourceInfo ( { type } ) ;
240+
241+ // Validate exampleConfigs — these should be fully valid configs
242+ const exampleEntries : Array < [ string , Array < Record < string , unknown > > ] > = [ ] ;
243+ if ( exampleConfigs ?. example1 ?. configs ) exampleEntries . push ( [ 'exampleConfigs.example1' , exampleConfigs . example1 . configs as Array < Record < string , unknown > > ] ) ;
244+ if ( exampleConfigs ?. example2 ?. configs ) exampleEntries . push ( [ 'exampleConfigs.example2' , exampleConfigs . example2 . configs as Array < Record < string , unknown > > ] ) ;
245+
246+ for ( const [ label , exampleConfigList ] of exampleEntries ) {
247+ for ( const [ idx , exampleConfig ] of exampleConfigList . entries ( ) ) {
248+ const configLabel = `resource '${ type } ' ${ label } [${ idx } ]` ;
249+ await this . validateSingleExampleConfig ( plugin , configLabel , exampleConfig , errors ) ;
250+ }
251+ }
252+
253+ // Validate defaultConfig — partial config, so only warn on failure
254+ if ( defaultConfig ) {
255+ try {
256+ const validate = await plugin . validate ( {
257+ configs : [ { core : { type } , parameters : defaultConfig } ]
258+ } ) ;
259+ const invalid = validate . resourceValidations . filter ( ( v ) => ! v . isValid ) ;
260+ if ( invalid . length > 0 ) {
261+ console . warn ( chalk . yellow ( `Resource '${ type } ' defaultConfig failed validation (this may be expected for partial configs):\n${ JSON . stringify ( invalid , null , 2 ) } ` ) ) ;
262+ }
263+ } catch ( error ) {
264+ console . warn ( chalk . yellow ( `Resource '${ type } ' defaultConfig could not be validated: ${ error } ` ) ) ;
265+ }
266+ }
267+ }
268+
269+ if ( errors . length > 0 ) {
270+ const message = errors . length === 1
271+ ? errors [ 0 ]
272+ : `Multiple example config validation failures:\n\n${ errors . map ( ( e , i ) => `[${ i + 1 } ] ${ e } ` ) . join ( '\n\n' ) } ` ;
273+ throw new Error ( message ) ;
274+ }
275+ }
276+
277+ private static async validateSingleExampleConfig (
278+ plugin : PluginProcess ,
279+ label : string ,
280+ exampleConfig : Record < string , unknown > ,
281+ errors : string [ ] ,
282+ ) : Promise < void > {
283+ try {
284+ const { coreParameters, parameters } = splitUserConfig ( exampleConfig as ResourceConfig ) ;
285+ const validate = await plugin . validate ( {
286+ configs : [ { core : coreParameters , parameters } ]
287+ } ) ;
288+ const invalid = validate . resourceValidations . filter ( ( v ) => ! v . isValid ) ;
289+ if ( invalid . length > 0 ) {
290+ errors . push ( `${ label } failed validation:\nConfig: ${ JSON . stringify ( exampleConfig , null , 2 ) } \nErrors: ${ JSON . stringify ( invalid , null , 2 ) } ` ) ;
291+ }
292+ } catch ( error ) {
293+ errors . push ( `${ label } could not be validated:\nConfig: ${ JSON . stringify ( exampleConfig , null , 2 ) } \nError: ${ error } ` ) ;
219294 }
220295 }
221296
0 commit comments