@@ -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' ] ,
@@ -543,7 +574,7 @@ export function extractTargetRefsFromSuite(
543574 }
544575
545576 const entries = Array . isArray ( rawProviders ) ? rawProviders : [ rawProviders ] ;
546- const refs = entries . map ( ( entry , index ) => parseEvalProviderRef ( entry , `providers[ ${ index } ]` ) ) ;
577+ const refs = parseInlineProviderRefs ( entries ) ;
547578 assertUniqueProviderRefs ( refs ) ;
548579 return refs . length > 0 ? refs : undefined ;
549580}
@@ -558,29 +589,18 @@ export function extractTargetsFromSuite(suite: JsonObject): readonly string[] |
558589 return names . length > 0 ? names : undefined ;
559590}
560591
561- function parseEvalProviderRef ( raw : unknown , location : string ) : EvalTargetRef {
562- if ( typeof raw === 'string' ) {
563- const name = raw . trim ( ) ;
564- if ( name . length === 0 ) {
565- throw new Error ( `Invalid ${ location } : provider reference must be non-empty.` ) ;
566- }
567- return { name } ;
568- }
569-
570- if ( ! isJsonObject ( raw ) ) {
571- throw new Error ( `Invalid ${ location } : use a provider reference string or provider object.` ) ;
572- }
573-
592+ function providerDefinitionToRef (
593+ raw : Record < string , unknown > ,
594+ rawId : string ,
595+ definition : ProviderDefinition ,
596+ ) : EvalTargetRef {
574597 const hooks = parseTargetHooks ( raw . hooks ) ;
575- const definition = normalizeProviderDefinition (
576- Object . fromEntries ( Object . entries ( raw ) . filter ( ( [ key ] ) => key !== 'hooks' ) ) ,
577- { location } ,
578- ) as ProviderDefinition ;
579-
598+ const rawLabel =
599+ typeof raw . label === 'string' && raw . label . trim ( ) . length > 0 ? raw . label . trim ( ) : undefined ;
580600 return {
581601 name : definition . name ,
582- id : typeof raw . id === 'string' ? raw . id . trim ( ) : definition . provider ,
583- ...( definition . label !== undefined ? { label : definition . label } : { } ) ,
602+ id : rawId ,
603+ ...( rawLabel !== undefined ? { label : rawLabel } : { } ) ,
584604 definition,
585605 ...( hooks !== undefined ? { hooks } : { } ) ,
586606 } ;
0 commit comments