@wix/evalforge-evaluator 0.189.0 → 0.191.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.js +98 -10
- package/build/index.js.map +2 -2
- package/build/index.mjs +98 -10
- package/build/index.mjs.map +2 -2
- package/package.json +2 -2
package/build/index.mjs
CHANGED
|
@@ -7081,7 +7081,10 @@ function createApiClient(serverUrl, options = "") {
|
|
|
7081
7081
|
},
|
|
7082
7082
|
async provisionScenarioSite(projectId2, evalRunId2, scenarioId) {
|
|
7083
7083
|
const res = await httpClient.request(provisionScenarioSite({ projectId: projectId2, evalRunId: evalRunId2, scenarioId })).catch(
|
|
7084
|
-
(err) => rethrowWithRequestId(
|
|
7084
|
+
(err) => rethrowWithRequestId(
|
|
7085
|
+
err,
|
|
7086
|
+
`provision a site for scenario ${scenarioId}`
|
|
7087
|
+
)
|
|
7085
7088
|
);
|
|
7086
7089
|
const site = res.data.site;
|
|
7087
7090
|
if (!site) {
|
|
@@ -7516,12 +7519,71 @@ async function installDependencies(workDir, onProgress, options = {}) {
|
|
|
7516
7519
|
}
|
|
7517
7520
|
|
|
7518
7521
|
// src/run-scenario/environment.ts
|
|
7519
|
-
async function
|
|
7522
|
+
async function withTimeout(promise, ms, label) {
|
|
7523
|
+
let timer;
|
|
7524
|
+
const timeout = new Promise((_, reject) => {
|
|
7525
|
+
timer = setTimeout(
|
|
7526
|
+
() => reject(new Error(`${label} did not complete within ${ms}ms`)),
|
|
7527
|
+
ms
|
|
7528
|
+
);
|
|
7529
|
+
});
|
|
7530
|
+
try {
|
|
7531
|
+
return await Promise.race([promise, timeout]);
|
|
7532
|
+
} finally {
|
|
7533
|
+
clearTimeout(timer);
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
async function probeGitHubAccess(source, onProgress) {
|
|
7537
|
+
const token = process.env.GITHUB_TOKEN;
|
|
7538
|
+
const url = `https://api.github.com/repos/${source.owner}/${source.repo}`;
|
|
7539
|
+
const controller = new AbortController();
|
|
7540
|
+
const timer = setTimeout(() => controller.abort(), 5e3);
|
|
7541
|
+
const startedAt = Date.now();
|
|
7542
|
+
try {
|
|
7543
|
+
const res = await fetch(url, {
|
|
7544
|
+
headers: {
|
|
7545
|
+
"User-Agent": "EvalForge-Evaluator",
|
|
7546
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
7547
|
+
},
|
|
7548
|
+
signal: controller.signal
|
|
7549
|
+
});
|
|
7550
|
+
onProgress(
|
|
7551
|
+
`[diag] github reachable: HTTP ${res.status} for repos/${source.owner}/${source.repo} in ${Date.now() - startedAt}ms (token: ${token ? "present" : "MISSING"})`
|
|
7552
|
+
);
|
|
7553
|
+
} catch (err) {
|
|
7554
|
+
onProgress(
|
|
7555
|
+
`[diag] github UNREACHABLE after ${Date.now() - startedAt}ms: ${err instanceof Error ? err.message : String(err)} (token: ${token ? "present" : "MISSING"})`
|
|
7556
|
+
);
|
|
7557
|
+
} finally {
|
|
7558
|
+
clearTimeout(timer);
|
|
7559
|
+
}
|
|
7560
|
+
}
|
|
7561
|
+
async function fetchAndWriteTemplateFiles(template, workDir, onProgress) {
|
|
7520
7562
|
let sourceFiles = [];
|
|
7521
7563
|
if (template.source) {
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7564
|
+
const { owner, repo, path: srcPath, ref } = template.source;
|
|
7565
|
+
onProgress(
|
|
7566
|
+
`[diag] template.source = ${owner}/${repo}/${srcPath ?? ""}@${ref ?? "default"}`
|
|
7567
|
+
);
|
|
7568
|
+
await probeGitHubAccess(template.source, onProgress);
|
|
7569
|
+
const startedAt = Date.now();
|
|
7570
|
+
try {
|
|
7571
|
+
sourceFiles = await withTimeout(
|
|
7572
|
+
fetchGitHubFolder(template.source, {
|
|
7573
|
+
userAgent: "EvalForge-Evaluator"
|
|
7574
|
+
}),
|
|
7575
|
+
6e4,
|
|
7576
|
+
"template source fetch"
|
|
7577
|
+
);
|
|
7578
|
+
onProgress(
|
|
7579
|
+
`[diag] fetched ${sourceFiles.length} template file(s) in ${Date.now() - startedAt}ms`
|
|
7580
|
+
);
|
|
7581
|
+
} catch (err) {
|
|
7582
|
+
onProgress(
|
|
7583
|
+
`[diag] template source fetch FAILED after ${Date.now() - startedAt}ms: ${err instanceof Error ? err.message : String(err)}`
|
|
7584
|
+
);
|
|
7585
|
+
throw err;
|
|
7586
|
+
}
|
|
7525
7587
|
} else if (template.sourceFiles?.length) {
|
|
7526
7588
|
sourceFiles = template.sourceFiles;
|
|
7527
7589
|
} else {
|
|
@@ -7530,11 +7592,36 @@ async function fetchAndWriteTemplateFiles(template, workDir) {
|
|
|
7530
7592
|
);
|
|
7531
7593
|
}
|
|
7532
7594
|
await writeFilesToDirectory(workDir, sourceFiles);
|
|
7595
|
+
const extraFiles = template.extraFiles ?? [];
|
|
7596
|
+
onProgress(`[diag] resolving ${extraFiles.length} extra file(s)`);
|
|
7533
7597
|
await Promise.all(
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7598
|
+
extraFiles.map(async (ef) => {
|
|
7599
|
+
let content;
|
|
7600
|
+
if (ef.gitSource) {
|
|
7601
|
+
const { owner, repo, path: gitPath, ref } = ef.gitSource;
|
|
7602
|
+
const startedAt = Date.now();
|
|
7603
|
+
onProgress(
|
|
7604
|
+
`[diag] extra fetch start: ${ef.path} <- ${owner}/${repo}/${gitPath ?? ""}@${ref ?? "default"}`
|
|
7605
|
+
);
|
|
7606
|
+
try {
|
|
7607
|
+
content = await withTimeout(
|
|
7608
|
+
fetchGitHubFile(ef.gitSource, { userAgent: "EvalForge-Evaluator" }),
|
|
7609
|
+
3e4,
|
|
7610
|
+
`extra file fetch (${ef.path})`
|
|
7611
|
+
);
|
|
7612
|
+
onProgress(
|
|
7613
|
+
`[diag] extra fetch done: ${ef.path} (${content.length} bytes) in ${Date.now() - startedAt}ms`
|
|
7614
|
+
);
|
|
7615
|
+
} catch (err) {
|
|
7616
|
+
onProgress(
|
|
7617
|
+
`[diag] extra fetch FAILED: ${ef.path} after ${Date.now() - startedAt}ms: ${err instanceof Error ? err.message : String(err)}`
|
|
7618
|
+
);
|
|
7619
|
+
throw err;
|
|
7620
|
+
}
|
|
7621
|
+
} else {
|
|
7622
|
+
content = ef.content ?? "";
|
|
7623
|
+
onProgress(`[diag] extra inline: ${ef.path} (${content.length} bytes)`);
|
|
7624
|
+
}
|
|
7538
7625
|
const dest = path2.resolve(workDir, ef.path);
|
|
7539
7626
|
if (!dest.startsWith(workDir + sep2)) {
|
|
7540
7627
|
throw new Error(
|
|
@@ -7545,6 +7632,7 @@ async function fetchAndWriteTemplateFiles(template, workDir) {
|
|
|
7545
7632
|
await writeFile2(dest, content, "utf8");
|
|
7546
7633
|
})
|
|
7547
7634
|
);
|
|
7635
|
+
onProgress("[diag] all extra files written");
|
|
7548
7636
|
}
|
|
7549
7637
|
function writeWixEnvFile(workDir) {
|
|
7550
7638
|
const configPath = path2.join(workDir, "wix.config.json");
|
|
@@ -7582,7 +7670,7 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
|
|
|
7582
7670
|
}
|
|
7583
7671
|
mkdirSync2(workDir2, { recursive: true });
|
|
7584
7672
|
onProgress("Fetching template files...");
|
|
7585
|
-
await fetchAndWriteTemplateFiles(template, workDir2);
|
|
7673
|
+
await fetchAndWriteTemplateFiles(template, workDir2, onProgress);
|
|
7586
7674
|
console.log(`Template files written to ${workDir2}`);
|
|
7587
7675
|
writeWixEnvFile(workDir2);
|
|
7588
7676
|
await installDependencies(workDir2, onProgress, {
|