@@ -12,7 +12,8 @@ import {
1212import { getAgentvConfigDir } from '../../paths.js' ;
1313import { createEvalConfigEnv , interpolateEnv } from '../interpolation.js' ;
1414import {
15- normalizeProviderDefinition ,
15+ expandProviderDefinitionEntries ,
16+ isProviderSpecString ,
1617 resolveProviderDefinitionEnvironments ,
1718} from '../providers/targets.js' ;
1819import type { ProviderDefinition } from '../providers/types.js' ;
@@ -326,14 +327,44 @@ function parseProviderDefinitions(
326327 if ( ! Array . isArray ( rawProviders ) ) {
327328 return Promise . resolve ( undefined ) ;
328329 }
329- const definitions = rawProviders . map ( ( entry , index ) =>
330- normalizeProviderDefinition ( entry , { location : `${ configPath } :providers[${ index } ]` } ) ,
331- ) ;
330+ const definitions = expandProviderDefinitionEntries ( rawProviders , {
331+ location : `${ configPath } :providers` ,
332+ stringMode : 'all' ,
333+ } ) . map ( ( entry ) => entry . definition ) ;
332334 return resolveProviderDefinitionEnvironments ( definitions , baseDir , {
333335 location : `${ configPath } :providers` ,
334336 } ) ;
335337}
336338
339+ function parseInlineProviderRefs ( rawProviders : readonly unknown [ ] ) : readonly EvalTargetRef [ ] {
340+ const refs : EvalTargetRef [ ] = [ ] ;
341+ rawProviders . forEach ( ( entry , index ) => {
342+ const location = `providers[${ index } ]` ;
343+ if ( typeof entry === 'string' && ! isProviderSpecString ( entry ) ) {
344+ const name = entry . trim ( ) ;
345+ if ( name . length === 0 ) {
346+ throw new Error ( `Invalid ${ location } : provider reference must be non-empty.` ) ;
347+ }
348+ refs . push ( { name } ) ;
349+ return ;
350+ }
351+
352+ refs . push ( ...parseEvalProviderRefs ( entry , location ) ) ;
353+ } ) ;
354+ return refs ;
355+ }
356+
357+ function parseEvalProviderRefs ( raw : unknown , location : string ) : readonly EvalTargetRef [ ] {
358+ const entries = expandProviderDefinitionEntries ( [ raw ] , {
359+ location : location . replace ( / \[ \d + \] $ / , '' ) ,
360+ stringMode : 'spec-only' ,
361+ } ) ;
362+
363+ return entries . map ( ( entry ) =>
364+ providerDefinitionToRef ( entry . rawDefinition , entry . rawId , entry . definition ) ,
365+ ) ;
366+ }
367+
337368function mergeExecutionConfig (
338369 defaults : ExecutionDefaults | undefined ,
339370 graph : ComposableConfigGraph [ 'execution' ] ,
@@ -541,7 +572,7 @@ export function extractTargetRefsFromSuite(
541572 }
542573
543574 const entries = Array . isArray ( rawProviders ) ? rawProviders : [ rawProviders ] ;
544- const refs = entries . map ( ( entry , index ) => parseEvalProviderRef ( entry , `providers[ ${ index } ]` ) ) ;
575+ const refs = parseInlineProviderRefs ( entries ) ;
545576 assertUniqueProviderRefs ( refs ) ;
546577 return refs . length > 0 ? refs : undefined ;
547578}
@@ -556,28 +587,15 @@ export function extractTargetsFromSuite(suite: JsonObject): readonly string[] |
556587 return names . length > 0 ? names : undefined ;
557588}
558589
559- function parseEvalProviderRef ( raw : unknown , location : string ) : EvalTargetRef {
560- if ( typeof raw === 'string' ) {
561- const name = raw . trim ( ) ;
562- if ( name . length === 0 ) {
563- throw new Error ( `Invalid ${ location } : provider reference must be non-empty.` ) ;
564- }
565- return { name } ;
566- }
567-
568- if ( ! isJsonObject ( raw ) ) {
569- throw new Error ( `Invalid ${ location } : use a provider reference string or provider object.` ) ;
570- }
571-
590+ function providerDefinitionToRef (
591+ raw : Record < string , unknown > ,
592+ rawId : string ,
593+ definition : ProviderDefinition ,
594+ ) : EvalTargetRef {
572595 const hooks = parseTargetHooks ( raw . hooks ) ;
573- const definition = normalizeProviderDefinition (
574- Object . fromEntries ( Object . entries ( raw ) . filter ( ( [ key ] ) => key !== 'hooks' ) ) ,
575- { location } ,
576- ) as ProviderDefinition ;
577-
578596 return {
579597 name : definition . name ,
580- id : typeof raw . id === 'string' ? raw . id . trim ( ) : definition . provider ,
598+ id : rawId ,
581599 ...( definition . label !== undefined ? { label : definition . label } : { } ) ,
582600 definition,
583601 ...( hooks !== undefined ? { hooks } : { } ) ,
0 commit comments