@lelouchhe/agent-evals 0.1.1 → 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/README.md +27 -18
- package/dist/checkers/file/index.js +181 -13
- package/dist/checkers/judge/index.d.ts +1 -1
- package/dist/checkers/judge/index.js +243 -31
- package/dist/checkers/judge/prompt.d.ts +4 -3
- package/dist/checkers/judge/prompt.js +22 -3
- package/dist/cli.js +171 -35
- package/dist/engine/authoring.js +108 -13
- package/dist/engine/check-runner.js +18 -3
- package/dist/engine/check-sandbox.js +9 -6
- package/dist/engine/config.d.ts +31 -2
- package/dist/engine/config.js +16 -10
- package/dist/engine/env-source.js +82 -14
- package/dist/engine/files.d.ts +2 -5
- package/dist/engine/files.js +4 -6
- package/dist/engine/mocks.js +72 -46
- package/dist/engine/params.d.ts +2 -0
- package/dist/engine/params.js +10 -0
- package/dist/engine/registry.d.ts +11 -0
- package/dist/engine/report.js +43 -8
- package/dist/engine/results.d.ts +7 -0
- package/dist/engine/results.js +9 -6
- package/dist/engine/run.d.ts +4 -1
- package/dist/engine/run.js +171 -28
- package/dist/engine/skills.js +12 -5
- package/dist/engine/view.d.ts +1 -1
- package/dist/engine/view.js +125 -10
- package/dist/engine/workspace.d.ts +7 -0
- package/dist/engine/workspace.js +37 -27
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/platform/index.d.ts +31 -0
- package/dist/platform/index.js +88 -0
- package/dist/platform/linux/index.d.ts +2 -0
- package/dist/platform/linux/index.js +40 -0
- package/dist/platform/linux/launch.d.ts +8 -0
- package/dist/platform/linux/launch.js +25 -0
- package/dist/platform/linux/policy.d.ts +46 -0
- package/dist/platform/linux/policy.js +388 -0
- package/dist/platform/linux/supervise.d.ts +8 -0
- package/dist/platform/linux/supervise.js +124 -0
- package/dist/platform/macos/index.d.ts +2 -0
- package/dist/platform/macos/index.js +59 -0
- package/dist/platform/macos/launch.d.ts +2 -8
- package/dist/platform/macos/launch.js +5 -3
- package/dist/platform/macos/policy.d.ts +3 -21
- package/dist/platform/macos/policy.js +5 -2
- package/dist/platform/macos/supervise.d.ts +3 -25
- package/dist/platform/posix-forwarder-client.mjs +129 -0
- package/dist/platform/posix-forwarder.sh +9 -0
- package/dist/platform/posix-helpers.d.ts +22 -0
- package/dist/platform/posix-helpers.js +97 -0
- package/dist/platform/types.d.ts +118 -0
- package/dist/platform/types.js +1 -0
- package/dist/platform/windows/forwarder-client.mjs +165 -0
- package/dist/platform/windows/forwarder.cmd +3 -0
- package/dist/platform/windows/forwarder.ps1 +2 -0
- package/dist/platform/windows/forwarder.sh +2 -0
- package/dist/platform/windows/index.d.ts +2 -0
- package/dist/platform/windows/index.js +225 -0
- package/dist/platform/windows/launch.d.ts +3 -0
- package/dist/platform/windows/launch.js +30 -0
- package/dist/platform/windows/policy.d.ts +17 -0
- package/dist/platform/windows/policy.js +155 -0
- package/dist/platform/windows/setup.ps1 +112 -0
- package/dist/platform/windows/supervise.d.ts +2 -0
- package/dist/platform/windows/supervise.js +142 -0
- package/dist/platform/windows/win-sandbox.exe +0 -0
- package/dist/runners/acp/commands.js +2 -3
- package/dist/runners/acp/environment.d.ts +1 -7
- package/dist/runners/acp/environment.js +18 -48
- package/dist/runners/acp/index.js +5 -1
- package/dist/runners/acp/session.d.ts +1 -1
- package/dist/runners/pi/index.js +2 -2
- package/dist/runners/pi/session.d.ts +1 -1
- package/dist/runners/pi/session.js +27 -44
- package/dist/runners/pi/supervisor.js +1 -0
- package/package.json +5 -3
- package/dist/engine/forwarder.sh +0 -61
package/dist/cli.js
CHANGED
|
@@ -7,34 +7,41 @@ import { judgeChecker } from "./checkers/judge/index.js";
|
|
|
7
7
|
import { mockChecker } from "./checkers/mock/index.js";
|
|
8
8
|
import { shellChecker } from "./checkers/shell/index.js";
|
|
9
9
|
import { traceChecker } from "./checkers/trace/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { loadCases } from "./engine/authoring.js";
|
|
11
11
|
import { ConfigError, errorMessage } from "./engine/config.js";
|
|
12
|
+
import { createEnvSource } from "./engine/env-source.js";
|
|
12
13
|
import { addChecker, addRunner, createRegistry, loadTrustedImplementations } from "./engine/registry.js";
|
|
13
14
|
import { executeEvaluation, prepareEvaluation } from "./engine/run.js";
|
|
14
15
|
import { formatMatrix, formatReport } from "./engine/report.js";
|
|
15
16
|
import { runOutcome } from "./engine/results.js";
|
|
16
17
|
import { describePlacement } from "./engine/placement.js";
|
|
17
18
|
import { formatResolvedCase } from "./engine/view.js";
|
|
19
|
+
import { setupSandbox } from "./platform/index.js";
|
|
18
20
|
import { piRunner } from "./runners/pi/index.js";
|
|
19
21
|
import { noopRunner } from "./runners/noop/index.js";
|
|
20
22
|
import { runAgentCommand } from "./runners/acp/commands.js";
|
|
21
23
|
import { acpRunner } from "./runners/acp/index.js";
|
|
22
|
-
const USAGE = `Usage: agent-evals <command>
|
|
24
|
+
const USAGE = `Usage: agent-evals <command> [arguments] [options]
|
|
23
25
|
|
|
24
26
|
Commands:
|
|
25
27
|
run <config.yml> Execute the selected case, or every case when --case is omitted
|
|
26
|
-
view <config.yml> Show the
|
|
28
|
+
view <config.yml> Show the selected case, or every case when --case is omitted
|
|
27
29
|
report <results-dir>... Print a session report from retained run records
|
|
28
30
|
config <agent.yml> Query ACP configuration values without prompting
|
|
29
31
|
login <agent.yml> Run the declared native command and save login files
|
|
32
|
+
setup <target> Prepare host prerequisites (sandbox)
|
|
30
33
|
|
|
31
34
|
Options:
|
|
32
|
-
--case <name> Named case to select (
|
|
33
|
-
--reps <n> Repeat each selected case n times
|
|
35
|
+
--case <name> Named case to select (omitting selects every case in a cases document)
|
|
36
|
+
--reps <n> Repeat each selected case n times (default: 1)
|
|
37
|
+
--jobs <n> Maximum concurrent runs (default: 1)
|
|
38
|
+
--retain <mode> Retain workspace and home (excluding login): none, on-failure, all (default: none)
|
|
34
39
|
--results-dir <path> Where run records are written (default: .agent-evals)
|
|
35
40
|
--extension-dir <path> Trusted extension root, one implementation per subdirectory (repeatable)
|
|
36
41
|
--files With view: list every placed and excluded path
|
|
37
42
|
--matrix With report: one table of checks by case instead of the session report
|
|
43
|
+
--teardown With setup: remove host sandbox setup instead of provisioning it
|
|
44
|
+
--version, -V Show version
|
|
38
45
|
--help Show this help
|
|
39
46
|
|
|
40
47
|
Configuration errors exit with code 2 before any run resource is created.
|
|
@@ -54,16 +61,25 @@ async function main(argv) {
|
|
|
54
61
|
process.stdout.write(USAGE);
|
|
55
62
|
return 0;
|
|
56
63
|
}
|
|
64
|
+
if (error instanceof VersionRequested) {
|
|
65
|
+
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
66
|
+
process.stdout.write(`${pkg.version ?? "unknown"}\n`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
57
69
|
process.stderr.write(`error: ${errorMessage(error)}\n\n${USAGE}`);
|
|
58
70
|
return 2;
|
|
59
71
|
}
|
|
60
72
|
try {
|
|
61
73
|
if (options.command === "view") {
|
|
62
|
-
const
|
|
74
|
+
const cases = await loadCases(options.configPath, {
|
|
63
75
|
...(options.caseName === undefined ? {} : { caseName: options.caseName }),
|
|
64
76
|
});
|
|
65
|
-
const
|
|
66
|
-
|
|
77
|
+
const rendered = [];
|
|
78
|
+
for (const resolved of cases) {
|
|
79
|
+
const placement = await describePlacement(resolved);
|
|
80
|
+
rendered.push(formatResolvedCase(resolved, { placement, files: options.showFiles }));
|
|
81
|
+
}
|
|
82
|
+
process.stdout.write(rendered.join("\n"));
|
|
67
83
|
return 0;
|
|
68
84
|
}
|
|
69
85
|
if (options.command === "report") {
|
|
@@ -85,6 +101,12 @@ async function main(argv) {
|
|
|
85
101
|
process.off("SIGTERM", onSignal);
|
|
86
102
|
}
|
|
87
103
|
}
|
|
104
|
+
if (options.command === "setup") {
|
|
105
|
+
const output = await setupSandbox({ teardown: options.teardown });
|
|
106
|
+
if (output.length > 0)
|
|
107
|
+
process.stdout.write(output);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
88
110
|
return await runCommand(options);
|
|
89
111
|
}
|
|
90
112
|
catch (error) {
|
|
@@ -126,10 +148,18 @@ async function runCommand(options) {
|
|
|
126
148
|
});
|
|
127
149
|
await loadTrustedImplementations(registry, { extensionDirs: options.extensionDirs });
|
|
128
150
|
const resultsDir = options.resultsDir ?? resolve(".agent-evals");
|
|
151
|
+
const envSource = createEnvSource(process.cwd(), abort.signal);
|
|
129
152
|
const prepared = [];
|
|
130
153
|
for (let rep = 0; rep < options.reps; rep += 1) {
|
|
131
154
|
for (const entry of cases) {
|
|
132
|
-
prepared.push(await prepareEvaluation({
|
|
155
|
+
prepared.push(await prepareEvaluation({
|
|
156
|
+
case: entry,
|
|
157
|
+
registry,
|
|
158
|
+
resultsDir,
|
|
159
|
+
retain: options.retain,
|
|
160
|
+
signal: abort.signal,
|
|
161
|
+
envSource,
|
|
162
|
+
}));
|
|
133
163
|
}
|
|
134
164
|
}
|
|
135
165
|
// One repetition of one case keeps the single-run output; so does an ordinary document.
|
|
@@ -139,15 +169,58 @@ async function runCommand(options) {
|
|
|
139
169
|
process.stdout.write(`\n${formatReport([record])}`);
|
|
140
170
|
return exitCode(record);
|
|
141
171
|
}
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
const slots = new Array(prepared.length);
|
|
173
|
+
const pending = prepared.map((_, index) => index);
|
|
174
|
+
const inFlightKeys = new Set();
|
|
175
|
+
let firstError;
|
|
176
|
+
let active = 0;
|
|
177
|
+
// Event-driven bounded pool: runs sharing a `concurrencyKey` (e.g., persistent ACP login.dir)
|
|
178
|
+
// serialize while unrelated runs execute concurrently up to `options.jobs`. If any worker
|
|
179
|
+
// rejects unexpectedly, abort and wait for all active workers to drain before exiting.
|
|
180
|
+
await new Promise((resolvePool) => {
|
|
181
|
+
const schedule = () => {
|
|
182
|
+
while (active < options.jobs && !abort.signal.aborted && firstError === undefined) {
|
|
183
|
+
const pos = pending.findIndex((index) => prepared[index].registered.concurrencyKeys.every((key) => !inFlightKeys.has(key)));
|
|
184
|
+
if (pos === -1)
|
|
185
|
+
break;
|
|
186
|
+
const [index] = pending.splice(pos, 1);
|
|
187
|
+
const entry = prepared[index];
|
|
188
|
+
const keys = entry.registered.concurrencyKeys;
|
|
189
|
+
for (const key of keys)
|
|
190
|
+
inFlightKeys.add(key);
|
|
191
|
+
active += 1;
|
|
192
|
+
void executeEvaluation(entry)
|
|
193
|
+
.then((record) => {
|
|
194
|
+
slots[index] = record;
|
|
195
|
+
}, (caught) => {
|
|
196
|
+
firstError ??= caught;
|
|
197
|
+
abort.abort();
|
|
198
|
+
})
|
|
199
|
+
.finally(() => {
|
|
200
|
+
for (const key of keys)
|
|
201
|
+
inFlightKeys.delete(key);
|
|
202
|
+
active -= 1;
|
|
203
|
+
schedule();
|
|
204
|
+
if (active === 0 && (pending.length === 0 || abort.signal.aborted || firstError !== undefined)) {
|
|
205
|
+
resolvePool();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (active === 0) {
|
|
210
|
+
resolvePool();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
schedule();
|
|
214
|
+
});
|
|
215
|
+
if (firstError !== undefined) {
|
|
216
|
+
throw firstError;
|
|
148
217
|
}
|
|
218
|
+
const records = [];
|
|
149
219
|
const casesPerRep = cases.length;
|
|
150
|
-
for (const [index, record] of
|
|
220
|
+
for (const [index, record] of slots.entries()) {
|
|
221
|
+
if (record === undefined)
|
|
222
|
+
continue;
|
|
223
|
+
records.push(record);
|
|
151
224
|
const repLabel = options.reps === 1 ? "" : `rep ${Math.floor(index / casesPerRep) + 1}/${options.reps} `;
|
|
152
225
|
printCaseLine(record, resultsDir, repLabel);
|
|
153
226
|
}
|
|
@@ -181,7 +254,11 @@ function parseArguments(argv) {
|
|
|
181
254
|
"extension-dir": { type: "string", multiple: true },
|
|
182
255
|
files: { type: "boolean" },
|
|
183
256
|
matrix: { type: "boolean" },
|
|
257
|
+
teardown: { type: "boolean" },
|
|
184
258
|
reps: { type: "string" },
|
|
259
|
+
jobs: { type: "string" },
|
|
260
|
+
retain: { type: "string" },
|
|
261
|
+
version: { type: "boolean", short: "V" },
|
|
185
262
|
help: { type: "boolean", short: "h" },
|
|
186
263
|
},
|
|
187
264
|
});
|
|
@@ -193,27 +270,48 @@ function parseArguments(argv) {
|
|
|
193
270
|
if (values.help === true) {
|
|
194
271
|
throw new HelpRequested();
|
|
195
272
|
}
|
|
273
|
+
if (values.version === true) {
|
|
274
|
+
throw new VersionRequested();
|
|
275
|
+
}
|
|
196
276
|
const [command, rawConfigPath, ...unexpected] = positionals;
|
|
197
|
-
if (command !== "run" &&
|
|
277
|
+
if (command !== "run" &&
|
|
278
|
+
command !== "view" &&
|
|
279
|
+
command !== "report" &&
|
|
280
|
+
command !== "config" &&
|
|
281
|
+
command !== "login" &&
|
|
282
|
+
command !== "setup") {
|
|
198
283
|
throw new ConfigError(command === undefined ? "a command is required" : `unknown command: ${command}`);
|
|
199
284
|
}
|
|
200
285
|
if (rawConfigPath === undefined) {
|
|
201
|
-
throw new ConfigError(command === "report"
|
|
286
|
+
throw new ConfigError(command === "report"
|
|
287
|
+
? "a results directory is required"
|
|
288
|
+
: command === "setup"
|
|
289
|
+
? "a setup target is required (supported: sandbox)"
|
|
290
|
+
: "a configuration file is required");
|
|
202
291
|
}
|
|
203
292
|
if (command !== "report" && unexpected.length > 0) {
|
|
204
293
|
throw new ConfigError(`unexpected argument: ${unexpected[0]}`);
|
|
205
294
|
}
|
|
295
|
+
if (command === "setup" && rawConfigPath !== "sandbox") {
|
|
296
|
+
throw new ConfigError(`unknown setup target: ${rawConfigPath} (supported: sandbox)`);
|
|
297
|
+
}
|
|
206
298
|
if ((command === "config" || command === "login") &&
|
|
207
299
|
(values.case !== undefined ||
|
|
208
300
|
values["results-dir"] !== undefined ||
|
|
209
301
|
values["extension-dir"] !== undefined ||
|
|
210
|
-
values.reps !== undefined
|
|
302
|
+
values.reps !== undefined ||
|
|
303
|
+
values.jobs !== undefined ||
|
|
304
|
+
values.retain !== undefined)) {
|
|
211
305
|
throw new ConfigError(`${command} accepts only an agent configuration file, not case or run options`);
|
|
212
306
|
}
|
|
213
307
|
const extensionDirs = (values["extension-dir"] ?? []).map((directory) => resolve(directory));
|
|
214
308
|
if (command === "view" &&
|
|
215
|
-
(values["results-dir"] !== undefined ||
|
|
216
|
-
|
|
309
|
+
(values["results-dir"] !== undefined ||
|
|
310
|
+
extensionDirs.length > 0 ||
|
|
311
|
+
values.reps !== undefined ||
|
|
312
|
+
values.jobs !== undefined ||
|
|
313
|
+
values.retain !== undefined)) {
|
|
314
|
+
throw new ConfigError("view does not accept --results-dir, --extension-dir, --reps, --jobs or --retain");
|
|
217
315
|
}
|
|
218
316
|
if (command !== "view" && values.files === true) {
|
|
219
317
|
throw new ConfigError("--files applies only to view");
|
|
@@ -221,34 +319,59 @@ function parseArguments(argv) {
|
|
|
221
319
|
if (command !== "report" && values.matrix === true) {
|
|
222
320
|
throw new ConfigError("--matrix applies only to report");
|
|
223
321
|
}
|
|
322
|
+
if (command !== "setup" && values.teardown === true) {
|
|
323
|
+
throw new ConfigError("--teardown applies only to setup");
|
|
324
|
+
}
|
|
325
|
+
if (command === "setup" &&
|
|
326
|
+
(values.case !== undefined ||
|
|
327
|
+
values["results-dir"] !== undefined ||
|
|
328
|
+
extensionDirs.length > 0 ||
|
|
329
|
+
values.reps !== undefined ||
|
|
330
|
+
values.jobs !== undefined ||
|
|
331
|
+
values.retain !== undefined)) {
|
|
332
|
+
throw new ConfigError("setup accepts only a target and optional --teardown");
|
|
333
|
+
}
|
|
224
334
|
if (command === "report" &&
|
|
225
335
|
(values.case !== undefined ||
|
|
226
336
|
values["results-dir"] !== undefined ||
|
|
227
337
|
values["extension-dir"] !== undefined ||
|
|
228
|
-
values.reps !== undefined
|
|
338
|
+
values.reps !== undefined ||
|
|
339
|
+
values.jobs !== undefined ||
|
|
340
|
+
values.retain !== undefined)) {
|
|
229
341
|
throw new ConfigError("report accepts only results directories");
|
|
230
342
|
}
|
|
231
|
-
const reps = values.reps === undefined ? 1 :
|
|
343
|
+
const reps = values.reps === undefined ? 1 : expectPositiveInt(values.reps, "--reps");
|
|
344
|
+
const jobs = values.jobs === undefined ? 1 : expectPositiveInt(values.jobs, "--jobs");
|
|
345
|
+
const retain = values.retain === undefined ? "none" : expectRetain(values.retain);
|
|
232
346
|
return {
|
|
233
347
|
command,
|
|
234
|
-
configPath: resolve(rawConfigPath),
|
|
348
|
+
configPath: command === "setup" ? rawConfigPath : resolve(rawConfigPath),
|
|
235
349
|
...(values.case === undefined ? {} : { caseName: values.case }),
|
|
236
350
|
...(values["results-dir"] === undefined ? {} : { resultsDir: resolve(values["results-dir"]) }),
|
|
237
351
|
extensionDirs,
|
|
238
352
|
showFiles: values.files === true,
|
|
239
353
|
matrix: values.matrix === true,
|
|
354
|
+
teardown: values.teardown === true,
|
|
240
355
|
reps,
|
|
356
|
+
jobs,
|
|
357
|
+
retain,
|
|
241
358
|
extraPaths: unexpected.map((path) => resolve(path)),
|
|
242
359
|
};
|
|
243
360
|
}
|
|
244
|
-
/** A
|
|
245
|
-
function
|
|
361
|
+
/** A count flag is a positive integer written in decimal that a loop can count to. */
|
|
362
|
+
function expectPositiveInt(value, flag) {
|
|
246
363
|
const count = Number(value);
|
|
247
364
|
if (!/^[0-9]+$/.test(value) || !Number.isSafeInteger(count) || count < 1) {
|
|
248
|
-
throw new ConfigError(
|
|
365
|
+
throw new ConfigError(`${flag} must be a positive integer, got ${JSON.stringify(value)}`);
|
|
249
366
|
}
|
|
250
367
|
return count;
|
|
251
368
|
}
|
|
369
|
+
function expectRetain(value) {
|
|
370
|
+
if (value !== "none" && value !== "on-failure" && value !== "all") {
|
|
371
|
+
throw new ConfigError(`--retain must be "none", "on-failure", or "all", got ${JSON.stringify(value)}`);
|
|
372
|
+
}
|
|
373
|
+
return value;
|
|
374
|
+
}
|
|
252
375
|
/**
|
|
253
376
|
* Read every retained run record under the given paths. A path may be a results directory (walked
|
|
254
377
|
* recursively), a single run directory or a `result.json` file.
|
|
@@ -295,16 +418,18 @@ async function findResultFiles(path) {
|
|
|
295
418
|
if (info.isFile()) {
|
|
296
419
|
return [path];
|
|
297
420
|
}
|
|
421
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
422
|
+
// A directory with `result.json` is a single run record; do not recurse into its subdirectories.
|
|
423
|
+
if (entries.some((entry) => !entry.isDirectory() && entry.name === "result.json")) {
|
|
424
|
+
return [join(path, "result.json")];
|
|
425
|
+
}
|
|
298
426
|
const found = [];
|
|
299
|
-
for (const entry of
|
|
300
|
-
|
|
301
|
-
if (entry.isDirectory()) {
|
|
302
|
-
for (const file of await findResultFiles(
|
|
427
|
+
for (const entry of entries) {
|
|
428
|
+
// Never descend into retained artifact trees, even for an incomplete run with no `result.json`.
|
|
429
|
+
if (entry.isDirectory() && entry.name !== "artifacts") {
|
|
430
|
+
for (const file of await findResultFiles(join(path, entry.name)))
|
|
303
431
|
found.push(file);
|
|
304
432
|
}
|
|
305
|
-
else if (entry.name === "result.json") {
|
|
306
|
-
found.push(child);
|
|
307
|
-
}
|
|
308
433
|
}
|
|
309
434
|
return found.sort();
|
|
310
435
|
}
|
|
@@ -318,6 +443,12 @@ function printRecord(record, resultsDir) {
|
|
|
318
443
|
if (record.error !== undefined) {
|
|
319
444
|
lines.push(` error: ${record.error}`);
|
|
320
445
|
}
|
|
446
|
+
if (record.artifacts?.status === "retained" && record.artifacts.path !== undefined) {
|
|
447
|
+
lines.push(` artifacts: ${join(resultsDir, record.runId, record.artifacts.path)}`);
|
|
448
|
+
}
|
|
449
|
+
else if (record.artifacts?.status === "failed") {
|
|
450
|
+
lines.push(` artifacts: failed — ${record.artifacts.error ?? "unknown error"}`);
|
|
451
|
+
}
|
|
321
452
|
lines.push(` results: ${join(resultsDir, record.runId, "result.json")}`);
|
|
322
453
|
process.stdout.write(lines.join("\n") + "\n");
|
|
323
454
|
}
|
|
@@ -337,7 +468,10 @@ function exitCode(record) {
|
|
|
337
468
|
/** One summary line per executed case: name, status and the retained result record. */
|
|
338
469
|
function printCaseLine(record, resultsDir, prefix = "") {
|
|
339
470
|
const name = record.case.name ?? record.case.path;
|
|
340
|
-
|
|
471
|
+
const retainNote = record.artifacts?.status === "failed"
|
|
472
|
+
? ` (artifacts retention failed: ${record.artifacts.error ?? "unknown error"})`
|
|
473
|
+
: "";
|
|
474
|
+
process.stdout.write(`${prefix}${name}: ${runOutcome(record)} ${join(resultsDir, record.runId, "result.json")}${retainNote}\n`);
|
|
341
475
|
}
|
|
342
476
|
/** Zero only when every case passed, 1 for failed checks, 2 for anything that could not be judged. */
|
|
343
477
|
function aggregateExit(records) {
|
|
@@ -348,5 +482,7 @@ function aggregateExit(records) {
|
|
|
348
482
|
}
|
|
349
483
|
class HelpRequested extends Error {
|
|
350
484
|
}
|
|
485
|
+
class VersionRequested extends Error {
|
|
486
|
+
}
|
|
351
487
|
const code = await main(process.argv.slice(2));
|
|
352
488
|
process.exitCode = code;
|
package/dist/engine/authoring.js
CHANGED
|
@@ -3,7 +3,7 @@ import { dirname, resolve } from "node:path";
|
|
|
3
3
|
import { parseImplementationParams } from "./params.js";
|
|
4
4
|
import { checkPlaceholders, substituteValues } from "./values.js";
|
|
5
5
|
import { isAlias, isMap, isNode, isScalar, isSeq, parseDocument } from "yaml";
|
|
6
|
-
import { CASES_KEY, CASE_FIELD_KEYS, ConfigError, errorMessage, expectCaseConfig, } from "./config.js";
|
|
6
|
+
import { CASES_KEY, CASE_FIELDS, CASE_FIELD_KEYS, ConfigError, errorMessage, expectCaseConfig, } from "./config.js";
|
|
7
7
|
/**
|
|
8
8
|
* Resolve one YAML authoring document to a single case.
|
|
9
9
|
*
|
|
@@ -44,27 +44,30 @@ async function readCaseDocument(path) {
|
|
|
44
44
|
common.push(field);
|
|
45
45
|
}
|
|
46
46
|
const cases = casesField === undefined ? undefined : parseCases(casesField, file, text);
|
|
47
|
-
return { file, common, ...(cases === undefined ? {} : { cases }) };
|
|
47
|
+
return { file, text, common, ...(cases === undefined ? {} : { cases }) };
|
|
48
48
|
}
|
|
49
49
|
function buildCase(document, selected) {
|
|
50
|
-
const { file, common } = document;
|
|
51
|
-
if (selected !== undefined) {
|
|
52
|
-
const commonKeys = new Set(common.map((field) => field.key));
|
|
53
|
-
const shared = selected.fields.filter((field) => commonKeys.has(field.key)).map((field) => field.key);
|
|
54
|
-
if (shared.length > 0) {
|
|
55
|
-
throw new ConfigError(`case "${selected.name}" in ${file} repeats top-level field${shared.length === 1 ? "" : "s"} from the common part: ${shared.join(", ")}; common and selected fields must be disjoint`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
50
|
+
const { file, text, common } = document;
|
|
58
51
|
const final = {};
|
|
59
52
|
const origins = {};
|
|
60
53
|
for (const field of common) {
|
|
54
|
+
const type = fieldType(field.key);
|
|
61
55
|
final[field.key] = fieldValue(field);
|
|
62
|
-
origins[field.key] = { file, line: field.line, kind: "common" };
|
|
56
|
+
origins[field.key] = extractFieldOrigin(type, field, { file, line: field.line, kind: "common" }, text);
|
|
63
57
|
}
|
|
64
58
|
if (selected !== undefined) {
|
|
65
59
|
for (const field of selected.fields) {
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
const type = fieldType(field.key);
|
|
61
|
+
const nextValue = fieldValue(field);
|
|
62
|
+
const nextOrigin = extractFieldOrigin(type, field, { file, line: field.line, kind: "case", caseName: selected.name }, text);
|
|
63
|
+
if (Object.hasOwn(final, field.key)) {
|
|
64
|
+
final[field.key] = composeFieldValue(type, final[field.key], nextValue);
|
|
65
|
+
origins[field.key] = composeFieldOrigin(type, origins[field.key], nextOrigin);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
final[field.key] = nextValue;
|
|
69
|
+
origins[field.key] = nextOrigin;
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
const label = selected === undefined ? `case configuration ${file}` : `case "${selected.name}"`;
|
|
@@ -81,6 +84,98 @@ function buildCase(document, selected) {
|
|
|
81
84
|
origins,
|
|
82
85
|
};
|
|
83
86
|
}
|
|
87
|
+
function fieldType(key) {
|
|
88
|
+
return CASE_FIELDS[key];
|
|
89
|
+
}
|
|
90
|
+
function composeFieldValue(type, commonValue, caseValue) {
|
|
91
|
+
if (typeof type !== "string") {
|
|
92
|
+
if (!isPlainRecord(commonValue) || !isPlainRecord(caseValue)) {
|
|
93
|
+
return isPlainRecord(commonValue) ? caseValue : commonValue;
|
|
94
|
+
}
|
|
95
|
+
const merged = {};
|
|
96
|
+
for (const [entryKey, value] of Object.entries(commonValue)) {
|
|
97
|
+
defineOwn(merged, entryKey, value);
|
|
98
|
+
}
|
|
99
|
+
for (const [entryKey, caseEntry] of Object.entries(caseValue)) {
|
|
100
|
+
defineOwn(merged, entryKey, Object.hasOwn(merged, entryKey) ? composeFieldValue(type.child, merged[entryKey], caseEntry) : caseEntry);
|
|
101
|
+
}
|
|
102
|
+
return merged;
|
|
103
|
+
}
|
|
104
|
+
switch (type) {
|
|
105
|
+
case "value":
|
|
106
|
+
return caseValue;
|
|
107
|
+
case "list":
|
|
108
|
+
if (!Array.isArray(commonValue) || !Array.isArray(caseValue)) {
|
|
109
|
+
return Array.isArray(commonValue) ? caseValue : commonValue;
|
|
110
|
+
}
|
|
111
|
+
return [...commonValue, ...caseValue];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function extractFieldOrigin(type, field, base, text) {
|
|
115
|
+
if (typeof type !== "string") {
|
|
116
|
+
if (!isMap(field.node))
|
|
117
|
+
return base;
|
|
118
|
+
const entries = {};
|
|
119
|
+
for (const pair of field.node.items) {
|
|
120
|
+
if (!isScalar(pair.key) || typeof pair.key.value !== "string")
|
|
121
|
+
continue;
|
|
122
|
+
const entryBase = {
|
|
123
|
+
...base,
|
|
124
|
+
line: isNode(pair.key) ? lineAt(pair.key, text) : base.line,
|
|
125
|
+
};
|
|
126
|
+
defineOwn(entries, pair.key.value, extractFieldOrigin(type.child, { node: pair.value }, entryBase, text));
|
|
127
|
+
}
|
|
128
|
+
return { kind: "map", base, entries };
|
|
129
|
+
}
|
|
130
|
+
switch (type) {
|
|
131
|
+
case "value":
|
|
132
|
+
return base;
|
|
133
|
+
case "list": {
|
|
134
|
+
if (!isSeq(field.node))
|
|
135
|
+
return base;
|
|
136
|
+
const items = field.node.items.map((item) => ({
|
|
137
|
+
...base,
|
|
138
|
+
line: isNode(item) ? lineAt(item, text) : base.line,
|
|
139
|
+
}));
|
|
140
|
+
return { kind: "list", base, items };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function composeFieldOrigin(type, common, next) {
|
|
145
|
+
if (typeof type !== "string") {
|
|
146
|
+
if (common.kind === "map" && next.kind === "map") {
|
|
147
|
+
const entries = {};
|
|
148
|
+
for (const [entryKey, entryOrigin] of Object.entries(common.entries)) {
|
|
149
|
+
defineOwn(entries, entryKey, entryOrigin);
|
|
150
|
+
}
|
|
151
|
+
for (const [entryKey, entryOrigin] of Object.entries(next.entries)) {
|
|
152
|
+
defineOwn(entries, entryKey, Object.hasOwn(entries, entryKey)
|
|
153
|
+
? composeFieldOrigin(type.child, entries[entryKey], entryOrigin)
|
|
154
|
+
: entryOrigin);
|
|
155
|
+
}
|
|
156
|
+
return { kind: "map", base: common.base, entries };
|
|
157
|
+
}
|
|
158
|
+
return next;
|
|
159
|
+
}
|
|
160
|
+
switch (type) {
|
|
161
|
+
case "value":
|
|
162
|
+
if ((common.kind === "common" || common.kind === "case") && (next.kind === "common" || next.kind === "case")) {
|
|
163
|
+
return { ...next, overrides: common };
|
|
164
|
+
}
|
|
165
|
+
return next;
|
|
166
|
+
case "list":
|
|
167
|
+
if (common.kind === "list" && next.kind === "list") {
|
|
168
|
+
return { kind: "list", base: common.base, items: [...common.items, ...next.items] };
|
|
169
|
+
}
|
|
170
|
+
return next;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function defineOwn(target, key, value) {
|
|
174
|
+
Object.defineProperty(target, key, { value, enumerable: true, writable: true, configurable: true });
|
|
175
|
+
}
|
|
176
|
+
function isPlainRecord(value) {
|
|
177
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
178
|
+
}
|
|
84
179
|
/** Load a standalone implementation object using the same YAML and placeholder rules as cases. */
|
|
85
180
|
export async function loadImplementationParameters(path, schema, source) {
|
|
86
181
|
const { file, fields } = await readMapping(path);
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { writeSync } from "node:fs";
|
|
2
|
+
import { closeSync, openSync, writeSync } from "node:fs";
|
|
3
3
|
import { copyFile, lstat, mkdir, readdir, unlink } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { checkChildEnv } from "../platform/index.js";
|
|
5
6
|
const [stagingDir, program, ...args] = process.argv.slice(2);
|
|
7
|
+
const REPORT_PIPE = process.env.AGENT_EVALS_REPORT_PIPE;
|
|
6
8
|
let settled = false;
|
|
7
9
|
function report(outcome) {
|
|
8
10
|
if (settled)
|
|
9
11
|
return;
|
|
10
12
|
settled = true;
|
|
13
|
+
const line = JSON.stringify(outcome) + "\n";
|
|
11
14
|
try {
|
|
12
|
-
|
|
15
|
+
if (typeof REPORT_PIPE === "string" && REPORT_PIPE.length > 0) {
|
|
16
|
+
const fd = openSync(REPORT_PIPE, "w");
|
|
17
|
+
try {
|
|
18
|
+
writeSync(fd, line);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
closeSync(fd);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
writeSync(5, line);
|
|
26
|
+
}
|
|
13
27
|
}
|
|
14
28
|
catch {
|
|
15
29
|
// Host closed the report pipe (for example on timeout or cancellation).
|
|
@@ -110,8 +124,9 @@ async function main() {
|
|
|
110
124
|
try {
|
|
111
125
|
const child = spawn(program, args, {
|
|
112
126
|
cwd: process.cwd(),
|
|
113
|
-
env:
|
|
127
|
+
env: checkChildEnv(process.env),
|
|
114
128
|
stdio: ["ignore", "inherit", "inherit"],
|
|
129
|
+
windowsHide: true,
|
|
115
130
|
});
|
|
116
131
|
child.on("error", (error) => {
|
|
117
132
|
report({ kind: "failed", reason: `could not start ${program}: ${errorCode(error)}` });
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { delimiter, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { errorMessage } from "./config.js";
|
|
5
5
|
import { stageCheckFiles } from "./files.js";
|
|
6
6
|
import { siblingRuntimeModule } from "./runtime-assets.js";
|
|
7
|
-
import { SYSTEM_PATH } from "../platform/
|
|
8
|
-
import { spawnSupervised } from "../platform/macos/supervise.js";
|
|
7
|
+
import { dirEnv, SYSTEM_PATH, spawnSupervised } from "../platform/index.js";
|
|
9
8
|
/** How much of a program's combined output a check may keep as its reason. */
|
|
10
9
|
const MAX_OUTPUT_LENGTH = 4_096;
|
|
11
10
|
const CHECK_RUNNER = fileURLToPath(siblingRuntimeModule(import.meta.url, "check-runner"));
|
|
@@ -21,7 +20,7 @@ async function runProgram(options, command, files) {
|
|
|
21
20
|
if (program === undefined) {
|
|
22
21
|
return { kind: "failed", reason: "the check named no program", output: "" };
|
|
23
22
|
}
|
|
24
|
-
const path = process.env.PATH ?? SYSTEM_PATH.join(
|
|
23
|
+
const path = process.env.PATH ?? SYSTEM_PATH.join(delimiter);
|
|
25
24
|
const directory = await mkdtemp(join(options.engineDir, "check-"));
|
|
26
25
|
const homeDir = join(directory, "home");
|
|
27
26
|
const tmpDir = join(directory, "tmp");
|
|
@@ -51,14 +50,18 @@ async function runProgram(options, command, files) {
|
|
|
51
50
|
supervised = await spawnSupervised({
|
|
52
51
|
policy: {
|
|
53
52
|
writableRoots: [options.workspaceDir, homeDir, tmpDir],
|
|
54
|
-
readableRoots: [],
|
|
53
|
+
readableRoots: stagingDir === undefined ? [] : [stagingDir],
|
|
54
|
+
readableFiles: [process.execPath, CHECK_RUNNER],
|
|
55
55
|
readAll: true,
|
|
56
56
|
allowNetwork: false,
|
|
57
57
|
},
|
|
58
58
|
policyDirectory: directory,
|
|
59
59
|
command: [process.execPath, CHECK_RUNNER, stagingDir ?? "-", program, ...args],
|
|
60
60
|
cwd: options.workspaceDir,
|
|
61
|
-
env: {
|
|
61
|
+
env: {
|
|
62
|
+
PATH: path,
|
|
63
|
+
...dirEnv({ home: homeDir, tmp: tmpDir }),
|
|
64
|
+
},
|
|
62
65
|
interactive: false,
|
|
63
66
|
report: true,
|
|
64
67
|
});
|
package/dist/engine/config.d.ts
CHANGED
|
@@ -78,16 +78,39 @@ export type ShellMocks = Readonly<Record<string, ShellMock>>;
|
|
|
78
78
|
export interface MocksConfig {
|
|
79
79
|
readonly shell: ShellMocks;
|
|
80
80
|
}
|
|
81
|
-
/**
|
|
82
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Structural YAML type of a top-level case field, which determines how common and case declarations compose:
|
|
83
|
+
* - `"value"`: scalar or atomic object; a case replaces the common default as a whole.
|
|
84
|
+
* - `"list"`: sequence; a case appends its items after the common items.
|
|
85
|
+
* - `{ kind: "map", child }`: mapping; keys merge recursively using `child` (when `child` is `"value"`,
|
|
86
|
+
* a repeated key in the case replaces the common value).
|
|
87
|
+
*/
|
|
88
|
+
export type FieldType = "value" | "list" | {
|
|
89
|
+
readonly kind: "map";
|
|
90
|
+
readonly child: FieldType;
|
|
91
|
+
};
|
|
92
|
+
/** Where a single declaration originated in a YAML document, plus the declaration it overrode if any. */
|
|
93
|
+
export type SourceOrigin = {
|
|
83
94
|
readonly file: string;
|
|
84
95
|
readonly line: number;
|
|
85
96
|
readonly kind: "common";
|
|
97
|
+
readonly overrides?: SourceOrigin;
|
|
86
98
|
} | {
|
|
87
99
|
readonly file: string;
|
|
88
100
|
readonly line: number;
|
|
89
101
|
readonly kind: "case";
|
|
90
102
|
readonly caseName: string;
|
|
103
|
+
readonly overrides?: SourceOrigin;
|
|
104
|
+
};
|
|
105
|
+
/** Origin annotation mirroring `FieldType`: a leaf origin, list items, or recursive map entries. */
|
|
106
|
+
export type FieldOrigin = SourceOrigin | {
|
|
107
|
+
readonly kind: "list";
|
|
108
|
+
readonly base: SourceOrigin;
|
|
109
|
+
readonly items: readonly SourceOrigin[];
|
|
110
|
+
} | {
|
|
111
|
+
readonly kind: "map";
|
|
112
|
+
readonly base: SourceOrigin;
|
|
113
|
+
readonly entries: Readonly<Record<string, FieldOrigin>>;
|
|
91
114
|
};
|
|
92
115
|
/** Basic environment-variable name grammar used by placeholders and declared variables. */
|
|
93
116
|
export declare const ENV_NAME_PATTERN: RegExp;
|
|
@@ -101,6 +124,12 @@ export interface ResolvedCase {
|
|
|
101
124
|
/** One annotation per final top-level field in `config`. */
|
|
102
125
|
readonly origins: Readonly<Record<string, FieldOrigin>>;
|
|
103
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Single source of truth for case fields and their structural types.
|
|
129
|
+
* Naming convention: plural names (`files`, `checks`, `mocks`) are collections (`list` / `map`);
|
|
130
|
+
* singular names (`input`, `runner`, `fixture`, `timeoutMs`, `expect`) are atomic `value`s.
|
|
131
|
+
*/
|
|
132
|
+
export declare const CASE_FIELDS: Readonly<Record<keyof CaseConfig, FieldType>>;
|
|
104
133
|
/** Top-level fields allowed in a complete resolved case. */
|
|
105
134
|
export declare const CASE_FIELD_KEYS: ReadonlySet<string>;
|
|
106
135
|
/** The document-level authoring control for named cases. */
|