@m4trix/evals 0.1.0 → 0.3.0

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/dist/cli.js CHANGED
@@ -5,8 +5,10 @@ import { useApp, useInput, Box, Text } from 'ink';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { randomUUID } from 'crypto';
7
7
  import { Effect, PubSub, Queue, Fiber } from 'effect';
8
+ import { existsSync } from 'fs';
9
+ import { resolve, relative, join, dirname } from 'path';
10
+ import * as jitiModule from 'jiti';
8
11
  import { mkdir, appendFile, readdir } from 'fs/promises';
9
- import { relative, join, dirname, resolve } from 'path';
10
12
  import { pathToFileURL } from 'url';
11
13
 
12
14
  var SEP = " ";
@@ -1292,10 +1294,104 @@ var defaultRunnerConfig = {
1292
1294
  },
1293
1295
  artifactDirectory: ".eval-results"
1294
1296
  };
1297
+ function toRunnerConfigOverrides(config) {
1298
+ if (!config) {
1299
+ return void 0;
1300
+ }
1301
+ const rawDiscovery = config.discovery;
1302
+ const discovery = {};
1303
+ if (rawDiscovery?.rootDir !== void 0) {
1304
+ discovery.rootDir = rawDiscovery.rootDir;
1305
+ }
1306
+ if (rawDiscovery?.datasetFilePatterns !== void 0) {
1307
+ discovery.datasetSuffixes = rawDiscovery.datasetFilePatterns;
1308
+ } else if (rawDiscovery?.datasetSuffixes !== void 0) {
1309
+ discovery.datasetSuffixes = rawDiscovery.datasetSuffixes;
1310
+ }
1311
+ if (rawDiscovery?.evaluatorFilePatterns !== void 0) {
1312
+ discovery.evaluatorSuffixes = rawDiscovery.evaluatorFilePatterns;
1313
+ } else if (rawDiscovery?.evaluatorSuffixes !== void 0) {
1314
+ discovery.evaluatorSuffixes = rawDiscovery.evaluatorSuffixes;
1315
+ }
1316
+ if (rawDiscovery?.testCaseFilePatterns !== void 0) {
1317
+ discovery.testCaseSuffixes = rawDiscovery.testCaseFilePatterns;
1318
+ } else if (rawDiscovery?.testCaseSuffixes !== void 0) {
1319
+ discovery.testCaseSuffixes = rawDiscovery.testCaseSuffixes;
1320
+ }
1321
+ if (rawDiscovery?.excludeDirectories !== void 0) {
1322
+ discovery.excludeDirectories = rawDiscovery.excludeDirectories;
1323
+ }
1324
+ const overrides = {};
1325
+ if (config.artifactDirectory !== void 0) {
1326
+ overrides.artifactDirectory = config.artifactDirectory;
1327
+ }
1328
+ if (Object.keys(discovery).length > 0) {
1329
+ overrides.discovery = discovery;
1330
+ }
1331
+ return overrides;
1332
+ }
1295
1333
  function withRunnerConfig(overrides) {
1296
- {
1334
+ if (!overrides) {
1297
1335
  return defaultRunnerConfig;
1298
1336
  }
1337
+ const discovery = overrides.discovery ? {
1338
+ ...defaultRunnerConfig.discovery,
1339
+ ...overrides.discovery
1340
+ } : defaultRunnerConfig.discovery;
1341
+ return {
1342
+ ...defaultRunnerConfig,
1343
+ ...overrides,
1344
+ discovery
1345
+ };
1346
+ }
1347
+ var CONFIG_FILE_NAME = "m4trix-eval.config.ts";
1348
+ var cachedLoader;
1349
+ function getJitiLoader() {
1350
+ if (cachedLoader) {
1351
+ return cachedLoader;
1352
+ }
1353
+ const createJiti2 = jitiModule.createJiti ?? jitiModule.default;
1354
+ if (typeof createJiti2 !== "function") {
1355
+ throw new Error(
1356
+ "Failed to initialize jiti for m4trix eval config loading."
1357
+ );
1358
+ }
1359
+ cachedLoader = createJiti2(import.meta.url, {
1360
+ interopDefault: true,
1361
+ moduleCache: true
1362
+ });
1363
+ return cachedLoader;
1364
+ }
1365
+ function resolveConfigModuleExport(loadedModule) {
1366
+ if (loadedModule && typeof loadedModule === "object" && "default" in loadedModule) {
1367
+ return loadedModule.default;
1368
+ }
1369
+ return loadedModule;
1370
+ }
1371
+ function resolveConfigValue(value) {
1372
+ if (value === void 0 || value === null) {
1373
+ return void 0;
1374
+ }
1375
+ if (typeof value === "function") {
1376
+ return value();
1377
+ }
1378
+ if (typeof value !== "object") {
1379
+ throw new Error(
1380
+ "Invalid m4trix eval config export. Expected an object or defineConfig(() => config)."
1381
+ );
1382
+ }
1383
+ return value;
1384
+ }
1385
+ function loadRunnerConfigFile(cwd = process.cwd()) {
1386
+ const configPath = resolve(cwd, CONFIG_FILE_NAME);
1387
+ if (!existsSync(configPath)) {
1388
+ return void 0;
1389
+ }
1390
+ const loader = getJitiLoader();
1391
+ const loaded = loader(configPath);
1392
+ const exportedValue = resolveConfigModuleExport(loaded);
1393
+ const config = resolveConfigValue(exportedValue);
1394
+ return toRunnerConfigOverrides(config);
1299
1395
  }
1300
1396
  var jitiLoader;
1301
1397
  function toId(prefix, filePath, name) {
@@ -1348,12 +1444,12 @@ function hasOneSuffix(filePath, suffixes) {
1348
1444
  async function loadModuleExports(filePath) {
1349
1445
  if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) {
1350
1446
  if (!jitiLoader) {
1351
- const jitiModule = await import('jiti');
1352
- const createJiti = jitiModule.createJiti ?? jitiModule.default;
1353
- if (!createJiti) {
1447
+ const jitiModule2 = await import('jiti');
1448
+ const createJiti2 = jitiModule2.createJiti ?? jitiModule2.default;
1449
+ if (!createJiti2) {
1354
1450
  throw new Error("Failed to initialize jiti TypeScript loader");
1355
1451
  }
1356
- jitiLoader = createJiti(import.meta.url, {
1452
+ jitiLoader = createJiti2(import.meta.url, {
1357
1453
  interopDefault: true,
1358
1454
  moduleCache: true
1359
1455
  });
@@ -1758,8 +1854,18 @@ function createNameMatcher(pattern) {
1758
1854
  }
1759
1855
  return (value) => value.toLowerCase() === normalizedPattern.toLowerCase();
1760
1856
  }
1857
+ function mergeRunnerOverrides(base, next) {
1858
+ if (!base) {
1859
+ return next;
1860
+ }
1861
+ {
1862
+ return base;
1863
+ }
1864
+ }
1761
1865
  function createRunner(overrides) {
1762
- return new EffectRunner(withRunnerConfig());
1866
+ const fileOverrides = loadRunnerConfigFile();
1867
+ const merged = mergeRunnerOverrides(fileOverrides, overrides);
1868
+ return new EffectRunner(withRunnerConfig(merged));
1763
1869
  }
1764
1870
  var EffectRunner = class {
1765
1871
  constructor(config) {