@wix/evalforge-evaluator 0.221.0 → 0.223.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/build/index.mjs CHANGED
@@ -6946,6 +6946,12 @@ function rethrowWithRequestId(err, action) {
6946
6946
  }
6947
6947
  throw err;
6948
6948
  }
6949
+ function requireEntity(entity, notFound) {
6950
+ if (!entity) {
6951
+ throw new Error(notFound);
6952
+ }
6953
+ return entity;
6954
+ }
6949
6955
  function resolveAmbassadorBaseUrl(serverUrl) {
6950
6956
  try {
6951
6957
  return new URL(serverUrl).origin;
@@ -6996,52 +7002,50 @@ function createApiClient(serverUrl, options = "") {
6996
7002
  const res = await httpClient.request(
6997
7003
  getEvalRun({ projectId: projectId2, evalRunId: id })
6998
7004
  );
6999
- const evalRun = res.data.evalRun;
7000
- if (!evalRun) {
7001
- throw new Error(`Eval run ${id} not found in project ${projectId2}`);
7002
- }
7005
+ const evalRun = requireEntity(
7006
+ res.data.evalRun,
7007
+ `Eval run ${id} not found in project ${projectId2}`
7008
+ );
7003
7009
  return evalRunFromProto(evalRun);
7004
7010
  },
7005
7011
  async getScenario(projectId2, id) {
7006
7012
  const res = await httpClient.request(
7007
7013
  getTestScenario({ projectId: projectId2, testScenarioId: id })
7008
7014
  );
7009
- const scenario = res.data.testScenario;
7010
- if (!scenario) {
7011
- throw new Error(
7012
- `Test scenario ${id} not found in project ${projectId2}`
7013
- );
7014
- }
7015
+ const scenario = requireEntity(
7016
+ res.data.testScenario,
7017
+ `Test scenario ${id} not found in project ${projectId2}`
7018
+ );
7015
7019
  return testScenarioFromProto(scenario);
7016
7020
  },
7017
7021
  async getAgent(projectId2, id) {
7018
7022
  const res = await httpClient.request(
7019
7023
  getAgent({ projectId: projectId2, agentId: id })
7020
7024
  );
7021
- const agent = res.data.agent;
7022
- if (!agent) {
7023
- throw new Error(`Agent ${id} not found in project ${projectId2}`);
7024
- }
7025
+ const agent = requireEntity(
7026
+ res.data.agent,
7027
+ `Agent ${id} not found in project ${projectId2}`
7028
+ );
7025
7029
  return agentFromProto(agent);
7026
7030
  },
7027
7031
  async getTemplate(projectId2, id) {
7028
7032
  const res = await httpClient.request(
7029
7033
  getTemplate({ projectId: projectId2, templateId: id })
7030
7034
  );
7031
- const template = res.data.template;
7032
- if (!template) {
7033
- throw new Error(`Template ${id} not found in project ${projectId2}`);
7034
- }
7035
+ const template = requireEntity(
7036
+ res.data.template,
7037
+ `Template ${id} not found in project ${projectId2}`
7038
+ );
7035
7039
  return templateFromProto(template);
7036
7040
  },
7037
7041
  async getPreset(projectId2, id) {
7038
7042
  const res = await httpClient.request(
7039
7043
  getPreset({ projectId: projectId2, presetId: id })
7040
7044
  );
7041
- const preset = res.data.preset;
7042
- if (!preset) {
7043
- throw new Error(`Preset ${id} not found in project ${projectId2}`);
7044
- }
7045
+ const preset = requireEntity(
7046
+ res.data.preset,
7047
+ `Preset ${id} not found in project ${projectId2}`
7048
+ );
7045
7049
  return presetFromProto(preset);
7046
7050
  },
7047
7051
  // The legacy REST endpoint enriched the capability with its latest version
@@ -7062,10 +7066,10 @@ function createApiClient(serverUrl, options = "") {
7062
7066
  if (capResult.status === "rejected") {
7063
7067
  throw capResult.reason;
7064
7068
  }
7065
- const capability = capResult.value.data.capability;
7066
- if (!capability) {
7067
- throw new Error(`Capability ${id} not found in project ${projectId2}`);
7068
- }
7069
+ const capability = requireEntity(
7070
+ capResult.value.data.capability,
7071
+ `Capability ${id} not found in project ${projectId2}`
7072
+ );
7069
7073
  let latestVersion;
7070
7074
  if (versionResult.status === "fulfilled" && versionResult.value.data.capabilityVersion) {
7071
7075
  latestVersion = capabilityVersionFromProto(
@@ -7088,12 +7092,10 @@ function createApiClient(serverUrl, options = "") {
7088
7092
  capabilityVersionId: versionId
7089
7093
  })
7090
7094
  );
7091
- const version = res.data.capabilityVersion;
7092
- if (!version) {
7093
- throw new Error(
7094
- `Capability version ${versionId} not found for capability ${capabilityId}`
7095
- );
7096
- }
7095
+ const version = requireEntity(
7096
+ res.data.capabilityVersion,
7097
+ `Capability version ${versionId} not found for capability ${capabilityId}`
7098
+ );
7097
7099
  return capabilityVersionFromProto(version, projectId2);
7098
7100
  },
7099
7101
  async addResult(projectId2, evalRunId2, result) {
@@ -7409,7 +7411,7 @@ import {
7409
7411
  } from "@wix/eval-assertions";
7410
7412
 
7411
7413
  // src/run-scenario/environment.ts
7412
- import { mkdirSync as mkdirSync2, existsSync as existsSync2, rmSync, readFileSync as readFileSync2, writeFileSync } from "fs";
7414
+ import { mkdirSync, existsSync as existsSync2, rmSync, readFileSync, writeFileSync } from "fs";
7413
7415
  import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
7414
7416
  import { tmpdir } from "os";
7415
7417
  import path2, { sep as sep2 } from "path";
@@ -7436,15 +7438,7 @@ async function writeFilesToDirectory(targetDir, files) {
7436
7438
  }
7437
7439
 
7438
7440
  // src/run-scenario/install-dependencies.ts
7439
- import {
7440
- mkdirSync,
7441
- existsSync,
7442
- readFileSync,
7443
- readdirSync,
7444
- copyFileSync,
7445
- cpSync
7446
- } from "fs";
7447
- import { createHash } from "crypto";
7441
+ import { existsSync, readdirSync } from "fs";
7448
7442
  import path from "path";
7449
7443
  import { spawn, execFileSync } from "child_process";
7450
7444
  var INSTALL_TIMEOUT_MS = 18e4;
@@ -7543,18 +7537,16 @@ function detectPackageManager(workDir) {
7543
7537
  if (existsSync(path.join(workDir, "pnpm-lock.yaml"))) {
7544
7538
  return {
7545
7539
  cmd: "pnpm",
7546
- args: ["install", "--frozen-lockfile"],
7547
- cacheSourceFile: "pnpm-lock.yaml"
7540
+ args: ["install", "--frozen-lockfile"]
7548
7541
  };
7549
7542
  }
7550
7543
  if (existsSync(path.join(workDir, "package-lock.json"))) {
7551
- return { cmd: "npm", args: ["ci"], cacheSourceFile: "package-lock.json" };
7544
+ return { cmd: "npm", args: ["ci"] };
7552
7545
  }
7553
7546
  if (existsSync(path.join(workDir, "yarn.lock"))) {
7554
7547
  return {
7555
7548
  cmd: "yarn",
7556
- args: ["install", "--frozen-lockfile"],
7557
- cacheSourceFile: "yarn.lock"
7549
+ args: ["install", "--frozen-lockfile"]
7558
7550
  };
7559
7551
  }
7560
7552
  return {
@@ -7565,17 +7557,9 @@ function detectPackageManager(workDir) {
7565
7557
  "--prefer-offline",
7566
7558
  "--no-fund",
7567
7559
  "--no-audit"
7568
- ],
7569
- cacheSourceFile: "package.json"
7560
+ ]
7570
7561
  };
7571
7562
  }
7572
- function cloneDirectory(src, dest) {
7573
- if (process.platform === "darwin") {
7574
- execFileSync("cp", ["-rc", src, dest]);
7575
- } else {
7576
- cpSync(src, dest, { recursive: true });
7577
- }
7578
- }
7579
7563
  async function runInstall(exec, pm, workDir, onProgress) {
7580
7564
  reportRegistry(workDir, onProgress);
7581
7565
  onProgress(`[diag] npm install starting: ${pm.cmd} ${pm.args.join(" ")}`);
@@ -7606,64 +7590,13 @@ async function runInstall(exec, pm, workDir, onProgress) {
7606
7590
  clearInterval(heartbeat);
7607
7591
  }
7608
7592
  }
7609
- async function installWithCache(workDir, exec, cacheBase, pm, onProgress) {
7610
- const sourceContent = readFileSync(
7611
- path.join(workDir, pm.cacheSourceFile),
7612
- "utf-8"
7613
- );
7614
- const cacheKey = createHash("sha256").update(sourceContent).digest("hex").slice(0, 16);
7615
- const cachedNodeModules = path.join(cacheBase, cacheKey, "node_modules");
7616
- const targetNodeModules = path.join(workDir, "node_modules");
7617
- const cacheDir = path.dirname(cachedNodeModules);
7618
- const cachedYarnLock = path.join(cacheDir, "yarn.lock");
7619
- if (existsSync(cachedNodeModules)) {
7620
- console.log(
7621
- `[environment] Restoring node_modules from cache (key: ${cacheKey})`
7622
- );
7623
- onProgress(`[diag] node_modules cache HIT (key: ${cacheKey}) \u2014 restoring`);
7624
- if (!existsSync(targetNodeModules)) {
7625
- cloneDirectory(cachedNodeModules, targetNodeModules);
7626
- }
7627
- if (existsSync(cachedYarnLock)) {
7628
- copyFileSync(cachedYarnLock, path.join(workDir, "yarn.lock"));
7629
- }
7630
- onProgress("[diag] node_modules cache restore complete");
7631
- return;
7632
- }
7633
- onProgress(`[diag] node_modules cache MISS (key: ${cacheKey})`);
7634
- const ok = await runInstall(exec, pm, workDir, onProgress);
7635
- if (!ok) {
7636
- return;
7637
- }
7638
- console.log(
7639
- "[environment] Dependency installation complete \u2014 saving to cache"
7640
- );
7641
- try {
7642
- mkdirSync(cacheDir, { recursive: true });
7643
- const yarnLockPath = path.join(workDir, "yarn.lock");
7644
- if (existsSync(yarnLockPath)) {
7645
- copyFileSync(yarnLockPath, cachedYarnLock);
7646
- }
7647
- cloneDirectory(targetNodeModules, cachedNodeModules);
7648
- } catch (err) {
7649
- console.error(
7650
- "[environment] Failed to save to cache (installation still succeeded):",
7651
- err instanceof Error ? err.message : String(err)
7652
- );
7653
- }
7654
- }
7655
7593
  async function installDependencies(workDir, onProgress, options = {}) {
7656
7594
  if (!existsSync(path.join(workDir, "package.json"))) {
7657
7595
  return;
7658
7596
  }
7659
7597
  const exec = options.exec ?? defaultExec;
7660
- const cacheBase = options.cacheBase;
7661
7598
  onProgress("Installing dependencies...");
7662
7599
  const pm = detectPackageManager(workDir);
7663
- if (cacheBase) {
7664
- await installWithCache(workDir, exec, cacheBase, pm, onProgress);
7665
- return;
7666
- }
7667
7600
  await runInstall(exec, pm, workDir, onProgress);
7668
7601
  }
7669
7602
 
@@ -7791,7 +7724,7 @@ function writeWixEnvFile(workDir) {
7791
7724
  return;
7792
7725
  }
7793
7726
  try {
7794
- const config = JSON.parse(readFileSync2(configPath, "utf-8"));
7727
+ const config = JSON.parse(readFileSync(configPath, "utf-8"));
7795
7728
  if (config.appId) {
7796
7729
  writeFileSync(
7797
7730
  path2.join(workDir, ".env"),
@@ -7808,7 +7741,6 @@ function writeWixEnvFile(workDir) {
7808
7741
  async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId, onProgress, options = {}) {
7809
7742
  const template = options.template;
7810
7743
  const baseDir = config.evaluationsDir ?? path2.join(tmpdir(), "evalforge-evaluations");
7811
- const nodeModulesCacheDir = path2.join(baseDir, "_node_modules_cache");
7812
7744
  if (template) {
7813
7745
  if (!config.evaluationsDir) {
7814
7746
  console.warn(
@@ -7819,7 +7751,7 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
7819
7751
  if (existsSync2(workDir2)) {
7820
7752
  rmSync(workDir2, { recursive: true });
7821
7753
  }
7822
- mkdirSync2(workDir2, { recursive: true });
7754
+ mkdirSync(workDir2, { recursive: true });
7823
7755
  onProgress("Fetching template files...");
7824
7756
  await fetchAndWriteTemplateFiles(template, workDir2, onProgress);
7825
7757
  console.log(`Template files written to ${workDir2}`);
@@ -7827,7 +7759,6 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
7827
7759
  writeWixEnvFile(workDir2);
7828
7760
  onProgress("[diag] entering installDependencies");
7829
7761
  await installDependencies(workDir2, onProgress, {
7830
- cacheBase: nodeModulesCacheDir,
7831
7762
  exec: createLoggingInstallExec(onProgress)
7832
7763
  });
7833
7764
  onProgress("[diag] installDependencies returned");
@@ -7838,7 +7769,7 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
7838
7769
  if (existsSync2(workDir)) {
7839
7770
  rmSync(workDir, { recursive: true });
7840
7771
  }
7841
- mkdirSync2(workDir, { recursive: true });
7772
+ mkdirSync(workDir, { recursive: true });
7842
7773
  console.log(`Empty working directory created at ${workDir}`);
7843
7774
  return workDir;
7844
7775
  }
@@ -11630,7 +11561,7 @@ var simpleAgentAdapter = new SimpleAgentAdapter();
11630
11561
  defaultRegistry.register(simpleAgentAdapter);
11631
11562
 
11632
11563
  // src/run-scenario/file-diff.ts
11633
- import { readdirSync as readdirSync2, readFileSync as readFileSync3, statSync, existsSync as existsSync3 } from "fs";
11564
+ import { readdirSync as readdirSync2, readFileSync as readFileSync2, statSync, existsSync as existsSync3 } from "fs";
11634
11565
  import { join as join10, relative } from "path";
11635
11566
 
11636
11567
  // ../../node_modules/diff/lib/index.mjs
@@ -12273,7 +12204,7 @@ function snapshotDirectory(dir, baseDir) {
12273
12204
  if (stats.size > MAX_FILE_SIZE) {
12274
12205
  continue;
12275
12206
  }
12276
- const content = readFileSync3(fullPath, "utf-8");
12207
+ const content = readFileSync2(fullPath, "utf-8");
12277
12208
  snapshot[relativePath] = content;
12278
12209
  } catch {
12279
12210
  continue;