promptfoo 0.17.9 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/util.ts CHANGED
@@ -4,6 +4,7 @@ import * as os from 'os';
4
4
 
5
5
  import $RefParser from '@apidevtools/json-schema-ref-parser';
6
6
  import fetch from 'node-fetch';
7
+ import invariant from 'tiny-invariant';
7
8
  import yaml from 'js-yaml';
8
9
  import nunjucks from 'nunjucks';
9
10
  import { globSync } from 'glob';
@@ -44,6 +45,15 @@ export function readProviderPromptMap(
44
45
  allPrompts.push(prompt.display);
45
46
  }
46
47
 
48
+ invariant(
49
+ typeof config.providers !== 'string',
50
+ 'In order to use a provider-prompt map, config.providers should be an array of objects, not a string',
51
+ );
52
+ invariant(
53
+ typeof config.providers !== 'function',
54
+ 'In order to use a provider-prompt map, config.providers should be an array of objects, not a function',
55
+ );
56
+
47
57
  for (const provider of config.providers) {
48
58
  if (typeof provider === 'object') {
49
59
  const rawProvider = provider as RawProviderConfig;
@@ -446,7 +456,7 @@ export function writeLatestResults(results: EvaluateSummary, config: Partial<Uni
446
456
  2,
447
457
  ),
448
458
  );
449
- if (fs.existsSync(latestResultsPath)) {
459
+ if (fs.existsSync(latestResultsPath) && fs.lstatSync(latestResultsPath).isSymbolicLink()) {
450
460
  fs.unlinkSync(latestResultsPath);
451
461
  }
452
462
  fs.symlinkSync(newResultsPath, latestResultsPath);
@@ -463,7 +473,7 @@ export function listPreviousResults(): string[] {
463
473
  const sortedFiles = resultsFiles.sort((a, b) => {
464
474
  const statA = fs.statSync(path.join(directory, a));
465
475
  const statB = fs.statSync(path.join(directory, b));
466
- return statB.birthtime.getTime() - statA.birthtime.getTime(); // sort in descending order
476
+ return statA.birthtime.getTime() - statB.birthtime.getTime(); // sort in ascending order
467
477
  });
468
478
  return sortedFiles;
469
479
  }