Skip to content

Commit 9275f35

Browse files
committed
refactor: normalize directory options
1 parent a28008e commit 9275f35

8 files changed

Lines changed: 23 additions & 24 deletions

File tree

packages/agent-eval/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ APIs:
8181
```ts
8282
import {findScenario, listScenarios, loadExperimentConfigs, run, type Model} from '@primer/agent-eval'
8383

84-
const scenarios = await listScenarios({scenariosDirectory: './scenarios'})
84+
const experiments = await loadExperimentConfigs({directory: './experiments'})
85+
const scenarios = await listScenarios({directory: './scenarios'})
8586
const scenario = await findScenario('001-agent-uses-button-from-primer', {
86-
scenariosDirectory: './scenarios',
87+
directory: './scenarios',
8788
})
8889
```

packages/agent-eval/src/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ if (!existsSync(ARTIFACTS_DIR)) {
6666
if (values.experiment) {
6767
experimentConfigs = await loadExperimentConfigs({
6868
experiment: values.experiment,
69-
experimentsDirectory: values.experiments,
69+
directory: values.experiments,
7070
})
7171
if (experimentConfigs.length === 0) {
7272
console.log('Experiments:')
7373
console.log(
7474
(
7575
await listExperiments({
76-
experimentsDirectory: values.experiments,
76+
directory: values.experiments,
7777
})
7878
)
7979
.map(([name]) => name)
@@ -82,7 +82,7 @@ if (values.experiment) {
8282
}
8383
} else {
8484
experimentConfigs = await loadExperimentConfigs({
85-
experimentsDirectory: values.experiments,
85+
directory: values.experiments,
8686
})
8787
}
8888

@@ -392,7 +392,7 @@ for (const config of experimentConfigs) {
392392
const scenarios = await Promise.all(
393393
config.scenarios.map(scenarioConfig => {
394394
return resolveExperimentScenario(scenarioConfig, {
395-
scenariosDirectory: values.scenarios,
395+
directory: values.scenarios,
396396
})
397397
}),
398398
)

packages/agent-eval/src/experiments.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('local experiment loading', () => {
3434
test('lists experiments from a local directory', async () => {
3535
const directory = await createExperimentsDirectory()
3636

37-
await expect(listExperiments({experimentsDirectory: directory})).resolves.toEqual([
37+
await expect(listExperiments({directory})).resolves.toEqual([
3838
['default-export', expect.objectContaining({name: 'Default export'})],
3939
['example', expect.objectContaining({name: 'Example'})],
4040
])
@@ -43,9 +43,7 @@ describe('local experiment loading', () => {
4343
test('finds a named experiment from a local directory', async () => {
4444
const directory = await createExperimentsDirectory()
4545

46-
await expect(findExperiment('example', {experimentsDirectory: directory})).resolves.toEqual(
47-
expect.objectContaining({name: 'Example'}),
48-
)
46+
await expect(findExperiment('example', {directory})).resolves.toEqual(expect.objectContaining({name: 'Example'}))
4947
})
5048

5149
test('finds an experiment from a local file path', async () => {
@@ -67,6 +65,6 @@ describe('local experiment loading', () => {
6765
test('loads all experiments when no experiment is specified', async () => {
6866
const directory = await createExperimentsDirectory()
6967

70-
await expect(loadExperimentConfigs({experimentsDirectory: directory})).resolves.toHaveLength(2)
68+
await expect(loadExperimentConfigs({directory})).resolves.toHaveLength(2)
7169
})
7270
})

packages/agent-eval/src/experiments.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type ExperimentModule = {
1111
}
1212

1313
type ExperimentSourceOptions = {
14-
experimentsDirectory?: string
14+
directory?: string
1515
}
1616

1717
type LoadExperimentOptions = ExperimentSourceOptions & {
@@ -64,8 +64,8 @@ async function getLocalExperimentEntries(experimentsDirectory: string): Promise<
6464
}
6565

6666
async function listExperiments(options: ExperimentSourceOptions = {}): Promise<Array<[string, ExperimentConfig]>> {
67-
if (options.experimentsDirectory) {
68-
return getLocalExperimentEntries(options.experimentsDirectory)
67+
if (options.directory) {
68+
return getLocalExperimentEntries(options.directory)
6969
}
7070

7171
return listPackagedExperiments()
@@ -75,8 +75,8 @@ async function findExperiment(
7575
id: string,
7676
options: ExperimentSourceOptions = {},
7777
): Promise<ExperimentConfig | undefined> {
78-
if (options.experimentsDirectory) {
79-
const experiments = await getLocalExperimentEntries(options.experimentsDirectory)
78+
if (options.directory) {
79+
const experiments = await getLocalExperimentEntries(options.directory)
8080
return experiments.find(([name]) => name === id)?.[1]
8181
}
8282

packages/agent-eval/src/scenario.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe(resolveExperimentScenario, () => {
3030

3131
await expect(
3232
resolveExperimentScenario('button-scenario', {
33-
scenariosDirectory,
33+
directory: scenariosDirectory,
3434
}),
3535
).resolves.toEqual({
3636
id: 'button-scenario',

packages/agent-eval/src/scenario.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ async function resolveExperimentScenario(
1212
): Promise<ResolvedScenario> {
1313
if (typeof scenarioConfig === 'string') {
1414
const scenario = await findScenario(scenarioConfig, {
15-
scenariosDirectory: options.scenariosDirectory,
15+
directory: options.directory,
1616
})
1717
if (!scenario) {
1818
throw new Error(
19-
`Scenario "${scenarioConfig}" was not found in: ${path.resolve(options.scenariosDirectory ?? 'scenarios')}`,
19+
`Scenario "${scenarioConfig}" was not found in: ${path.resolve(options.directory ?? 'scenarios')}`,
2020
)
2121
}
2222
return scenario

packages/agent-eval/src/scenarios.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('scenario loading', () => {
3434
await createScenario(scenariosDirectory, 'second', 'Second prompt')
3535
await createScenario(scenariosDirectory, 'first', 'First prompt')
3636

37-
await expect(listScenarios({scenariosDirectory})).resolves.toEqual([
37+
await expect(listScenarios({directory: scenariosDirectory})).resolves.toEqual([
3838
expect.objectContaining({id: 'first', config: {prompt: 'First prompt'}}),
3939
expect.objectContaining({id: 'second', config: {prompt: 'Second prompt'}}),
4040
])
@@ -44,7 +44,7 @@ describe('scenario loading', () => {
4444
const scenariosDirectory = await createScenariosDirectory()
4545
const directory = await createScenario(scenariosDirectory, 'example', 'Example prompt')
4646

47-
await expect(findScenario('example', {scenariosDirectory})).resolves.toEqual({
47+
await expect(findScenario('example', {directory: scenariosDirectory})).resolves.toEqual({
4848
id: 'example',
4949
directory,
5050
config: {prompt: 'Example prompt'},
@@ -55,6 +55,6 @@ describe('scenario loading', () => {
5555
test('returns undefined when a scenario is not found', async () => {
5656
const scenariosDirectory = await createScenariosDirectory()
5757

58-
await expect(findScenario('missing-scenario', {scenariosDirectory})).resolves.toBeUndefined()
58+
await expect(findScenario('missing-scenario', {directory: scenariosDirectory})).resolves.toBeUndefined()
5959
})
6060
})

packages/agent-eval/src/scenarios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ type ResolvedScenario = {
1111
}
1212

1313
type ScenarioSourceOptions = {
14-
scenariosDirectory?: string
14+
directory?: string
1515
}
1616

1717
function resolveScenariosDirectory(options: ScenarioSourceOptions): string {
18-
return path.resolve(options.scenariosDirectory ?? 'scenarios')
18+
return path.resolve(options.directory ?? 'scenarios')
1919
}
2020

2121
async function assertScenariosDirectory(directory: string) {

0 commit comments

Comments
 (0)