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

Function getStandaloneTestsFileMetadata

src/util/testCaseReader.ts:247–279  ·  view source on GitHub ↗
(
  varsPath: string,
  basePath: string,
)

Source from the content-addressed store, hash-verified

245}
246
247function getStandaloneTestsFileMetadata(
248 varsPath: string,
249 basePath: string,
250): StandaloneTestsFileMetadata {
251 const resolvedVarsPath = path.resolve(basePath, varsPath.replace(/^file:\/\//, ''));
252 // Split on the last colon to handle Windows drive letters correctly
253 const colonCount = resolvedVarsPath.split(':').length - 1;
254 const lastColonIndex = resolvedVarsPath.lastIndexOf(':');
255
256 // For Windows paths, we need to account for the drive letter colon
257 const isWindowsPath = /^[A-Za-z]:/.test(resolvedVarsPath);
258 const effectiveColonCount = isWindowsPath ? colonCount - 1 : colonCount;
259
260 if (effectiveColonCount > 1) {
261 throw new Error(`Too many colons. Invalid test file script path: ${varsPath}`);
262 }
263
264 const pathWithoutFunction =
265 lastColonIndex > 1 ? resolvedVarsPath.slice(0, lastColonIndex) : resolvedVarsPath;
266 const maybeFunctionName =
267 lastColonIndex > 1 ? resolvedVarsPath.slice(lastColonIndex + 1) : undefined;
268 const fileExtension = parsePath(pathWithoutFunction).ext.slice(1);
269 // For xlsx/xls files, remove sheet specifier (e.g., #Sheet1) from extension
270 const extensionWithoutSheet = fileExtension.split('#')[0];
271
272 return {
273 resolvedVarsPath,
274 pathWithoutFunction,
275 maybeFunctionName,
276 fileExtension,
277 extensionWithoutSheet,
278 };
279}
280
281async function readJavascriptTestCases(
282 pathWithoutFunction: string,

Callers 1

Calls 2

resolveMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…