Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/cli/src/commands/eval/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@agentv/core';
import { array, command, multioption, option, optional, positional, string } from 'cmd-ts';

import { discoverTargetsFile } from '../../../utils/targets.js';
import { discoverProvidersFile } from '../../../utils/providers.js';
import { loadEnvFromHierarchy } from '../env.js';
import { findRepoRoot, resolveEvalPaths } from '../shared.js';
import { readTestSuiteTarget } from '../targets.js';
Expand Down Expand Up @@ -216,7 +216,7 @@ export const evalBundleCommand = command({
definitions = [suite.inlineTarget];
targetNames = unique(args.provider.length > 0 ? args.provider : [suite.inlineTarget.name]);
} else {
const targetsFilePath = await discoverTargetsFile({
const targetsFilePath = await discoverProvidersFile({
explicitPath: args.providers,
testFilePath: evalFilePath,
repoRoot,
Expand Down
12 changes: 6 additions & 6 deletions apps/cli/src/commands/eval/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import { listProviderLabels, readProviderDefinitions } from '@agentv/core';
import { checkbox, confirm, number, search, select } from '@inquirer/prompts';

import { PROVIDER_FILE_CANDIDATES, fileExists } from '../../utils/targets.js';
import { PROVIDER_FILE_CANDIDATES, fileExists } from '../../utils/providers.js';
import {
type DiscoveredEvalFile,
discoverEvalFiles,
Expand Down Expand Up @@ -202,14 +202,14 @@ async function promptTargetSelection(cwd: string, firstEvalPath: string): Promis
const repoRoot = await findRepoRoot(cwd);

// Try to find providers.yaml near the eval file first, then cwd/repoRoot.
const targetsPath = await findTargetsFile(cwd, repoRoot, firstEvalPath);
const providersPath = await findProvidersFile(cwd, repoRoot, firstEvalPath);

if (!targetsPath) {
if (!providersPath) {
console.log(`${ANSI_DIM}No providers.yaml found. Using default provider.${ANSI_RESET}`);
return 'default';
}

const definitions = await readProviderDefinitions(targetsPath);
const definitions = await readProviderDefinitions(providersPath);
const targetNames = listProviderLabels(definitions);

if (targetNames.length === 0) {
Expand Down Expand Up @@ -239,12 +239,12 @@ async function promptTargetSelection(cwd: string, firstEvalPath: string): Promis
});
}

async function findTargetsFile(
async function findProvidersFile(
cwd: string,
repoRoot: string,
evalFilePath?: string,
): Promise<string | undefined> {
// Build directory chain: eval file dir cwd repoRoot (mirrors discoverTargetsFile)
// Build directory chain: eval file dir -> cwd -> repoRoot.
const dirsToSearch: string[] = [];

if (evalFilePath) {
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/eval/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
resolveProviderDefinitionEnvironments,
} from '@agentv/core';
import { validateTargetsFile } from '@agentv/core/evaluation/validation';
import { discoverTargetsFile } from '../../utils/targets.js';
import { discoverProvidersFile } from '../../utils/providers.js';

const ANSI_YELLOW = '\u001b[33m';
const ANSI_RED = '\u001b[31m';
Expand Down Expand Up @@ -134,7 +134,7 @@ async function readProviderCatalog(options: {
'No provider catalog configured. Add `providers:` to .agentv/config.yaml, use `providers: file://providers.yaml`, or pass --providers <path>.',
);
}
const targetsFilePath = await discoverTargetsFile({
const targetsFilePath = await discoverProvidersFile({
explicitPath: options.explicitTargetsPath,
testFilePath: options.testFilePath,
repoRoot: options.repoRoot,
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/results/eval-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { listProviderLabels, readProviderDefinitions } from '@agentv/core';
import type { Context } from 'hono';
import type { Hono } from 'hono';

import { PROVIDER_FILE_CANDIDATES } from '../../utils/targets.js';
import { PROVIDER_FILE_CANDIDATES } from '../../utils/providers.js';
import { discoverEvalFiles } from '../eval/discover.js';
import {
RESULT_INDEX_FILENAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ async function findProviderFileInDirectory(directory: string): Promise<string |
return undefined;
}

async function findLegacyTargetFileInDirectory(directory: string): Promise<string | undefined> {
async function findLegacyGeneratedTargetFileInDirectory(
directory: string,
): Promise<string | undefined> {
for (const candidate of LEGACY_TARGET_FILE_CANDIDATES) {
const fullPath = path.join(directory, candidate);
if ((await pathKind(fullPath)) === 'file') {
Expand All @@ -71,11 +73,12 @@ async function findLegacyTargetFileInDirectory(directory: string): Promise<strin
return undefined;
}

export async function discoverTargetsFile(options: {
export async function discoverProvidersFile(options: {
readonly explicitPath?: string;
readonly testFilePath: string;
readonly repoRoot: string;
readonly cwd: string;
/** Rerun-only carveout for old generated test bundles that captured targets.yaml. */
readonly allowLegacyTargetFiles?: boolean;
}): Promise<string> {
const { explicitPath, testFilePath, repoRoot, cwd, allowLegacyTargetFiles = false } = options;
Expand All @@ -95,7 +98,7 @@ export async function discoverTargetsFile(options: {
if (providerFile) {
return providerFile;
}
const legacyTargetFile = await findLegacyTargetFileInDirectory(resolvedExplicit);
const legacyTargetFile = await findLegacyGeneratedTargetFileInDirectory(resolvedExplicit);
if (legacyTargetFile) {
if (allowLegacyTargetFiles) {
return legacyTargetFile;
Expand Down Expand Up @@ -123,7 +126,7 @@ export async function discoverTargetsFile(options: {
}

for (const directory of directories) {
const legacyTargetFile = await findLegacyTargetFileInDirectory(directory);
const legacyTargetFile = await findLegacyGeneratedTargetFileInDirectory(directory);
if (legacyTargetFile) {
if (allowLegacyTargetFiles) {
return legacyTargetFile;
Expand Down
39 changes: 39 additions & 0 deletions apps/cli/test/commands/eval/targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,45 @@ describe('eval target selection', () => {
expect(selections[0]?.resolvedTarget.config.response).toBe('modern');
});

it('uses an explicit directory containing providers.yaml', async () => {
const agentvDir = path.join(tempDir, '.agentv');
await mkdir(agentvDir, { recursive: true });
await writeFile(
path.join(agentvDir, 'providers.yaml'),
['- id: mock', ' label: directory-modern', ' response: directory', ''].join('\n'),
);
const evalPath = path.join(tempDir, 'provider-directory-discovery.eval.yaml');
await writeFile(
evalPath,
[
'providers:',
' - directory-modern',
'prompts:',
' - "{{ input }}"',
'tests:',
' - id: provider-case',
' criteria: ok',
' vars:',
' input: hello',
].join('\n'),
);

const suite = await loadTestSuite(evalPath, tempDir);
const selections = await selectMultipleTargets({
testFilePath: evalPath,
repoRoot: tempDir,
cwd: tempDir,
explicitTargetsPath: agentvDir,
env: {},
targetNames: suite.targets ?? [],
targetRefs: suite.targetRefs,
targetSource: 'test-file',
});

expect(selections[0]?.targetName).toBe('directory-modern');
expect(selections[0]?.resolvedTarget.config.response).toBe('directory');
});

it('requires config or explicit provider catalog when requested', async () => {
const agentvDir = path.join(tempDir, '.agentv');
await mkdir(agentvDir, { recursive: true });
Expand Down
Loading