@nexface/evals 0.0.0-stage → 0.1.21-alpha.7
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/CLI.md +55 -0
- package/README.md +35 -2
- package/approved-task.mjs +32 -0
- package/cli.mjs +31 -0
- package/execution-model.mjs +48 -0
- package/generated.mjs +72 -0
- package/judge.mjs +88 -0
- package/native-tools.mjs +149 -0
- package/package.json +52 -4
- package/playwright.cjs +1 -0
- package/playwright.d.mts +10 -0
- package/playwright.mjs +1 -0
- package/report-output.mjs +195 -0
- package/runner.mjs +160 -0
- package/session.mjs +89 -0
- package/site-run.mjs +134 -0
- package/spec-config.mjs +24 -0
- package/spec-reporter.mjs +63 -0
- package/spec-run.mjs +87 -0
- package/studio.html +613 -0
- package/studio.mjs +244 -0
- package/suite.mjs +112 -0
- package/task-fixture.mjs +314 -0
- package/task-session.mjs +97 -0
package/task-session.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { runSiteAgent } from "./site-run.mjs";
|
|
4
|
+
import { siteConnection } from "./native-tools.mjs";
|
|
5
|
+
import { readSuite, taskRevision } from "./suite.mjs";
|
|
6
|
+
import { taskAssets } from "./generated.mjs";
|
|
7
|
+
import { bounded } from "./session.mjs";
|
|
8
|
+
|
|
9
|
+
export async function openTask(page, baseURL, testInfo) {
|
|
10
|
+
const options = JSON.parse(process.env.NEXFACE_SPEC_OPTIONS || "{}");
|
|
11
|
+
const id = testInfo.title;
|
|
12
|
+
if (process.env.NEXFACE_SPEC_OPTIONS) {
|
|
13
|
+
const { dir } = options;
|
|
14
|
+
const counts = JSON.parse(await readFile(join(dir, "test-counts.json"), "utf8"));
|
|
15
|
+
if (counts[id] !== 1) throw new Error("Expected exactly one test for task: " + id);
|
|
16
|
+
}
|
|
17
|
+
const suite = await readSuite(process.cwd());
|
|
18
|
+
const task = suite?.tasks.find((task) => task.id === id);
|
|
19
|
+
if (!task) throw new Error("No approved task for spec: " + id);
|
|
20
|
+
if (suite.status !== "ready") throw new Error("Approve the task before running its spec.");
|
|
21
|
+
const record = await taskAssets(process.cwd(), task);
|
|
22
|
+
const revision = taskRevision(task);
|
|
23
|
+
if (options.dir) {
|
|
24
|
+
const selection = JSON.parse(await readFile(join(options.dir, "selection.json"), "utf8"))[id];
|
|
25
|
+
if (selection?.revision !== revision || selection.fingerprint !== (record?.fingerprint ?? null))
|
|
26
|
+
throw new Error(
|
|
27
|
+
"The task or registered spec changed after selection. Start a new evaluation: " + id,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const origin = new URL(baseURL).origin;
|
|
31
|
+
const row = {
|
|
32
|
+
id,
|
|
33
|
+
goal: task.goal,
|
|
34
|
+
revision,
|
|
35
|
+
fingerprint: record?.fingerprint,
|
|
36
|
+
status: "blocked",
|
|
37
|
+
stage: "Starting page",
|
|
38
|
+
checks: [],
|
|
39
|
+
calls: [],
|
|
40
|
+
};
|
|
41
|
+
const site = siteConnection(page, origin, row);
|
|
42
|
+
await page.addInitScript((expected) => {
|
|
43
|
+
globalThis[Symbol.for("@nexface/evals/phase")] =
|
|
44
|
+
location.origin === expected ? "read" : "forbidden";
|
|
45
|
+
}, origin);
|
|
46
|
+
|
|
47
|
+
function assertStartingRoute() {
|
|
48
|
+
const start = new URL(task.start?.route ?? baseURL, baseURL);
|
|
49
|
+
if (new URL(page.url()).origin !== origin || (task.start?.route && page.url() !== start.href))
|
|
50
|
+
throw new Error("Unexpected starting route: " + new URL(page.url()).pathname);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function execute(goal) {
|
|
54
|
+
row.stage = "Tool discovery";
|
|
55
|
+
const deadline = Date.now() + 8000;
|
|
56
|
+
do {
|
|
57
|
+
row.tools = await site.tools();
|
|
58
|
+
if (row.tools.length) break;
|
|
59
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
60
|
+
} while (Date.now() < deadline);
|
|
61
|
+
if (!row.tools.length)
|
|
62
|
+
throw new Error("No WebMCP business tools published on the starting page.");
|
|
63
|
+
|
|
64
|
+
row.stage = "Task execution";
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timer = setTimeout(() => controller.abort(new Error("Task timed out.")), 90000);
|
|
67
|
+
try {
|
|
68
|
+
const result = await bounded(
|
|
69
|
+
runSiteAgent(goal, 90000, site, controller.signal),
|
|
70
|
+
93000,
|
|
71
|
+
"Task timed out.",
|
|
72
|
+
);
|
|
73
|
+
row.reply = result.output;
|
|
74
|
+
row.model = result.model;
|
|
75
|
+
if (result.blockedReason || result.outcome.type === "interrupt") {
|
|
76
|
+
row.interrupted = true;
|
|
77
|
+
row.reason = result.blockedReason ?? "User confirmation required.";
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
row.reason = controller.signal.aborted ? "Task timed out." : error.message;
|
|
81
|
+
} finally {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
controller.abort();
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
row.calls.some(
|
|
87
|
+
(call) =>
|
|
88
|
+
call.status === "running" ||
|
|
89
|
+
(call.phase === "task" && call.status === "error" && /timeout/i.test(call.error ?? "")),
|
|
90
|
+
)
|
|
91
|
+
) {
|
|
92
|
+
row.traceWarning = "A dispatched tool may still be running. The final page state is unknown.";
|
|
93
|
+
}
|
|
94
|
+
row.endURL = page.url().split(/[?#]/)[0];
|
|
95
|
+
}
|
|
96
|
+
return { task, origin, row, site, assertStartingRoute, execute };
|
|
97
|
+
}
|