Skip to content

Commit

Permalink
fix: sharing option is degraded (promptfoo#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
mocyuto authored Dec 6, 2023
1 parent 71af29f commit 0e62e28
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export async function readConfigs(configPaths: string[]): Promise<UnifiedConfig>
(prev, curr) => ({ ...prev, ...curr.commandLineOptions }),
{},
),
sharing: !configs.some(config => config.sharing === false),
};

return combinedConfig;
Expand Down
51 changes: 50 additions & 1 deletion test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ describe('util', () => {
env: { envVar1: 'envValue1' },
evaluateOptions: { maxConcurrency: 1 },
commandLineOptions: { verbose: true },
sharing: false,
};
const config2 = {
description: 'test2',
Expand All @@ -419,10 +420,13 @@ describe('util', () => {
env: { envVar2: 'envValue2' },
evaluateOptions: { maxConcurrency: 2 },
commandLineOptions: { verbose: false },
sharing: true,
};

(globSync as jest.Mock).mockImplementation((pathOrGlob) => [pathOrGlob]);
(fs.readFileSync as jest.Mock)
.mockReturnValueOnce(JSON.stringify(config1))
.mockReturnValueOnce(JSON.stringify(config2))
.mockReturnValueOnce(JSON.stringify(config1))
.mockReturnValueOnce(JSON.stringify(config2))
.mockReturnValue('you should not see this');
Expand All @@ -433,9 +437,53 @@ describe('util', () => {
throw new Error('File does not exist');
});

const config1Result = await readConfigs(['config1.json']);
expect(config1Result).toEqual({
description: 'test1',
providers: ['provider1'],
prompts: ['prompt1'],
tests: ['test1'],
scenarios: ['scenario1'],
defaultTest: {
description: 'defaultTest1',
options: {},
vars: { var1: 'value1' },
assert: [
{ type: 'equals', value: 'expected1' },
],
},
nunjucksFilters: { filter1: 'filter1' },
env: { envVar1: 'envValue1' },
evaluateOptions: { maxConcurrency: 1 },
commandLineOptions: { verbose: true },
sharing: false,
});

const config2Result = await readConfigs(['config2.json']);
expect(config2Result).toEqual({
description: 'test2',
providers: ['provider2'],
prompts: ['prompt2'],
tests: ['test2'],
scenarios: ['scenario2'],
defaultTest: {
description: 'defaultTest2',
options: {},
vars: { var2: 'value2' },
assert: [
{ type: 'equals', value: 'expected2' },
],
},
nunjucksFilters: { filter2: 'filter2' },
env: { envVar2: 'envValue2' },
evaluateOptions: { maxConcurrency: 2 },
commandLineOptions: { verbose: false },
sharing: true,
});

const result = await readConfigs(['config1.json', 'config2.json']);

expect(fs.readFileSync).toHaveBeenCalledTimes(2);
expect(fs.readFileSync).toHaveBeenCalledTimes(4);
expect(result).toEqual({
description: 'test1, test2',
providers: ['provider1', 'provider2'],
Expand All @@ -455,6 +503,7 @@ describe('util', () => {
env: { envVar1: 'envValue1', envVar2: 'envValue2' },
evaluateOptions: { maxConcurrency: 2 },
commandLineOptions: { verbose: false },
sharing: false,
});
});

Expand Down

0 comments on commit 0e62e28

Please sign in to comment.