gaunt-sloth 2.3.1 → 2.4.1
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/commands/batchCommand.js +4 -1
- package/dist/commands/batchCommand.js.map +1 -1
- package/dist/commands/commandEvalRunner.d.ts +114 -0
- package/dist/commands/commandEvalRunner.js +732 -0
- package/dist/commands/commandEvalRunner.js.map +1 -0
- package/dist/commands/commandWorkspace.d.ts +68 -0
- package/dist/commands/commandWorkspace.js +235 -0
- package/dist/commands/commandWorkspace.js.map +1 -0
- package/dist/commands/commandWorkspaceChecks.d.ts +47 -0
- package/dist/commands/commandWorkspaceChecks.js +187 -0
- package/dist/commands/commandWorkspaceChecks.js.map +1 -0
- package/dist/commands/evalCommand.d.ts +8 -0
- package/dist/commands/evalCommand.js +212 -13
- package/dist/commands/evalCommand.js.map +1 -1
- package/dist/commands/execCommand.js +16 -2
- package/dist/commands/execCommand.js.map +1 -1
- package/dist/commands/requirementsDiscovery.d.ts +1 -1
- package/dist/tui/debugRender.d.ts +10 -7
- package/dist/tui/debugRender.js +11 -10
- package/dist/tui/debugRender.js.map +1 -1
- package/dist/tui/tuiSessionModule.js +2 -2
- package/dist/tui/tuiSessionModule.js.map +1 -1
- package/package.json +18 -18
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BATCH-57 — the `command` target's production runner for `gth eval`: start a command-line agent
|
|
3
|
+
* once per case, decode what it printed, and hand the eval runner the same outcome shape the
|
|
4
|
+
* `gth-agent` target produces. The analogue of `agUiEvalRunner.ts` (HTTP/SSE) and
|
|
5
|
+
* `adkEvalRunner.ts` (A2A) for an agent that is a program.
|
|
6
|
+
*
|
|
7
|
+
* ## The prompt never passes through a shell
|
|
8
|
+
*
|
|
9
|
+
* The suite parser has already split `run` into argv (`commandArgv.ts`). The process is started
|
|
10
|
+
* with `shell: false`, and the prompt is either appended as ONE more argv element (`prompt: arg`,
|
|
11
|
+
* the default) or written to the child's stdin (`prompt: stdin`). No program between gth and the
|
|
12
|
+
* agent parses the prompt, so `$(…)`, backticks and quotes in it reach the agent byte for byte and
|
|
13
|
+
* execute nothing. A spec proves this with a prompt built to do damage if it were ever spliced.
|
|
14
|
+
*
|
|
15
|
+
* The cost is on Windows: Node refuses to start a `.cmd`/`.bat` file without a shell, and an
|
|
16
|
+
* npm-installed CLI is a `.cmd` shim there. A suite on Windows names the real executable instead
|
|
17
|
+
* (`node path/to/cli.js …`). That limit is accepted rather than worked around, because the
|
|
18
|
+
* work-around is `cmd.exe /c`, which re-parses its whole command line, the prompt included.
|
|
19
|
+
*
|
|
20
|
+
* ## Timeout
|
|
21
|
+
*
|
|
22
|
+
* Each case has its own budget (`EvalCase.timeoutMs`, resolved at parse). On expiry the whole
|
|
23
|
+
* process TREE is killed — an agent CLI starts its tools as children, and killing only the CLI
|
|
24
|
+
* would leave them running and holding the output pipes open — through the same
|
|
25
|
+
* `killProcessGroup` the shell tool uses (negative pid on POSIX, `taskkill /T` on Windows), with
|
|
26
|
+
* the same SIGTERM-then-SIGKILL escalation. The case then settles WITHOUT waiting for `'close'`:
|
|
27
|
+
* on Windows a surviving grandchild can keep the pipes open and `'close'` never fires, which is the
|
|
28
|
+
* EXT-15 hang. A timed-out case is a harness error (`ok: false`), never a FAIL.
|
|
29
|
+
*
|
|
30
|
+
* ## Harness errors
|
|
31
|
+
*
|
|
32
|
+
* A run that times out, cannot be started, exits non-zero, or prints a transcript the decoder
|
|
33
|
+
* rejects (cut off, or an error result such as Claude Code's `error_max_turns`) is `ok: false`: the
|
|
34
|
+
* case is reported as `SUT run failed` with the reason, and a suite in which every case failed that
|
|
35
|
+
* way exits 2. Grading a run that did not finish would turn the harness's limit into an assertion
|
|
36
|
+
* failure that reads as the agent's choice.
|
|
37
|
+
*
|
|
38
|
+
* BATCH-62 — the one opt-out is `grade_when`: a run whose decoder reports an early ending the case
|
|
39
|
+
* lists (a `--max-turns` cap, say) is graded on the transcript it produced, whatever the exit code,
|
|
40
|
+
* and carries that `outcome` into its result. A decoder throw, a timeout and a signal kill are never
|
|
41
|
+
* graded. See `gradedEnding`.
|
|
42
|
+
*
|
|
43
|
+
* ## Workspaces (BATCH-58)
|
|
44
|
+
*
|
|
45
|
+
* {@link CommandSpawnRequest} carries `cwd` and `env` per call. A case with no `workspace` runs in
|
|
46
|
+
* the directory gth was started in, with gth's own environment object, exactly as before. A case
|
|
47
|
+
* with one gets, per run: a fresh directory (`commandWorkspace.ts`), its `setup` steps started in
|
|
48
|
+
* order through the same spawn seam as the command (no shell, the case's timeout per step, the
|
|
49
|
+
* same tree kill and exit hook), then the command, then the case's BATCH-59 workspace assertions
|
|
50
|
+
* (`file_contains`, `must_not_exist`, then the `after` steps; see `gradeWorkspace` below), then the
|
|
51
|
+
* test seam {@link CommandRunnerOptions.inspectWorkspace}, and the directory is removed last. The
|
|
52
|
+
* assertions are built in rather than passed through that option, so no caller can build a runner
|
|
53
|
+
* that silently skips them. A step that
|
|
54
|
+
* cannot start, exits non-zero or times out is a harness error naming the step, and the command
|
|
55
|
+
* does not run: grading an agent in a half-built fixture would charge the fixture's failure to the
|
|
56
|
+
* agent.
|
|
57
|
+
*
|
|
58
|
+
* @module
|
|
59
|
+
*/
|
|
60
|
+
import { spawn } from 'node:child_process';
|
|
61
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
62
|
+
import { join, resolve } from 'node:path';
|
|
63
|
+
import { fileURLToPath } from 'node:url';
|
|
64
|
+
import { isTranscriptDecoderModulePath, resolveTranscriptDecoder, } from '@gaunt-sloth/batch/transcripts/registry.js';
|
|
65
|
+
import { COMMAND_TARGET_DEFAULT_TIMEOUT_MS } from '@gaunt-sloth/batch/evalTypes.js';
|
|
66
|
+
import { killProcessGroup } from '@gaunt-sloth/agent/tools/GthDevToolkit.js';
|
|
67
|
+
import { capToolResultText, TOOL_RESULT_CONTENT_CAP } from '@gaunt-sloth/core/core/runStats.js';
|
|
68
|
+
import { importExternalFile } from '@gaunt-sloth/core/utils/fileUtils.js';
|
|
69
|
+
import { env, getCurrentWorkDir } from '@gaunt-sloth/core/utils/systemUtils.js';
|
|
70
|
+
import { evalToolCallRecords } from '#src/commands/evalToolCallRecords.js';
|
|
71
|
+
import { buildWorkspaceEnv, createWorkspaceDir, expandSetupArgv, removeWorkspaceDir, resolveSuiteDir, resolveWorkspaceCwd, } from '#src/commands/commandWorkspace.js';
|
|
72
|
+
import { checkFileContains, checkMustNotExist, WorkspaceUnreadableError, } from '#src/commands/commandWorkspaceChecks.js';
|
|
73
|
+
/** How long a SIGTERM'd tree gets before SIGKILL, matching the shell tool's ladder. */
|
|
74
|
+
const KILL_GRACE_MS = 3_000;
|
|
75
|
+
/** How long after SIGKILL the case waits for `'close'` before settling without it. */
|
|
76
|
+
const SETTLE_AFTER_KILL_MS = 1_000;
|
|
77
|
+
/** How much of stderr a harness-error reason quotes. */
|
|
78
|
+
const STDERR_TAIL_CHARS = 600;
|
|
79
|
+
/**
|
|
80
|
+
* The commands this process has started and not yet settled.
|
|
81
|
+
*
|
|
82
|
+
* ## Why gth's exit kills them
|
|
83
|
+
*
|
|
84
|
+
* On POSIX each command leads its own process group (that is what lets the timeout kill the whole
|
|
85
|
+
* tree), so the terminal's Ctrl+C, which signals only the FOREGROUND group, never reaches it. Core's
|
|
86
|
+
* SIGINT and SIGTERM handlers (`systemUtils.ts`) end in `process.exit(0)`, and the per-case timeout
|
|
87
|
+
* timers die with gth. Without this hook an interrupted `gth eval` would leave the agent CLI running
|
|
88
|
+
* with no deadline at all, still editing the directory and still spending tokens.
|
|
89
|
+
*
|
|
90
|
+
* So the first spawn installs ONE `'exit'` listener, and nothing else. `'exit'` runs on every way
|
|
91
|
+
* the process ends that can run code — core's signal handlers calling `process.exit`, an explicit
|
|
92
|
+
* exit, an uncaught exception, a normal end — so this catches Ctrl+C without adding a second
|
|
93
|
+
* SIGINT handler or changing what core's does, and a command that never starts a `command` target
|
|
94
|
+
* never gets the listener. An `'exit'` listener must be synchronous, and `killProcessGroup` is
|
|
95
|
+
* (`process.kill` on POSIX, `spawnSync('taskkill')` on Windows). It sends SIGKILL, because nothing
|
|
96
|
+
* survives gth to escalate a SIGTERM that the agent chose to ignore.
|
|
97
|
+
*
|
|
98
|
+
* A child leaves the set when its run settles, not when it exits: a timed-out run whose grandchild
|
|
99
|
+
* outlived the kill is still worth a last attempt.
|
|
100
|
+
*
|
|
101
|
+
* Limits: a SIGKILL of gth itself runs no code, so it cannot reach the children. On Windows, a child
|
|
102
|
+
* spawned without `detached` shares gth's console, so a console Ctrl+C reaches it directly; an
|
|
103
|
+
* external `TerminateProcess` of gth runs no code there either.
|
|
104
|
+
*
|
|
105
|
+
* BATCH-58 — the same listener removes every live case workspace, AFTER the kills: on Windows a
|
|
106
|
+
* directory is busy while a process still has it as its cwd. `removeWorkspaceDir` is synchronous
|
|
107
|
+
* and retries a busy directory, which is what an `'exit'` listener can afford. A removal that still
|
|
108
|
+
* fails is left behind silently, because there is no run left to report it to. A workspace kept
|
|
109
|
+
* with `--keep-workspaces` is never registered here, so an interrupt keeps it too.
|
|
110
|
+
*/
|
|
111
|
+
const liveChildren = new Set();
|
|
112
|
+
const liveWorkspaces = new Set();
|
|
113
|
+
let exitHookInstalled = false;
|
|
114
|
+
/**
|
|
115
|
+
* Kill every live command's process tree, then remove every live case workspace. The `'exit'`
|
|
116
|
+
* listener; exported for its spec.
|
|
117
|
+
*/
|
|
118
|
+
export function killLiveCommandChildren() {
|
|
119
|
+
for (const child of liveChildren)
|
|
120
|
+
killProcessGroup(child, 'SIGKILL');
|
|
121
|
+
liveChildren.clear();
|
|
122
|
+
for (const dir of liveWorkspaces) {
|
|
123
|
+
try {
|
|
124
|
+
removeWorkspaceDir(dir);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Nothing is left to report to; see the docblock above.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
liveWorkspaces.clear();
|
|
131
|
+
}
|
|
132
|
+
function installExitHook() {
|
|
133
|
+
if (!exitHookInstalled) {
|
|
134
|
+
exitHookInstalled = true;
|
|
135
|
+
process.on('exit', killLiveCommandChildren);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function trackLiveChild(child) {
|
|
139
|
+
liveChildren.add(child);
|
|
140
|
+
installExitHook();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Start the command once and collect its output. Rejects only when the process cannot be started
|
|
144
|
+
* (an unknown command, for one); every other outcome resolves, timed out or not.
|
|
145
|
+
*/
|
|
146
|
+
export function runCommandProcess(request) {
|
|
147
|
+
const [command, ...baseArgs] = request.argv;
|
|
148
|
+
const viaArg = request.promptDelivery === 'arg';
|
|
149
|
+
const viaStdin = request.promptDelivery === 'stdin';
|
|
150
|
+
const args = viaArg ? [...baseArgs, request.prompt] : baseArgs;
|
|
151
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
152
|
+
const child = spawn(command, args, {
|
|
153
|
+
shell: false,
|
|
154
|
+
cwd: request.cwd,
|
|
155
|
+
env: request.env,
|
|
156
|
+
// Unless the prompt goes on stdin, stdin is closed: a `-p` CLI that finds an open pipe may
|
|
157
|
+
// wait on it forever.
|
|
158
|
+
stdio: [viaStdin ? 'pipe' : 'ignore', 'pipe', 'pipe'],
|
|
159
|
+
// POSIX: lead a process group so the timeout can signal the whole tree. Windows has no
|
|
160
|
+
// groups; `killProcessGroup` uses `taskkill /T` there instead.
|
|
161
|
+
detached: process.platform !== 'win32',
|
|
162
|
+
windowsHide: true,
|
|
163
|
+
});
|
|
164
|
+
trackLiveChild(child);
|
|
165
|
+
const stdout = [];
|
|
166
|
+
const stderr = [];
|
|
167
|
+
let timedOut = false;
|
|
168
|
+
let settled = false;
|
|
169
|
+
const timers = [];
|
|
170
|
+
const finish = (exitCode) => {
|
|
171
|
+
if (settled)
|
|
172
|
+
return;
|
|
173
|
+
settled = true;
|
|
174
|
+
liveChildren.delete(child);
|
|
175
|
+
for (const timer of timers)
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
resolvePromise({
|
|
178
|
+
stdout: Buffer.concat(stdout).toString('utf8'),
|
|
179
|
+
stderr: Buffer.concat(stderr).toString('utf8'),
|
|
180
|
+
exitCode,
|
|
181
|
+
timedOut,
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
child.stdout?.on('data', (chunk) => stdout.push(chunk));
|
|
185
|
+
child.stderr?.on('data', (chunk) => stderr.push(chunk));
|
|
186
|
+
child.on('error', (error) => {
|
|
187
|
+
if (settled)
|
|
188
|
+
return;
|
|
189
|
+
settled = true;
|
|
190
|
+
liveChildren.delete(child);
|
|
191
|
+
for (const timer of timers)
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
rejectPromise(new Error(`could not start "${command}": ${error.message}`));
|
|
194
|
+
});
|
|
195
|
+
child.on('close', (code) => finish(code));
|
|
196
|
+
if (viaStdin && child.stdin) {
|
|
197
|
+
// A child that exits without reading its stdin makes the write fail with EPIPE; that is the
|
|
198
|
+
// child's business, and its exit status says what happened.
|
|
199
|
+
child.stdin.on('error', () => undefined);
|
|
200
|
+
child.stdin.end(request.prompt, 'utf8');
|
|
201
|
+
}
|
|
202
|
+
timers.push(setTimeout(() => {
|
|
203
|
+
timedOut = true;
|
|
204
|
+
killProcessGroup(child, 'SIGTERM');
|
|
205
|
+
timers.push(setTimeout(() => {
|
|
206
|
+
killProcessGroup(child, 'SIGKILL');
|
|
207
|
+
// Settle even if 'close' never comes: a grandchild that outlived the kill can hold the
|
|
208
|
+
// pipes open, and waiting on them is the hang the timeout exists to prevent.
|
|
209
|
+
timers.push(setTimeout(() => {
|
|
210
|
+
child.stdout?.destroy();
|
|
211
|
+
child.stderr?.destroy();
|
|
212
|
+
finish(null);
|
|
213
|
+
}, SETTLE_AFTER_KILL_MS));
|
|
214
|
+
}, KILL_GRACE_MS));
|
|
215
|
+
}, request.timeoutMs));
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Resolve a target's `transcript` to a decoder: a built-in by name, or the default export of a
|
|
220
|
+
* module, resolved against the directory of the suite file that names it (the decoder belongs to
|
|
221
|
+
* the suite, so a relative path reads the way the suite author sees it).
|
|
222
|
+
*/
|
|
223
|
+
export async function loadTranscriptDecoder(spec, suiteReadPath) {
|
|
224
|
+
if (!isTranscriptDecoderModulePath(spec))
|
|
225
|
+
return resolveTranscriptDecoder(spec);
|
|
226
|
+
const modulePath = spec.startsWith('file:')
|
|
227
|
+
? fileURLToPath(spec)
|
|
228
|
+
: resolve(resolveSuiteDir(suiteReadPath), spec);
|
|
229
|
+
let mod;
|
|
230
|
+
try {
|
|
231
|
+
mod = await importExternalFile(modulePath);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
throw new Error(`failed to load transcript decoder "${spec}": ` +
|
|
235
|
+
(error instanceof Error ? error.message : String(error)));
|
|
236
|
+
}
|
|
237
|
+
if (typeof mod.default !== 'function') {
|
|
238
|
+
throw new Error(`transcript decoder "${spec}" must export a default function (stdout) => transcript; got ` +
|
|
239
|
+
`${typeof mod.default}.`);
|
|
240
|
+
}
|
|
241
|
+
return mod.default;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* BATCH-66 — the file name, without extension, of one run's kept transcript: `<id>` for a case that
|
|
245
|
+
* runs once, `<id>#run<n>` for each run of a repeated case.
|
|
246
|
+
*
|
|
247
|
+
* The run suffix is BATCH-60's own name for a run cell, and it is used rather than a `-run-<n>`
|
|
248
|
+
* suffix because `#` is outside the case-id alphabet (`/^[\w.-]+$/`, checked at parse): case `a`
|
|
249
|
+
* run 1 and a separate case `a-run-1` could otherwise share a file and overwrite each other. That
|
|
250
|
+
* same parse-time check is what keeps an id from naming a path outside the output directory, so the
|
|
251
|
+
* id needs no further sanitising here. A `command` target rejects `identities` and `sweep` at parse,
|
|
252
|
+
* so a run has no identity or sweep cell to add to the name.
|
|
253
|
+
*/
|
|
254
|
+
export function transcriptFileBase(cell) {
|
|
255
|
+
return cell.run !== undefined ? `${cell.id}#run${cell.run}` : cell.id;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* BATCH-66 — write one run's raw output into `outputDir`, beside the case's `<id>.json`:
|
|
259
|
+
* `<base>.stdout.txt` always, and `<base>.stderr.txt` only when the command printed to standard
|
|
260
|
+
* error. Both are written exactly as captured, with no header, so a kept stdout can be fed straight
|
|
261
|
+
* back to a decoder. {@link runCommandProcess} keeps all of both streams, so nothing in either file
|
|
262
|
+
* was cut; the 600-character stderr tail is only what a harness-error reason quotes.
|
|
263
|
+
*/
|
|
264
|
+
export function writeCommandTranscript(outputDir, cell, run) {
|
|
265
|
+
const base = transcriptFileBase(cell);
|
|
266
|
+
mkdirSync(outputDir, { recursive: true });
|
|
267
|
+
writeFileSync(join(outputDir, `${base}.stdout.txt`), run.stdout);
|
|
268
|
+
const stderrFile = join(outputDir, `${base}.stderr.txt`);
|
|
269
|
+
// A run with nothing on stderr removes the file a previous run into the same `-o` left under
|
|
270
|
+
// this name. Left in place it would sit beside this run's stdout and read as this run's.
|
|
271
|
+
if (run.stderr.length > 0)
|
|
272
|
+
writeFileSync(stderrFile, run.stderr);
|
|
273
|
+
else
|
|
274
|
+
rmSync(stderrFile, { force: true });
|
|
275
|
+
}
|
|
276
|
+
function tail(text) {
|
|
277
|
+
const trimmed = text.trim();
|
|
278
|
+
if (!trimmed)
|
|
279
|
+
return '';
|
|
280
|
+
return trimmed.length > STDERR_TAIL_CHARS ? `…${trimmed.slice(-STDERR_TAIL_CHARS)}` : trimmed;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* BATCH-65 — a value a custom decoder returned, as text for a harness-error reason. It must never
|
|
284
|
+
* throw: the reason is what names the decoder, and a throw here would replace it with the
|
|
285
|
+
* formatter's own message (`Do not know how to serialize a BigInt`). `JSON.stringify` throws on a
|
|
286
|
+
* BigInt and on a circular object, so a BigInt is written with its `n` suffix, and anything
|
|
287
|
+
* `JSON.stringify` cannot write falls back to `String`, then to the value's type.
|
|
288
|
+
*/
|
|
289
|
+
function describeDecodedValue(value) {
|
|
290
|
+
if (typeof value === 'number')
|
|
291
|
+
return String(value);
|
|
292
|
+
if (typeof value === 'bigint')
|
|
293
|
+
return `${value}n`;
|
|
294
|
+
try {
|
|
295
|
+
return JSON.stringify(value) ?? String(value);
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
try {
|
|
299
|
+
return String(value);
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return `a value of type ${typeof value}`;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Shape a decoded transcript the way the gth-agent target shapes its run stats: `tools` is the
|
|
308
|
+
* de-duplicated names of every requested and executed tool in first-seen order (core's set), and
|
|
309
|
+
* every payload and argument string is capped with core's own {@link capToolResultText}.
|
|
310
|
+
*/
|
|
311
|
+
function shapeOutcome(decoded, captureMaxBytes, recordToolCallArgs) {
|
|
312
|
+
const tools = [
|
|
313
|
+
...new Set([
|
|
314
|
+
...decoded.toolCalls.map((call) => call.name),
|
|
315
|
+
...decoded.toolResults.map((result) => result.name),
|
|
316
|
+
]),
|
|
317
|
+
];
|
|
318
|
+
const calls = decoded.toolCalls.map((call) => {
|
|
319
|
+
const capped = capToolResultText(call.args, captureMaxBytes);
|
|
320
|
+
return {
|
|
321
|
+
name: call.name,
|
|
322
|
+
...(call.id ? { id: call.id } : {}),
|
|
323
|
+
args: capped.text,
|
|
324
|
+
...(capped.truncated ? { argsTruncated: true, argsOriginalBytes: capped.originalBytes } : {}),
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
const toolResults = decoded.toolResults.map((result) => {
|
|
328
|
+
const capped = result.content !== undefined ? capToolResultText(result.content, captureMaxBytes) : undefined;
|
|
329
|
+
return {
|
|
330
|
+
name: result.name,
|
|
331
|
+
isError: result.isError,
|
|
332
|
+
...(capped !== undefined ? { content: capped.text } : {}),
|
|
333
|
+
...(capped?.truncated
|
|
334
|
+
? { contentTruncated: true, contentOriginalBytes: capped.originalBytes }
|
|
335
|
+
: {}),
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
return { tools, toolCalls: evalToolCallRecords(calls, recordToolCallArgs), toolResults };
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Build the `RunCellFn` for a command target. The cell id is the case id — a command suite has no
|
|
342
|
+
* identity matrix — so each run takes its case's own timeout.
|
|
343
|
+
*/
|
|
344
|
+
export function buildCommandRunCell(target, suite, decoder, options = {}) {
|
|
345
|
+
const timeouts = new Map(suite.cases.map((evalCase) => [evalCase.id, evalCase.timeoutMs]));
|
|
346
|
+
const spawnCommand = options.spawnCommand ?? runCommandProcess;
|
|
347
|
+
const captureMaxBytes = options.captureMaxBytes ?? TOOL_RESULT_CONTENT_CAP;
|
|
348
|
+
const workspaces = new Map(suite.cases.flatMap((evalCase) => evalCase.workspace !== undefined ? [[evalCase.id, evalCase.workspace]] : []));
|
|
349
|
+
const checks = new Map(suite.cases.flatMap((evalCase) => evalCase.workspaceChecks !== undefined
|
|
350
|
+
? [[evalCase.id, evalCase.workspaceChecks]]
|
|
351
|
+
: []));
|
|
352
|
+
const gradeWhen = new Map(suite.cases.flatMap((evalCase) => evalCase.gradeWhen !== undefined ? [[evalCase.id, new Set(evalCase.gradeWhen)]] : []));
|
|
353
|
+
/**
|
|
354
|
+
* BATCH-62 — is a run that ended on `outcome` (not `success`) graded instead of being a harness
|
|
355
|
+
* error? Only when BOTH hold:
|
|
356
|
+
*
|
|
357
|
+
* - **The case's effective `grade_when` lists it.** Resolved at parse: the case's list, else the
|
|
358
|
+
* target's, and a case's `[]` leaves nothing listed. An unlisted outcome stays a harness error,
|
|
359
|
+
* because harness error is the right default: a run that did not finish is not evidence unless
|
|
360
|
+
* the suite author says it is.
|
|
361
|
+
* - **The process exited with a code.** A run killed by a signal (`exitCode: null`) is never
|
|
362
|
+
* graded, even when what it printed before dying happens to end on a listed result: the process
|
|
363
|
+
* did not end the run, something outside it did. A timed-out run never gets here at all.
|
|
364
|
+
*
|
|
365
|
+
* The exit code's VALUE is deliberately not consulted. Claude Code exits 1 on `error_max_turns`,
|
|
366
|
+
* so requiring 0 would make the key useless for the case it exists for, and the transcript's own
|
|
367
|
+
* result line is the more specific statement of how the run ended. A `success` transcript with a
|
|
368
|
+
* non-zero exit is not an outcome and never reaches here: it stays a harness error, as before.
|
|
369
|
+
*
|
|
370
|
+
* A decoder THROW is never graded either, whatever the list says (it never reaches here): output
|
|
371
|
+
* without a terminal result is not a run that ended on anything.
|
|
372
|
+
*/
|
|
373
|
+
function gradedEnding(outcome, caseId, exitCode) {
|
|
374
|
+
if (exitCode === null)
|
|
375
|
+
return false;
|
|
376
|
+
return gradeWhen.get(caseId)?.has(outcome) === true;
|
|
377
|
+
}
|
|
378
|
+
const runAndDecode = async (cell, timeoutMs, cwd, childEnv) => {
|
|
379
|
+
let run;
|
|
380
|
+
try {
|
|
381
|
+
run = await spawnCommand({
|
|
382
|
+
argv: target.argv,
|
|
383
|
+
prompt: cell.content,
|
|
384
|
+
promptDelivery: target.prompt,
|
|
385
|
+
timeoutMs,
|
|
386
|
+
cwd,
|
|
387
|
+
env: childEnv,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
392
|
+
}
|
|
393
|
+
// Before any branch below can return: every way a finished run is judged keeps its transcript.
|
|
394
|
+
options.onTranscript?.(cell, run);
|
|
395
|
+
const stderrTail = tail(run.stderr);
|
|
396
|
+
const withStderr = (reason) => stderrTail ? `${reason}; stderr: ${stderrTail}` : reason;
|
|
397
|
+
if (run.timedOut) {
|
|
398
|
+
return {
|
|
399
|
+
ok: false,
|
|
400
|
+
error: withStderr(`the command did not finish within its ${timeoutMs}ms timeout and its process tree was ` +
|
|
401
|
+
'killed'),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
let decoded;
|
|
405
|
+
let decodeError;
|
|
406
|
+
try {
|
|
407
|
+
decoded = decoder(run.stdout);
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
decodeError = error instanceof Error ? error.message : String(error);
|
|
411
|
+
}
|
|
412
|
+
// BATCH-62 — `outcome` is part of the public decoder contract, so a custom decoder's value is
|
|
413
|
+
// checked before it can decide anything: it must be a non-empty string. Anything else is a
|
|
414
|
+
// harness error naming the decoder, whatever `grade_when` lists and whatever the exit code,
|
|
415
|
+
// because a malformed outcome cannot be matched against the list honestly; treating it as
|
|
416
|
+
// `success` would grade a run the decoder was trying to say did not finish.
|
|
417
|
+
if (decoded !== undefined && 'outcome' in decoded && decoded.outcome !== undefined) {
|
|
418
|
+
const value = decoded.outcome;
|
|
419
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
420
|
+
return {
|
|
421
|
+
ok: false,
|
|
422
|
+
error: withStderr(`transcript "${target.transcript}" returned an invalid outcome ` +
|
|
423
|
+
`${describeDecodedValue(value)}: it must be a non-empty string naming ` +
|
|
424
|
+
'how the run ended, or left out for a run that finished'),
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// BATCH-65 — `costUsd` is part of the same public contract, and is checked the same way: a value
|
|
429
|
+
// that is set must be a finite, non-negative number of US dollars. Anything else is a harness
|
|
430
|
+
// error naming the decoder. Dropping it would make the printed total silently cover fewer cases
|
|
431
|
+
// than the decoder's author expects; keeping it would put NaN, Infinity or a negative into a sum.
|
|
432
|
+
if (decoded !== undefined && 'costUsd' in decoded && decoded.costUsd !== undefined) {
|
|
433
|
+
const value = decoded.costUsd;
|
|
434
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
435
|
+
return {
|
|
436
|
+
ok: false,
|
|
437
|
+
error: withStderr(`transcript "${target.transcript}" returned an invalid costUsd ` +
|
|
438
|
+
`${describeDecodedValue(value)}: it must be a finite, non-negative ` +
|
|
439
|
+
'number of US dollars, or left out when the agent reports no cost'),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// Carried on both graded paths below, including a run graded under `grade_when`: a capped run
|
|
444
|
+
// still spent money, and leaving it out would understate the total.
|
|
445
|
+
const cost = decoded?.costUsd !== undefined ? { costUsd: decoded.costUsd } : {};
|
|
446
|
+
// BATCH-62 — a run that reached a terminal result but did not end in `success`. See
|
|
447
|
+
// `gradedEnding` for when it is graded; otherwise it is the harness error the decoder used to
|
|
448
|
+
// throw, with the decoder's own sentence as the reason, so a suite without `grade_when` reports
|
|
449
|
+
// exactly what it did before the key existed.
|
|
450
|
+
const outcome = decoded?.outcome !== undefined && decoded.outcome !== 'success' ? decoded.outcome : undefined;
|
|
451
|
+
if (decoded !== undefined && outcome !== undefined) {
|
|
452
|
+
if (gradedEnding(outcome, cell.id, run.exitCode)) {
|
|
453
|
+
return {
|
|
454
|
+
ok: true,
|
|
455
|
+
outcome,
|
|
456
|
+
answer: decoded.answer,
|
|
457
|
+
...(decoded.tokensInput !== undefined ? { tokensInput: decoded.tokensInput } : {}),
|
|
458
|
+
...(decoded.tokensOutput !== undefined ? { tokensOutput: decoded.tokensOutput } : {}),
|
|
459
|
+
...cost,
|
|
460
|
+
...shapeOutcome(decoded, captureMaxBytes, options.recordToolCallArgs === true),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
const reason = decoded.outcomeReason;
|
|
464
|
+
decodeError =
|
|
465
|
+
typeof reason === 'string' && reason.trim() !== ''
|
|
466
|
+
? reason
|
|
467
|
+
: `the run ended with outcome "${outcome}"`;
|
|
468
|
+
decoded = undefined;
|
|
469
|
+
}
|
|
470
|
+
if (run.exitCode !== 0) {
|
|
471
|
+
const decoderSays = decodeError ? `; transcript "${target.transcript}": ${decodeError}` : '';
|
|
472
|
+
return {
|
|
473
|
+
ok: false,
|
|
474
|
+
error: withStderr(`the command exited with code ${run.exitCode}${decoderSays}`),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (decoded === undefined) {
|
|
478
|
+
return {
|
|
479
|
+
ok: false,
|
|
480
|
+
error: withStderr(`transcript "${target.transcript}" could not be decoded: ${decodeError}`),
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
ok: true,
|
|
485
|
+
answer: decoded.answer,
|
|
486
|
+
...(decoded.tokensInput !== undefined ? { tokensInput: decoded.tokensInput } : {}),
|
|
487
|
+
...(decoded.tokensOutput !== undefined ? { tokensOutput: decoded.tokensOutput } : {}),
|
|
488
|
+
...cost,
|
|
489
|
+
...shapeOutcome(decoded, captureMaxBytes, options.recordToolCallArgs === true),
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
return async (cell) => {
|
|
493
|
+
const timeoutMs = timeouts.get(cell.id) ?? COMMAND_TARGET_DEFAULT_TIMEOUT_MS;
|
|
494
|
+
const baseEnv = options.env ?? env;
|
|
495
|
+
const spec = workspaces.get(cell.id);
|
|
496
|
+
// No workspace: the directory gth was started in and gth's own environment object, unchanged.
|
|
497
|
+
if (spec === undefined) {
|
|
498
|
+
return runAndDecode(cell, timeoutMs, options.cwd ?? getCurrentWorkDir(), baseEnv);
|
|
499
|
+
}
|
|
500
|
+
let dir;
|
|
501
|
+
try {
|
|
502
|
+
dir = createWorkspaceDir(cell.id, spec);
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
return {
|
|
506
|
+
ok: false,
|
|
507
|
+
error: `the workspace could not be prepared: ${error instanceof Error ? error.message : String(error)}`,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
const keep = options.keepWorkspaces === true;
|
|
511
|
+
if (keep) {
|
|
512
|
+
// Reported as the case starts, not when it ends: a case that hangs and is interrupted never
|
|
513
|
+
// reaches `finally`, and that is the run whose workspace is most worth looking at.
|
|
514
|
+
options.onWorkspaceKept?.(cell.id, dir);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
liveWorkspaces.add(dir);
|
|
518
|
+
installExitHook();
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const childEnv = buildWorkspaceEnv(spec, dir, baseEnv);
|
|
522
|
+
const setupError = await runWorkspaceSetup(spec, dir, baseEnv, childEnv, timeoutMs);
|
|
523
|
+
if (setupError !== undefined)
|
|
524
|
+
return { ok: false, error: setupError };
|
|
525
|
+
// BATCH-63 — only the command starts in the workspace's `cwd`; setup ran, and the `after`
|
|
526
|
+
// steps and file checks below run, in `dir`. A `cwd` that is missing or leads outside the
|
|
527
|
+
// workspace is a harness error: the agent never ran, so there is nothing to grade.
|
|
528
|
+
let commandDir;
|
|
529
|
+
try {
|
|
530
|
+
commandDir = resolveWorkspaceCwd(dir, spec.cwd);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
return {
|
|
534
|
+
ok: false,
|
|
535
|
+
error: `${error instanceof Error ? error.message : String(error)}; the case's command was not started`,
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const ran = await runAndDecode(cell, timeoutMs, commandDir, childEnv);
|
|
539
|
+
const outcome = await gradeWorkspace(checks.get(cell.id), spec, dir, baseEnv, childEnv, timeoutMs, ran);
|
|
540
|
+
return options.inspectWorkspace
|
|
541
|
+
? await options.inspectWorkspace({ caseId: cell.id, dir }, outcome)
|
|
542
|
+
: outcome;
|
|
543
|
+
}
|
|
544
|
+
finally {
|
|
545
|
+
if (!keep) {
|
|
546
|
+
liveWorkspaces.delete(dir);
|
|
547
|
+
try {
|
|
548
|
+
removeWorkspaceDir(dir);
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
options.onWorkspaceRemoveFailed?.(cell.id, dir, error instanceof Error ? error.message : String(error));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Run the workspace's `setup` steps in order. Returns the harness-error reason of the first step
|
|
558
|
+
* that cannot start, exits non-zero or times out, or `undefined` when every step succeeded.
|
|
559
|
+
*/
|
|
560
|
+
async function runWorkspaceSetup(spec, dir, baseEnv, childEnv, timeoutMs) {
|
|
561
|
+
const notStarted = "; the case's command was not started";
|
|
562
|
+
for (const [index, step] of spec.setup.entries()) {
|
|
563
|
+
const name = `workspace setup step ${index + 1} of ${spec.setup.length} ("${step.run}")`;
|
|
564
|
+
const started = await startWorkspaceStep(step.argv, name, notStarted, spec, dir, {
|
|
565
|
+
baseEnv,
|
|
566
|
+
childEnv,
|
|
567
|
+
timeoutMs,
|
|
568
|
+
});
|
|
569
|
+
if ('reason' in started)
|
|
570
|
+
return started.reason;
|
|
571
|
+
const { run } = started;
|
|
572
|
+
if (run.exitCode !== 0) {
|
|
573
|
+
return `${name} exited with code ${run.exitCode}${notStarted}${stderrSuffix(run)}`;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return undefined;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Start one workspace-side step — a BATCH-58 `setup` step or a BATCH-59 `after` step — the one way
|
|
580
|
+
* both are started: its parse-time argv with the tokens expanded per element, through the spawn
|
|
581
|
+
* seam (no shell, the tree kill and the exit hook), with the workspace as its cwd, the workspace's
|
|
582
|
+
* `env`, NO prompt (appending the case's prompt to `git init` would make it a directory name), and
|
|
583
|
+
* the case's own timeout. One helper, so a change to how such a step starts cannot reach one kind
|
|
584
|
+
* and miss the other.
|
|
585
|
+
*
|
|
586
|
+
* Returns the run, or the harness-error reason when the step could not start or outlived the
|
|
587
|
+
* timeout; `suffix` is added to that reason before the stderr tail. What a finished run MEANS is
|
|
588
|
+
* the caller's: a `setup` step must exit 0, an `after` step is compared with its expectation.
|
|
589
|
+
*/
|
|
590
|
+
async function startWorkspaceStep(argv, name, suffix, spec, dir, envs) {
|
|
591
|
+
let run;
|
|
592
|
+
try {
|
|
593
|
+
run = await spawnCommand({
|
|
594
|
+
argv: expandSetupArgv(argv, spec, dir, envs.baseEnv),
|
|
595
|
+
prompt: '',
|
|
596
|
+
promptDelivery: 'none',
|
|
597
|
+
timeoutMs: envs.timeoutMs,
|
|
598
|
+
cwd: dir,
|
|
599
|
+
env: envs.childEnv,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
return {
|
|
604
|
+
reason: `${name} ${error instanceof Error ? error.message : String(error)}${suffix}`,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (run.timedOut) {
|
|
608
|
+
return {
|
|
609
|
+
reason: `${name} did not finish within the case's ${envs.timeoutMs}ms timeout and its process ` +
|
|
610
|
+
`tree was killed${suffix}${stderrSuffix(run)}`,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
return { run };
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* BATCH-59 — grade the case's workspace assertions while the workspace still exists, and return
|
|
617
|
+
* the outcome to report.
|
|
618
|
+
*
|
|
619
|
+
* ## The order, and what each result becomes
|
|
620
|
+
*
|
|
621
|
+
* - **Nothing is graded on a run that failed.** An `ok: false` outcome (the command timed out,
|
|
622
|
+
* exited non-zero, or printed no transcript) is already a harness error, and what it left on
|
|
623
|
+
* disk is a half-finished run.
|
|
624
|
+
* - **`file_contains`, then `must_not_exist`, then the `after` steps, in order.** The file checks
|
|
625
|
+
* go first because an `after` step can change the tree (a build, a formatter); they grade what
|
|
626
|
+
* the AGENT left.
|
|
627
|
+
* - **A check that does not hold is an assertion failure:** its reason goes on
|
|
628
|
+
* `workspaceFailures`, the outcome stays `ok: true`, and the eval runner adds it to the cell's
|
|
629
|
+
* `reasons`, so the cell FAILs (exit 1).
|
|
630
|
+
* - **A workspace entry the file checks could not read** (EACCES and the like) is a harness
|
|
631
|
+
* error, for the same reason as the next item: the check never looked.
|
|
632
|
+
* - **An `after` step that cannot start, or outlives the case's timeout, is a harness error**
|
|
633
|
+
* (`ok: false`, exit 2), exactly as a `setup` step is: the check never ran, so there is no
|
|
634
|
+
* result to grade, and reporting the case as failed would charge the harness's trouble to the
|
|
635
|
+
* agent. Later steps are not run.
|
|
636
|
+
*
|
|
637
|
+
* Every step runs even when an earlier one did not match, so one run reports every check that
|
|
638
|
+
* did not hold.
|
|
639
|
+
*/
|
|
640
|
+
async function gradeWorkspace(caseChecks, spec, dir, baseEnv, childEnv, timeoutMs, outcome) {
|
|
641
|
+
if (caseChecks === undefined || !outcome.ok)
|
|
642
|
+
return outcome;
|
|
643
|
+
let failures;
|
|
644
|
+
try {
|
|
645
|
+
failures = [
|
|
646
|
+
...checkFileContains(dir, caseChecks.fileContains),
|
|
647
|
+
...checkMustNotExist(dir, caseChecks.mustNotExist),
|
|
648
|
+
];
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
// An entry the check could not look at (EACCES and the like) is a harness error: see
|
|
652
|
+
// WorkspaceUnreadableError. Anything else is a bug, and is left to propagate.
|
|
653
|
+
if (error instanceof WorkspaceUnreadableError)
|
|
654
|
+
return { ok: false, error: error.message };
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
657
|
+
for (const [index, step] of caseChecks.after.entries()) {
|
|
658
|
+
const result = await runAfterStep(step, index, caseChecks.after.length, spec, dir, {
|
|
659
|
+
baseEnv,
|
|
660
|
+
childEnv,
|
|
661
|
+
timeoutMs,
|
|
662
|
+
});
|
|
663
|
+
if (result.harnessError !== undefined)
|
|
664
|
+
return { ok: false, error: result.harnessError };
|
|
665
|
+
if (result.failure !== undefined)
|
|
666
|
+
failures.push(result.failure);
|
|
667
|
+
}
|
|
668
|
+
return failures.length > 0 ? { ...outcome, workspaceFailures: failures } : outcome;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* BATCH-59 — run one `after` step and compare its result.
|
|
672
|
+
*
|
|
673
|
+
* It is started exactly as a `setup` step is, by {@link startWorkspaceStep}.
|
|
674
|
+
*
|
|
675
|
+
* ## A crashed check must never pass on its output
|
|
676
|
+
*
|
|
677
|
+
* Under `equals` or `contains`, a step that exits non-zero FAILS, naming the exit code and the
|
|
678
|
+
* tail of its stderr, and its stdout is not compared. `git status --porcelain` run outside a
|
|
679
|
+
* repository prints nothing to stdout and exits 128; compared on its output alone, that is
|
|
680
|
+
* exactly `equals: ""`, the "nothing changed" assertion, and it would pass on a workspace where
|
|
681
|
+
* git never looked. Only `exit_code` reads the exit code as the answer.
|
|
682
|
+
*
|
|
683
|
+
* stdout is compared trimmed, with Windows line endings read as `\n`, so a check written once
|
|
684
|
+
* reads the same output on every platform.
|
|
685
|
+
*/
|
|
686
|
+
async function runAfterStep(step, index, count, spec, dir, envs) {
|
|
687
|
+
const name = `after step ${index + 1} of ${count} ("${step.run}")`;
|
|
688
|
+
const started = await startWorkspaceStep(step.argv, name, '', spec, dir, envs);
|
|
689
|
+
if ('reason' in started)
|
|
690
|
+
return { harnessError: started.reason };
|
|
691
|
+
const { run } = started;
|
|
692
|
+
const withStderr = (reason) => `${reason}${stderrSuffix(run)}`;
|
|
693
|
+
const expectation = step.expect;
|
|
694
|
+
if (expectation.kind === 'exit_code') {
|
|
695
|
+
return run.exitCode === expectation.code
|
|
696
|
+
? {}
|
|
697
|
+
: {
|
|
698
|
+
failure: withStderr(`${name}: expected exit code ${expectation.code}, got ` +
|
|
699
|
+
(run.exitCode === null ? 'none (it was killed by a signal)' : `${run.exitCode}`)),
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
if (run.exitCode !== 0) {
|
|
703
|
+
return {
|
|
704
|
+
failure: withStderr(`${name} exited with code ${run.exitCode === null ? 'none (killed by a signal)' : run.exitCode}, ` +
|
|
705
|
+
`so its output was not compared (${expectation.kind})`),
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
const stdout = run.stdout.replace(/\r\n/g, '\n').trim();
|
|
709
|
+
if (expectation.kind === 'equals') {
|
|
710
|
+
return stdout === expectation.value
|
|
711
|
+
? {}
|
|
712
|
+
: {
|
|
713
|
+
failure: `${name}: expected stdout ${JSON.stringify(expectation.value)}, got ${JSON.stringify(clip(stdout))}`,
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
return stdout.includes(expectation.value)
|
|
717
|
+
? {}
|
|
718
|
+
: {
|
|
719
|
+
failure: `${name}: stdout does not contain ${JSON.stringify(expectation.value)}; it was ${JSON.stringify(clip(stdout))}`,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/** `; stderr: <tail>` for a run that printed to stderr, or nothing. */
|
|
724
|
+
function stderrSuffix(run) {
|
|
725
|
+
const stderrTail = tail(run.stderr);
|
|
726
|
+
return stderrTail ? `; stderr: ${stderrTail}` : '';
|
|
727
|
+
}
|
|
728
|
+
/** At most {@link STDERR_TAIL_CHARS} characters of `text`, from its start, for a reason. */
|
|
729
|
+
function clip(text) {
|
|
730
|
+
return text.length > STDERR_TAIL_CHARS ? `${text.slice(0, STDERR_TAIL_CHARS)}…` : text;
|
|
731
|
+
}
|
|
732
|
+
//# sourceMappingURL=commandEvalRunner.js.map
|