MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / readLocalStandaloneTestsFile

Function readLocalStandaloneTestsFile

src/util/testCaseReader.ts:177–237  ·  view source on GitHub ↗
(
  varsPath: string,
  basePath: string,
  finalConfig: Record<string, any> | undefined,
)

Source from the content-addressed store, hash-verified

175}
176
177async function readLocalStandaloneTestsFile(
178 varsPath: string,
179 basePath: string,
180 finalConfig: Record<string, any> | undefined,
181): Promise<TestCase[]> {
182 const {
183 resolvedVarsPath,
184 pathWithoutFunction,
185 maybeFunctionName,
186 fileExtension,
187 extensionWithoutSheet,
188 } = getStandaloneTestsFileMetadata(varsPath, basePath);
189
190 if (isJavascriptFile(pathWithoutFunction)) {
191 telemetry.record('feature_used', {
192 feature: 'js tests file',
193 });
194 return readJavascriptTestCases(pathWithoutFunction, maybeFunctionName, finalConfig);
195 }
196 if (fileExtension === 'py') {
197 telemetry.record('feature_used', {
198 feature: 'python tests file',
199 });
200 return readPythonTestCases(pathWithoutFunction, maybeFunctionName, finalConfig);
201 }
202
203 if (fileExtension === 'csv') {
204 telemetry.record('feature_used', {
205 feature: 'csv tests file - local',
206 });
207 return csvRowsToTestCases(await readLocalCsvRows(resolvedVarsPath));
208 }
209 if (extensionWithoutSheet === 'xlsx' || extensionWithoutSheet === 'xls') {
210 telemetry.record('feature_used', {
211 feature: 'xlsx tests file - local',
212 });
213 return csvRowsToTestCases(await parseXlsxFile(resolvedVarsPath));
214 }
215 if (fileExtension === 'json') {
216 telemetry.record('feature_used', {
217 feature: 'json tests file',
218 });
219 return readJsonTestCases(resolvedVarsPath);
220 }
221 if (fileExtension === 'jsonl') {
222 telemetry.record('feature_used', {
223 feature: 'jsonl tests file',
224 });
225 return readJsonlTestCases(resolvedVarsPath);
226 }
227 if (fileExtension === 'yaml' || fileExtension === 'yml') {
228 telemetry.record('feature_used', {
229 feature: 'yaml tests file',
230 });
231 const rawContent = yaml.load(await fsPromises.readFile(resolvedVarsPath, 'utf-8'));
232 const rows = maybeLoadConfigFromExternalFile(rawContent) as unknown as CsvRow[];
233 return csvRowsToTestCases(rows);
234 }

Callers 1

readStandaloneTestsFileFunction · 0.85

Calls 11

isJavascriptFileFunction · 0.90
parseXlsxFileFunction · 0.90
readJavascriptTestCasesFunction · 0.85
readPythonTestCasesFunction · 0.85
csvRowsToTestCasesFunction · 0.85
readLocalCsvRowsFunction · 0.85
readJsonTestCasesFunction · 0.85
readJsonlTestCasesFunction · 0.85
recordMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…