cliprobe 1.4.0 → 1.4.2
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 +29 -27
- package/dist/cli.js +379 -81
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,29 +128,31 @@ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, onl
|
|
|
128
128
|
npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings fail too, except restore's
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
| Option | Meaning
|
|
132
|
-
| ---------------------------- |
|
|
133
|
-
| `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote
|
|
134
|
-
| `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards)
|
|
135
|
-
| `--check <name>` | Run only this check; repeat it or use commas for several
|
|
136
|
-
| `--skip <name>` | Leave this check out; repeat it or use commas for several
|
|
137
|
-
| `--strict` | Exit 1 on a warning too, not only on a failure
|
|
138
|
-
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports)
|
|
139
|
-
| `--json` | Same as `--format json`
|
|
140
|
-
| `-o`, `--output-file <path>` | Write the `--format` report to a file (atomically,
|
|
141
|
-
| `--timeout <ms>` | Kill a probe after this long (default 15000); a command still running then is judged on what it did so far
|
|
142
|
-
| `-h`, `--help` | Show help
|
|
143
|
-
| `-v`, `--version` | Show the version
|
|
131
|
+
| Option | Meaning |
|
|
132
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
|
|
134
|
+
| `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards) |
|
|
135
|
+
| `--check <name>` | Run only this check; repeat it or use commas for several |
|
|
136
|
+
| `--skip <name>` | Leave this check out; repeat it or use commas for several |
|
|
137
|
+
| `--strict` | Exit 1 on a warning too, not only on a failure |
|
|
138
|
+
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports) |
|
|
139
|
+
| `--json` | Same as `--format json` |
|
|
140
|
+
| `-o`, `--output-file <path>` | Write the `--format` report to a file (replaced atomically, keeping its mode and following symlinks, with parent folders created; a FIFO, `/dev/stdout` or `/dev/fd/N` is written in place); the human report still prints. For a path that starts with `-`, write `-o=<path>` or `./<path>` |
|
|
141
|
+
| `--timeout <ms>` | Kill a probe after this long (default 15000, at most 2147483647, about 24 days); a command still running then is judged on what it did so far |
|
|
142
|
+
| `-h`, `--help` | Show help |
|
|
143
|
+
| `-v`, `--version` | Show the version |
|
|
144
|
+
|
|
145
|
+
An option's value follows it or comes after `=` (`--format=json`). A value that is another option, as in `-o --strict`, is a usage error rather than a file named `--strict`. `--probe` is the exception: its value may start with `-`, to probe a flag (`--probe --json`).
|
|
144
146
|
|
|
145
147
|
## Exit codes
|
|
146
148
|
|
|
147
|
-
| Code | Meaning
|
|
148
|
-
| ---- |
|
|
149
|
-
| `0` | No check failed
|
|
150
|
-
| `1` | A check failed, or warned with `--strict`
|
|
151
|
-
| `2` | Usage error,
|
|
149
|
+
| Code | Meaning |
|
|
150
|
+
| ---- | ------------------------------------------------------------------------------------------ |
|
|
151
|
+
| `0` | No check failed |
|
|
152
|
+
| `1` | A check failed, or warned with `--strict` |
|
|
153
|
+
| `2` | Usage error, the command could not run, or the `--output-file` report could not be written |
|
|
152
154
|
|
|
153
|
-
A command that isn't on `PATH` is
|
|
155
|
+
A command that can't run is reported once, before any check runs, with exit `2` and no report: one that isn't on `PATH`, a directory, a file without the execute bit (`chmod +x`), or a script whose `#!` interpreter is missing. A file this system can't execute at all, such as a binary built for another platform, makes every check say could-not-run (`ERROR`), so cliprobe exits `2` there too; on Linux, where `/bin/sh` tries such a file as a script, cliprobe recognizes the shell's complaint. An `--output-file` path that can't be written, such as a directory or a folder without write permission, is also reported before any check runs, with exit `2`. If the file still can't be written at the end, cliprobe prints the human report first, so no result is lost, then the error, and exits `2` even when a check failed: CI fails the step either way. That makes cliprobe usable as a CI gate.
|
|
154
156
|
|
|
155
157
|
## In CI
|
|
156
158
|
|
|
@@ -270,14 +272,14 @@ A carriage-return redraw only warns because some tools draw a progress meter on
|
|
|
270
272
|
|
|
271
273
|
### stdin
|
|
272
274
|
|
|
273
|
-
Agents and CI runners often start a command with stdin as a pipe that stays open and never receives anything. A program that reads stdin, or asks a question, then waits forever. cliprobe runs the command three ways: with stdin closed (`/dev/null`), with an open pipe, and, if that hangs
|
|
275
|
+
Agents and CI runners often start a command with stdin as a pipe that stays open and never receives anything. A program that reads stdin, or asks a question, then waits forever. cliprobe runs the command three ways: with stdin closed (`/dev/null`), with an open pipe, and, if that hangs, with a pipe it closes partway through. Finishing only after the close proves stdin was the cause. The open pipe gets 3 seconds, or twice the time the command took with stdin closed plus 1 second if that is longer, so a program that is just slow to answer isn't mistaken for one that waits. The pipe in the third run is closed after 1 second, or after that longer time for a slow command. Each run still stops at `--timeout`. Results:
|
|
274
276
|
|
|
275
|
-
| Verdict | Meaning
|
|
276
|
-
| ------- |
|
|
277
|
-
| `PASS` | Finished without waiting for stdin
|
|
278
|
-
| `FAIL` | `--version` or `--help` waited for stdin before answering: they must never need input
|
|
279
|
-
| `WARN` | A probe you wrote printed an unfinished line, like a question, then waited: it prompts even though stdin isn't a terminal
|
|
280
|
-
| `SKIP` | A probe you wrote waited silently, like a filter (`grep pattern`),
|
|
277
|
+
| Verdict | Meaning |
|
|
278
|
+
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
279
|
+
| `PASS` | Finished without waiting for stdin |
|
|
280
|
+
| `FAIL` | `--version` or `--help` waited for stdin before answering: they must never need input |
|
|
281
|
+
| `WARN` | A probe you wrote printed an unfinished line, like a question, then waited: it prompts even though stdin isn't a terminal |
|
|
282
|
+
| `SKIP` | A probe you wrote waited silently, like a filter (`grep pattern`), the hang wasn't caused by stdin, or the command is too slow for `--timeout` to tell |
|
|
281
283
|
|
|
282
284
|
In the census of the top 100 npm CLIs, 9 of 238 `--help` and `--version` runs failed, each confirmed by hand. he, cssesc and ansi-html read stdin before looking at their arguments. webpack and webpack-dev-server, when webpack-cli is missing, ask whether to install it and wait for an answer without checking for a terminal. With no arguments, 17 tools waited on stdin as filters by design, which is why probes you write never fail this check.
|
|
283
285
|
|
|
@@ -433,7 +435,7 @@ Then ask in your own words, for example "check my CLI for pipe and Ctrl-C bugs b
|
|
|
433
435
|
|
|
434
436
|
## Safety
|
|
435
437
|
|
|
436
|
-
cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin, ctrl-c and sigterm checks use a pipe that they never write to), a temporary `HOME`, and a minimal environment (no tokens from your shell). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal, and when a program exits it kills whatever it left running, in its group or started in another one, in every check. If cliprobe itself is stopped by Ctrl-C, SIGTERM or SIGHUP, it first kills the probe it is running and removes its temporary directories, then exits by the same signal (130, 143 or 129). It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command, which Alpine ships in `util-linux-misc`. Windows isn't supported yet.
|
|
438
|
+
cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin, ctrl-c and sigterm checks use a pipe that they never write to), a temporary `HOME`, and a minimal environment (no tokens from your shell). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal, and when a program exits it kills whatever it left running, in its group or started in another one, in every check. If cliprobe itself is stopped by Ctrl-C, SIGTERM or SIGHUP, it first kills the probe it is running and removes its temporary directories and any half-written report file, then exits by the same signal (130, 143 or 129). It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command, which Alpine ships in `util-linux-misc`. Windows isn't supported yet.
|
|
437
439
|
|
|
438
440
|
## FAQ
|
|
439
441
|
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
4
|
-
import { accessSync, closeSync, constants,
|
|
5
|
-
import { delimiter, dirname, join } from "node:path";
|
|
4
|
+
import { accessSync, closeSync, constants, lstatSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
5
|
+
import { delimiter, dirname, join, resolve, sep } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
+
import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
7
8
|
// src/core/interrupt.ts
|
|
8
9
|
const cleanups = /* @__PURE__ */ new Set();
|
|
9
10
|
/** Registers `cleanup` until the returned function is called. */
|
|
@@ -218,9 +219,118 @@ function sandbox() {
|
|
|
218
219
|
}
|
|
219
220
|
};
|
|
220
221
|
}
|
|
222
|
+
// src/core/which.ts
|
|
223
|
+
function isExecutableFile(path) {
|
|
224
|
+
try {
|
|
225
|
+
accessSync(path, constants.X_OK);
|
|
226
|
+
return statSync(path).isFile();
|
|
227
|
+
} catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Where `command` would be found, as spawn() looks for it: a path with a slash
|
|
233
|
+
* as given, otherwise each PATH entry in turn (an empty entry is the current
|
|
234
|
+
* directory). Under a PTY, a missing command is only a line of shell output, so
|
|
235
|
+
* the terminal checks ask first.
|
|
236
|
+
*/
|
|
237
|
+
function findCommand(command, path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
238
|
+
if (command.includes("/")) return isExecutableFile(command) ? command : void 0;
|
|
239
|
+
for (const dir of path.split(delimiter)) {
|
|
240
|
+
const candidate = join(dir || ".", command);
|
|
241
|
+
if (isExecutableFile(candidate)) return candidate;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** The first bytes of a file, or nothing when it can't be read (execute-only, say). */
|
|
245
|
+
function head(path, bytes = 512) {
|
|
246
|
+
let fd;
|
|
247
|
+
try {
|
|
248
|
+
fd = openSync(path, "r");
|
|
249
|
+
const buffer = Buffer.alloc(bytes);
|
|
250
|
+
return buffer.subarray(0, readSync(fd, buffer, 0, bytes, 0));
|
|
251
|
+
} catch {
|
|
252
|
+
return Buffer.alloc(0);
|
|
253
|
+
} finally {
|
|
254
|
+
if (fd !== void 0) closeSync(fd);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Why the interpreter named on a `#!` line can't run, if it can't. */
|
|
258
|
+
function interpreterProblem(command, file, path) {
|
|
259
|
+
const start = head(file, 256);
|
|
260
|
+
if (start.subarray(0, 2).toString("latin1") !== "#!") return void 0;
|
|
261
|
+
const [interpreter = "", first] = (start.toString("utf8").slice(2).split("\n")[0] ?? "").trim().split(/[ \t]+/);
|
|
262
|
+
if (interpreter === "") return void 0;
|
|
263
|
+
try {
|
|
264
|
+
statSync(interpreter);
|
|
265
|
+
} catch {
|
|
266
|
+
return `${command}: interpreter ${interpreter} not found`;
|
|
267
|
+
}
|
|
268
|
+
if (!isExecutableFile(interpreter)) return `${command}: interpreter ${interpreter} is not executable`;
|
|
269
|
+
if (/(^|\/)env$/.test(interpreter) && first !== void 0 && !first.startsWith("-")) {
|
|
270
|
+
if (!first.includes("=") && findCommand(first, path) === void 0) return `${command}: interpreter ${first} not found (${interpreter} ${first})`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Why `command` can't run, or undefined if it looks runnable: not found, a
|
|
275
|
+
* directory, not executable, or a `#!` interpreter that is missing. Asked before
|
|
276
|
+
* any check, so the user sees the cause once instead of an error per probe.
|
|
277
|
+
*/
|
|
278
|
+
function commandProblem(command, path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
279
|
+
if (command.includes("/")) {
|
|
280
|
+
let isFile;
|
|
281
|
+
try {
|
|
282
|
+
const stat = statSync(command);
|
|
283
|
+
if (stat.isDirectory()) return `${command} is a directory`;
|
|
284
|
+
isFile = stat.isFile();
|
|
285
|
+
} catch {
|
|
286
|
+
return `command not found: ${command}`;
|
|
287
|
+
}
|
|
288
|
+
if (!isFile) return `${command} is not a regular file`;
|
|
289
|
+
if (!isExecutableFile(command)) return `${command} is not executable (chmod +x?)`;
|
|
290
|
+
return interpreterProblem(command, command, path);
|
|
291
|
+
}
|
|
292
|
+
const file = findCommand(command, path);
|
|
293
|
+
if (file === void 0) return `command not found: ${command}`;
|
|
294
|
+
return interpreterProblem(command, file, path);
|
|
295
|
+
}
|
|
296
|
+
/** The reason given for a file this system can't run as a program. */
|
|
297
|
+
const notAProgram = (command, how) => `${command} is not a program this system can run (${how})`;
|
|
298
|
+
/**
|
|
299
|
+
* Whether `command` resolves to a file that no shell or kernel would run as a
|
|
300
|
+
* program of this system: no `#!` line, and a NUL byte near its start, which no
|
|
301
|
+
* script has. Alone this could be a binary run through binfmt_misc, so callers
|
|
302
|
+
* also need the run to have exited 126 or 127.
|
|
303
|
+
*/
|
|
304
|
+
function cannotExecute(command, path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
305
|
+
const file = findCommand(command, path);
|
|
306
|
+
if (file === void 0) return false;
|
|
307
|
+
const start = head(file);
|
|
308
|
+
return start.subarray(0, 2).toString("latin1") !== "#!" && start.includes(0);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Whether a run ended because the system could not run the file at all. On
|
|
312
|
+
* Linux, spawn() hands a file the kernel can't execute (ENOEXEC) to /bin/sh,
|
|
313
|
+
* as execvp() does, so a binary that isn't one for this system "runs" and exits
|
|
314
|
+
* 126 or 127 with the shell's complaint, prefixed by the file's path. Only a
|
|
315
|
+
* file with no `#!` line and a NUL byte near its start counts, as no script has
|
|
316
|
+
* one: a binary run through binfmt_misc, or a script without `#!`, is left alone.
|
|
317
|
+
* Returns the reason, or undefined.
|
|
318
|
+
*/
|
|
319
|
+
function shellFallbackError(command, exitCode, stderr, path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
320
|
+
if (exitCode !== 126 && exitCode !== 127) return void 0;
|
|
321
|
+
const file = findCommand(command, path);
|
|
322
|
+
if (file === void 0 || !cannotExecute(command, path)) return void 0;
|
|
323
|
+
if (!stderr.startsWith(`${command}: `) && !stderr.startsWith(`${file}: `)) return void 0;
|
|
324
|
+
return notAProgram(command, `/bin/sh tried it as a script and exited ${exitCode}`);
|
|
325
|
+
}
|
|
221
326
|
// src/core/run.ts
|
|
222
327
|
const STDERR_CAP = 65536;
|
|
223
328
|
const STDOUT_CAP = 1048576;
|
|
329
|
+
/**
|
|
330
|
+
* The longest delay setTimeout takes (2^31 - 1 ms, about 24.8 days). Node turns
|
|
331
|
+
* anything longer into 1 ms, which would kill every probe at once.
|
|
332
|
+
*/
|
|
333
|
+
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
224
334
|
/** How often the process table is read while the program runs, to learn its descendants. */
|
|
225
335
|
const TREE_POLL_MS = 200;
|
|
226
336
|
/** How long to wait for the output pipes to close once everything the run started is gone. */
|
|
@@ -317,7 +427,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
317
427
|
finish({
|
|
318
428
|
exitCode: null,
|
|
319
429
|
signal: null,
|
|
320
|
-
spawnError:
|
|
430
|
+
spawnError: spawnMessage(command, error)
|
|
321
431
|
});
|
|
322
432
|
return;
|
|
323
433
|
}
|
|
@@ -342,7 +452,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
342
452
|
timedOut = true;
|
|
343
453
|
recordTree();
|
|
344
454
|
killRun();
|
|
345
|
-
}, timeout);
|
|
455
|
+
}, Math.min(timeout, MAX_TIMEOUT_MS));
|
|
346
456
|
const signalTimer = signal && setTimeout(() => {
|
|
347
457
|
if (exited || proc.pid === void 0) return;
|
|
348
458
|
recordTree();
|
|
@@ -386,9 +496,11 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
386
496
|
}
|
|
387
497
|
proc.stdout?.destroy();
|
|
388
498
|
proc.stderr?.destroy();
|
|
499
|
+
const notRun = timedOut ? void 0 : shellFallbackError(command, exitCode, stderr);
|
|
389
500
|
finish({
|
|
390
501
|
exitCode,
|
|
391
|
-
signal: exitSignal
|
|
502
|
+
signal: exitSignal,
|
|
503
|
+
...notRun === void 0 ? {} : { spawnError: notRun }
|
|
392
504
|
});
|
|
393
505
|
})();
|
|
394
506
|
});
|
|
@@ -405,7 +517,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
405
517
|
finish({
|
|
406
518
|
exitCode: null,
|
|
407
519
|
signal: null,
|
|
408
|
-
spawnError: error
|
|
520
|
+
spawnError: spawnMessage(command, error)
|
|
409
521
|
});
|
|
410
522
|
});
|
|
411
523
|
proc.on("close", () => {
|
|
@@ -414,6 +526,11 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
414
526
|
});
|
|
415
527
|
});
|
|
416
528
|
}
|
|
529
|
+
/** Why spawn() failed; "spawn ENOEXEC" names neither the file nor the problem. */
|
|
530
|
+
function spawnMessage(command, error) {
|
|
531
|
+
if (!(error instanceof Error)) return String(error);
|
|
532
|
+
return "code" in error && error.code === "ENOEXEC" ? notAProgram(command, "exec format error") : error.message;
|
|
533
|
+
}
|
|
417
534
|
/**
|
|
418
535
|
* Waits up to `ms` for what the program left running to finish on its own, as
|
|
419
536
|
* children stopped by their parent take a moment to exit, and returns what is
|
|
@@ -1720,33 +1837,13 @@ const pipeEscapesCheck = {
|
|
|
1720
1837
|
return results;
|
|
1721
1838
|
}
|
|
1722
1839
|
};
|
|
1723
|
-
// src/core/which.ts
|
|
1724
|
-
function isExecutableFile(path) {
|
|
1725
|
-
try {
|
|
1726
|
-
accessSync(path, constants.X_OK);
|
|
1727
|
-
return statSync(path).isFile();
|
|
1728
|
-
} catch {
|
|
1729
|
-
return false;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
/**
|
|
1733
|
-
* Where `command` would be found, as spawn() looks for it: a path with a slash
|
|
1734
|
-
* as given, otherwise each PATH entry in turn (an empty entry is the current
|
|
1735
|
-
* directory). Under a PTY, a missing command is only a line of shell output, so
|
|
1736
|
-
* the terminal checks ask first.
|
|
1737
|
-
*/
|
|
1738
|
-
function findCommand(command, path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
1739
|
-
if (command.includes("/")) return isExecutableFile(command) ? command : void 0;
|
|
1740
|
-
for (const dir of path.split(delimiter)) {
|
|
1741
|
-
const candidate = join(dir || ".", command);
|
|
1742
|
-
if (isExecutableFile(candidate)) return candidate;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
1840
|
// src/checks/restore.ts
|
|
1746
1841
|
function listLabels(modes) {
|
|
1747
1842
|
const labels = modes.map((m) => m.label);
|
|
1748
1843
|
return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
|
|
1749
1844
|
}
|
|
1845
|
+
/** The PTY wrapper's own complaint when it can't exec the program. */
|
|
1846
|
+
const WRAPPER_EXEC_FAILED = /^sh: [^\n]*(cannot execute|exec format error)/i;
|
|
1750
1847
|
/** What the Ctrl-C key sends to a terminal. */
|
|
1751
1848
|
const CTRL_C_KEY = "";
|
|
1752
1849
|
const showSequence = (sequence) => sequence.replaceAll("\x1B", "ESC");
|
|
@@ -1784,7 +1881,10 @@ async function restore(command, args, { timeout, interrupt }) {
|
|
|
1784
1881
|
afterMs: CTRL_C_DELAY_MS
|
|
1785
1882
|
} } : {}
|
|
1786
1883
|
});
|
|
1787
|
-
const judgement = judgeRestore(r)
|
|
1884
|
+
const judgement = judgeRestore(r.spawnError === void 0 && (r.exitCode === 126 || r.exitCode === 127 || WRAPPER_EXEC_FAILED.test(r.output)) && cannotExecute(command) ? {
|
|
1885
|
+
...r,
|
|
1886
|
+
spawnError: notAProgram(command, "the terminal's shell could not exec it")
|
|
1887
|
+
} : r);
|
|
1788
1888
|
return {
|
|
1789
1889
|
check: "restore",
|
|
1790
1890
|
invocation: [command, ...args],
|
|
@@ -1896,10 +1996,29 @@ const startupCheck = {
|
|
|
1896
1996
|
}
|
|
1897
1997
|
};
|
|
1898
1998
|
// src/checks/stdin.ts
|
|
1899
|
-
/**
|
|
1999
|
+
/** The least time the program gets with stdin left open before it counts as waiting. */
|
|
1900
2000
|
const STDIN_WAIT_MS = 3e3;
|
|
1901
|
-
/**
|
|
2001
|
+
/** The earliest the confirming run closes stdin, and the least time it then gets to finish. */
|
|
1902
2002
|
const STDIN_CLOSE_AFTER_MS = 1e3;
|
|
2003
|
+
const STDIN_GRACE_MS = 3e3;
|
|
2004
|
+
/**
|
|
2005
|
+
* How long a run must go past the one with stdin closed before stdin can be
|
|
2006
|
+
* blamed: twice that time and a second more, so a program that is merely slow
|
|
2007
|
+
* (3 to 4 s to answer) finishes well within it.
|
|
2008
|
+
*/
|
|
2009
|
+
const stdinMargin = (closedMs) => 2 * closedMs + 1e3;
|
|
2010
|
+
/**
|
|
2011
|
+
* Whether the runs prove the program waited for stdin: it hung with stdin open
|
|
2012
|
+
* for well past the time it needed with stdin closed, and in the confirming run
|
|
2013
|
+
* it finished after stdin was closed, not before.
|
|
2014
|
+
*/
|
|
2015
|
+
function provenByClose(runs) {
|
|
2016
|
+
const { closed, open, closing } = runs;
|
|
2017
|
+
const openMs = runs.openMs ?? 3e3;
|
|
2018
|
+
const closeAfterMs = runs.closeAfterMs ?? 1e3;
|
|
2019
|
+
return open?.timedOut === true && openMs >= stdinMargin(closed.durationMs) && closing !== void 0 && !closing.timedOut && closing.durationMs >= closeAfterMs;
|
|
2020
|
+
}
|
|
2021
|
+
const seconds = (ms) => `${Math.round(ms / 100) / 10} s`;
|
|
1903
2022
|
/** The last line printed before waiting, when it reads like a question left on the line. */
|
|
1904
2023
|
function promptLine(r) {
|
|
1905
2024
|
const last = stripEscapes(r.stdout.toString("utf8") + r.stderr).split("\n").at(-1) ?? "";
|
|
@@ -1925,11 +2044,21 @@ function judgeStdin(runs, defaultProbe) {
|
|
|
1925
2044
|
verdict: "pass",
|
|
1926
2045
|
reason: "finished without waiting for stdin"
|
|
1927
2046
|
};
|
|
2047
|
+
const openMs = runs.openMs ?? 3e3;
|
|
2048
|
+
const closeAfterMs = runs.closeAfterMs ?? 1e3;
|
|
2049
|
+
if (openMs < stdinMargin(closed.durationMs)) return {
|
|
2050
|
+
verdict: "skip",
|
|
2051
|
+
reason: `takes ${closed.durationMs} ms even with stdin closed, too close to --timeout to tell whether an open stdin makes it wait; raise --timeout`
|
|
2052
|
+
};
|
|
1928
2053
|
if (!closing || closing.timedOut) return {
|
|
1929
2054
|
verdict: "skip",
|
|
1930
2055
|
reason: "hung with stdin open, but closing stdin didn't end it, so the cause isn't proven"
|
|
1931
2056
|
};
|
|
1932
|
-
|
|
2057
|
+
if (!provenByClose(runs)) return {
|
|
2058
|
+
verdict: "skip",
|
|
2059
|
+
reason: "hung once with stdin open, but finished before stdin was closed the next time, so the cause isn't proven"
|
|
2060
|
+
};
|
|
2061
|
+
const evidence = `${closed.durationMs} ms with stdin closed; still running after ${seconds(openMs)} with stdin open; finished ${closing.durationMs - closeAfterMs} ms after stdin closed`;
|
|
1933
2062
|
if (defaultProbe) return {
|
|
1934
2063
|
verdict: "fail",
|
|
1935
2064
|
reason: "waited for stdin before answering, so an agent or CI step that leaves stdin open hangs forever",
|
|
@@ -1951,21 +2080,27 @@ async function stdinRuns(command, args, timeout) {
|
|
|
1951
2080
|
const closed = await run$1(command, args, { timeout });
|
|
1952
2081
|
if (closed.timedOut) return { closed };
|
|
1953
2082
|
if (closed.spawnError) return { closed };
|
|
2083
|
+
const margin = stdinMargin(closed.durationMs);
|
|
2084
|
+
const openMs = Math.min(timeout, Math.max(STDIN_WAIT_MS, margin));
|
|
1954
2085
|
const open = await run$1(command, args, {
|
|
1955
|
-
timeout:
|
|
2086
|
+
timeout: openMs,
|
|
1956
2087
|
stdin: "open"
|
|
1957
2088
|
});
|
|
1958
|
-
if (!open.timedOut) return {
|
|
2089
|
+
if (!open.timedOut || openMs < margin) return {
|
|
1959
2090
|
closed,
|
|
1960
|
-
open
|
|
2091
|
+
open,
|
|
2092
|
+
openMs
|
|
1961
2093
|
};
|
|
2094
|
+
const closeAfterMs = Math.max(STDIN_CLOSE_AFTER_MS, margin);
|
|
1962
2095
|
return {
|
|
1963
2096
|
closed,
|
|
1964
2097
|
open,
|
|
2098
|
+
openMs,
|
|
1965
2099
|
closing: await run$1(command, args, {
|
|
1966
|
-
timeout:
|
|
1967
|
-
stdin: { closeAfterMs
|
|
1968
|
-
})
|
|
2100
|
+
timeout: closeAfterMs + Math.max(STDIN_GRACE_MS, margin),
|
|
2101
|
+
stdin: { closeAfterMs }
|
|
2102
|
+
}),
|
|
2103
|
+
closeAfterMs
|
|
1969
2104
|
};
|
|
1970
2105
|
}
|
|
1971
2106
|
async function stdinCheck(command, args, defaultProbe, ctx) {
|
|
@@ -1980,14 +2115,14 @@ async function stdinCheck(command, args, defaultProbe, ctx) {
|
|
|
1980
2115
|
};
|
|
1981
2116
|
const runs = await stdinRuns(command, args, ctx.timeout);
|
|
1982
2117
|
if (runs.closed.timedOut) markLongRunning(ctx, command, args);
|
|
1983
|
-
const proven = runs
|
|
2118
|
+
const proven = provenByClose(runs);
|
|
1984
2119
|
return {
|
|
1985
2120
|
check: "stdin",
|
|
1986
2121
|
invocation: [command, ...args],
|
|
1987
2122
|
...judgeStdin(runs, defaultProbe),
|
|
1988
2123
|
closedMs: runs.closed.spawnError ? null : runs.closed.durationMs,
|
|
1989
2124
|
waitedForStdin: proven,
|
|
1990
|
-
finishedAfterCloseMs: proven && runs.closing ? runs.closing.durationMs -
|
|
2125
|
+
finishedAfterCloseMs: proven && runs.closing ? runs.closing.durationMs - (runs.closeAfterMs ?? 1e3) : null
|
|
1991
2126
|
};
|
|
1992
2127
|
}
|
|
1993
2128
|
// src/checks/index.ts
|
|
@@ -2151,7 +2286,7 @@ function formatHuman({ version, command, checks, strict, results }, { color }) {
|
|
|
2151
2286
|
lines.push("");
|
|
2152
2287
|
if (checks.length > 1) lines.push(check);
|
|
2153
2288
|
for (const r of results.filter((result) => result.check === check)) {
|
|
2154
|
-
lines.push(` ${paint(r.verdict)} ${safe(shellJoin(r.invocation)).padEnd(width)} ${r.reason}`);
|
|
2289
|
+
lines.push(` ${paint(r.verdict)} ${safe(shellJoin(r.invocation)).padEnd(width)} ${safe(r.reason)}`);
|
|
2155
2290
|
if (r.evidence) lines.push(` ${" ".repeat(5)} ${" ".repeat(width)} ${safe(r.evidence).slice(0, 200)}`);
|
|
2156
2291
|
}
|
|
2157
2292
|
}
|
|
@@ -2294,20 +2429,144 @@ const FORMATS = {
|
|
|
2294
2429
|
junit: formatJunit
|
|
2295
2430
|
};
|
|
2296
2431
|
// src/report/write.ts
|
|
2432
|
+
/** Why a report can't be written to a path, in words for the person who gave it. */
|
|
2433
|
+
var ReportPathError = class extends Error {};
|
|
2434
|
+
const allowed = (path, mode) => {
|
|
2435
|
+
try {
|
|
2436
|
+
accessSync(path, mode);
|
|
2437
|
+
return true;
|
|
2438
|
+
} catch {
|
|
2439
|
+
return false;
|
|
2440
|
+
}
|
|
2441
|
+
};
|
|
2442
|
+
/** The errno code of a failed file system call, such as ENOENT. */
|
|
2443
|
+
const errorCode = (error) => error instanceof Error && "code" in error ? error.code : void 0;
|
|
2444
|
+
/** A folder in which cliprobe may create and rename files. */
|
|
2445
|
+
const writableFolder = (path) => allowed(path, constants.W_OK | constants.X_OK);
|
|
2446
|
+
/** stat() that follows symlinks, undefined for a path that doesn't exist (or runs through a file). */
|
|
2447
|
+
function statPath(path) {
|
|
2448
|
+
try {
|
|
2449
|
+
return statSync(path);
|
|
2450
|
+
} catch (error) {
|
|
2451
|
+
const code = errorCode(error);
|
|
2452
|
+
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
2453
|
+
throw new ReportPathError(describeWriteError(error));
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
/** A symlink's final target, followed even when that target doesn't exist yet. */
|
|
2457
|
+
function followLinks(path) {
|
|
2458
|
+
let current = resolve(path);
|
|
2459
|
+
for (let hops = 0; hops < 40; hops++) {
|
|
2460
|
+
let st;
|
|
2461
|
+
try {
|
|
2462
|
+
st = lstatSync(current);
|
|
2463
|
+
} catch {
|
|
2464
|
+
return current;
|
|
2465
|
+
}
|
|
2466
|
+
if (!st.isSymbolicLink()) return current;
|
|
2467
|
+
current = resolve(dirname(current), readlinkSync(current));
|
|
2468
|
+
}
|
|
2469
|
+
throw new ReportPathError("too many levels of symbolic links");
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Decides how to write a report to `path`, or throws a ReportPathError that says
|
|
2473
|
+
* why it can't be written. It changes nothing on disk, so the same rule serves
|
|
2474
|
+
* the check before any probe runs and the write at the end.
|
|
2475
|
+
*/
|
|
2476
|
+
function reportTarget(path) {
|
|
2477
|
+
const st = statPath(path);
|
|
2478
|
+
if (st?.isDirectory()) throw new ReportPathError("is a directory");
|
|
2479
|
+
if (st && (!st.isFile() || /^\/(dev|proc)\//.test(resolve(path)))) return {
|
|
2480
|
+
how: "direct",
|
|
2481
|
+
path
|
|
2482
|
+
};
|
|
2483
|
+
if (st) {
|
|
2484
|
+
const real = realpathSync(path);
|
|
2485
|
+
const mode = st.mode & 4095;
|
|
2486
|
+
if (writableFolder(dirname(real))) return {
|
|
2487
|
+
how: "replace",
|
|
2488
|
+
path: real,
|
|
2489
|
+
mode
|
|
2490
|
+
};
|
|
2491
|
+
if (allowed(real, constants.W_OK)) return {
|
|
2492
|
+
how: "direct",
|
|
2493
|
+
path: real
|
|
2494
|
+
};
|
|
2495
|
+
throw new ReportPathError("permission denied");
|
|
2496
|
+
}
|
|
2497
|
+
if (path.endsWith(sep) || path.endsWith(`${sep}.`)) throw new ReportPathError("names a folder, not a file");
|
|
2498
|
+
const target = followLinks(path);
|
|
2499
|
+
let ancestor = dirname(target);
|
|
2500
|
+
let ancestorStat = statPath(ancestor);
|
|
2501
|
+
while (!ancestorStat && dirname(ancestor) !== ancestor) {
|
|
2502
|
+
ancestor = dirname(ancestor);
|
|
2503
|
+
ancestorStat = statPath(ancestor);
|
|
2504
|
+
}
|
|
2505
|
+
if (!ancestorStat?.isDirectory()) throw new ReportPathError(`${ancestor} is not a folder`);
|
|
2506
|
+
if (!writableFolder(ancestor)) throw new ReportPathError("permission denied");
|
|
2507
|
+
return {
|
|
2508
|
+
how: "replace",
|
|
2509
|
+
path: target,
|
|
2510
|
+
mode: void 0
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2297
2513
|
/**
|
|
2298
|
-
*
|
|
2299
|
-
*
|
|
2300
|
-
* parent directories are created. Throws on failure, leaving no temporary file.
|
|
2514
|
+
* A failed write in words, without the file name that a raw error ends with, which
|
|
2515
|
+
* may be the temporary file's: "ENOSPC: no space left on device".
|
|
2301
2516
|
*/
|
|
2302
|
-
function
|
|
2303
|
-
|
|
2304
|
-
const
|
|
2517
|
+
function describeWriteError(error) {
|
|
2518
|
+
if (error instanceof ReportPathError) return error.message;
|
|
2519
|
+
const code = errorCode(error);
|
|
2520
|
+
if (code === "ELOOP") return "too many levels of symbolic links";
|
|
2521
|
+
if (code === "EACCES" || code === "EPERM") return "permission denied";
|
|
2522
|
+
return (error instanceof Error ? error.message : String(error)).replace(/, \w+ '.*$/s, "");
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* Checks `path` the way writeReportFile will write it, and returns why it can't
|
|
2526
|
+
* be written, or undefined when it can.
|
|
2527
|
+
*/
|
|
2528
|
+
function reportPathProblem(path) {
|
|
2305
2529
|
try {
|
|
2306
|
-
|
|
2307
|
-
|
|
2530
|
+
reportTarget(path);
|
|
2531
|
+
return;
|
|
2308
2532
|
} catch (error) {
|
|
2309
|
-
|
|
2310
|
-
|
|
2533
|
+
return describeWriteError(error);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Writes a report to `path` as reportTarget decides: a regular file is replaced
|
|
2538
|
+
* whole (missing parent folders are created), anything else is written in
|
|
2539
|
+
* place. Asynchronous, so that waiting for a FIFO's reader leaves the event
|
|
2540
|
+
* loop, and the signal handlers, running. Throws an Error that says why on failure, leaving no
|
|
2541
|
+
* temporary file, even if cliprobe is interrupted meanwhile.
|
|
2542
|
+
*/
|
|
2543
|
+
async function writeReportFile(path, text) {
|
|
2544
|
+
let target;
|
|
2545
|
+
try {
|
|
2546
|
+
target = reportTarget(path);
|
|
2547
|
+
} catch (error) {
|
|
2548
|
+
throw new Error(describeWriteError(error), { cause: error });
|
|
2549
|
+
}
|
|
2550
|
+
if (target.how === "direct") {
|
|
2551
|
+
try {
|
|
2552
|
+
await writeFile(target.path, text);
|
|
2553
|
+
} catch (error) {
|
|
2554
|
+
throw new Error(describeWriteError(error), { cause: error });
|
|
2555
|
+
}
|
|
2556
|
+
return;
|
|
2557
|
+
}
|
|
2558
|
+
const temp = `${target.path}.cliprobe-${process.pid}.tmp`;
|
|
2559
|
+
const unregister = onInterrupt(() => rmSync(temp, { force: true }));
|
|
2560
|
+
try {
|
|
2561
|
+
await mkdir(dirname(target.path), { recursive: true });
|
|
2562
|
+
await writeFile(temp, text);
|
|
2563
|
+
if (target.mode !== void 0) await chmod(temp, target.mode);
|
|
2564
|
+
await rename(temp, target.path);
|
|
2565
|
+
} catch (error) {
|
|
2566
|
+
await rm(temp, { force: true }).catch(() => void 0);
|
|
2567
|
+
throw new Error(describeWriteError(error), { cause: error });
|
|
2568
|
+
} finally {
|
|
2569
|
+
unregister();
|
|
2311
2570
|
}
|
|
2312
2571
|
}
|
|
2313
2572
|
// src/version.ts
|
|
@@ -2323,6 +2582,27 @@ function readVersion() {
|
|
|
2323
2582
|
const VERSION = readVersion();
|
|
2324
2583
|
// src/cli/args.ts
|
|
2325
2584
|
var UsageError = class extends Error {};
|
|
2585
|
+
/** Every option cliprobe takes, to tell a forgotten value from a value that starts with -. */
|
|
2586
|
+
const OPTIONS = /* @__PURE__ */ new Set([
|
|
2587
|
+
"--json",
|
|
2588
|
+
"--bare",
|
|
2589
|
+
"--strict",
|
|
2590
|
+
"-o",
|
|
2591
|
+
"--output-file",
|
|
2592
|
+
"--format",
|
|
2593
|
+
"-h",
|
|
2594
|
+
"--help",
|
|
2595
|
+
"-v",
|
|
2596
|
+
"--version",
|
|
2597
|
+
"--timeout",
|
|
2598
|
+
"--probe",
|
|
2599
|
+
"--check",
|
|
2600
|
+
"--skip"
|
|
2601
|
+
]);
|
|
2602
|
+
/** Options whose value is a path, which ./ can make start with something other than -. */
|
|
2603
|
+
const PATH_OPTIONS = /* @__PURE__ */ new Set(["-o", "--output-file"]);
|
|
2604
|
+
/** The option name in an argument such as --format=json. */
|
|
2605
|
+
const flagOf = (arg) => arg.split("=")[0] ?? arg;
|
|
2326
2606
|
function parseArgs(argv) {
|
|
2327
2607
|
const opts = {
|
|
2328
2608
|
format: "human",
|
|
@@ -2344,37 +2624,43 @@ function parseArgs(argv) {
|
|
|
2344
2624
|
[opts.command, ...opts.args] = argv.slice(i + 1);
|
|
2345
2625
|
break;
|
|
2346
2626
|
}
|
|
2627
|
+
/** The value of the option `a`: after its `=`, or the next argument, which must not be another option. */
|
|
2628
|
+
const value = (what) => {
|
|
2629
|
+
const flag = flagOf(a);
|
|
2630
|
+
const inline = a.includes("=");
|
|
2631
|
+
const v = inline ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2632
|
+
if (v === void 0 || v === "") throw new UsageError(`${flag} needs ${what}`);
|
|
2633
|
+
if (!inline && v.startsWith("-")) throw new UsageError(`${flag} needs ${what}, got option "${v}"${PATH_OPTIONS.has(flag) && !OPTIONS.has(flagOf(v)) ? `; use ${flag}=${v} or ./${v} for a value that starts with -` : ""}`);
|
|
2634
|
+
return v;
|
|
2635
|
+
};
|
|
2347
2636
|
if (a === "--json") opts.format = "json";
|
|
2348
2637
|
else if (a === "--bare") opts.bare = true;
|
|
2349
2638
|
else if (a === "--strict") opts.strict = true;
|
|
2350
|
-
else if (
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2356
|
-
if (value === void 0 || !isFormat(value)) throw new UsageError(`--format needs one of ${FORMAT_NAMES.join(", ")}, got "${String(value)}"`);
|
|
2357
|
-
opts.format = value;
|
|
2639
|
+
else if (/^(-o|--output-file)(=|$)/.test(a)) opts.outputFile = value("a file path");
|
|
2640
|
+
else if (/^--format(=|$)/.test(a)) {
|
|
2641
|
+
const format = value(`a value (one of ${FORMAT_NAMES.join(", ")})`);
|
|
2642
|
+
if (!isFormat(format)) throw new UsageError(`--format needs one of ${FORMAT_NAMES.join(", ")}, got "${format}"`);
|
|
2643
|
+
opts.format = format;
|
|
2358
2644
|
} else if (a === "-h" || a === "--help") opts.help = true;
|
|
2359
2645
|
else if (a === "-v" || a === "--version") opts.version = true;
|
|
2360
|
-
else if (
|
|
2361
|
-
const
|
|
2362
|
-
opts.timeout = Number(
|
|
2363
|
-
if (!Number.isInteger(opts.timeout) || opts.timeout <= 0) throw new UsageError(`--timeout needs a
|
|
2646
|
+
else if (/^--timeout(=|$)/.test(a)) {
|
|
2647
|
+
const ms = value("a value");
|
|
2648
|
+
opts.timeout = Number(ms);
|
|
2649
|
+
if (!Number.isInteger(opts.timeout) || opts.timeout <= 0 || opts.timeout > MAX_TIMEOUT_MS) throw new UsageError(`--timeout needs a whole number of milliseconds from 1 to ${MAX_TIMEOUT_MS} (about 24 days), got "${ms}"`);
|
|
2364
2650
|
} else if (a === "--probe" || a.startsWith("--probe=")) {
|
|
2365
|
-
const
|
|
2366
|
-
if (
|
|
2651
|
+
const probe = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2652
|
+
if (probe === void 0) throw new UsageError("--probe needs the arguments to probe");
|
|
2367
2653
|
let words;
|
|
2368
2654
|
try {
|
|
2369
|
-
words = shellSplit(
|
|
2655
|
+
words = shellSplit(probe);
|
|
2370
2656
|
} catch (error) {
|
|
2371
|
-
throw new UsageError(`--probe ${shellJoin([
|
|
2657
|
+
throw new UsageError(`--probe ${shellJoin([probe])} ${error instanceof Error ? error.message : String(error)}`);
|
|
2372
2658
|
}
|
|
2373
2659
|
if (words.length === 0) throw new UsageError("--probe needs the arguments to probe; use --bare for none");
|
|
2374
2660
|
opts.probes.push(words);
|
|
2375
2661
|
} else if (/^--(check|skip)(=|$)/.test(a)) {
|
|
2376
|
-
const flag = a
|
|
2377
|
-
const names = (
|
|
2662
|
+
const flag = flagOf(a);
|
|
2663
|
+
const names = value("a check name").split(",").map((n) => n.trim()).filter(Boolean);
|
|
2378
2664
|
if (names.length === 0) throw new UsageError(`${flag} needs a check name`);
|
|
2379
2665
|
(flag === "--skip" ? opts.skip : opts.checks).push(...names);
|
|
2380
2666
|
} else if (a.startsWith("-")) throw new UsageError(`unknown option "${a}"`);
|
|
@@ -2470,16 +2756,19 @@ Options:
|
|
|
2470
2756
|
summary or PR comment) or junit (XML for CI test reports)
|
|
2471
2757
|
--json Same as --format json
|
|
2472
2758
|
-o, --output-file <path>
|
|
2473
|
-
Write the --format report to a file (
|
|
2474
|
-
with parent folders
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2759
|
+
Write the --format report to a file (replaced atomically,
|
|
2760
|
+
keeping its mode, with parent folders created; a FIFO or
|
|
2761
|
+
/dev/stdout is written in place); the human report still
|
|
2762
|
+
prints. For a path that starts with -, use -o=<path>
|
|
2763
|
+
--timeout <ms> Kill a probe after this long (default 15000, at most
|
|
2764
|
+
2147483647, about 24 days). A command still running then
|
|
2765
|
+
(a server, a watcher) is judged on what it did so far,
|
|
2766
|
+
and later checks watch it for 3 s
|
|
2478
2767
|
-h, --help Show this help
|
|
2479
2768
|
-v, --version Show the version
|
|
2480
2769
|
|
|
2481
2770
|
Exit codes: 0 no failures, 1 a check failed (or warned, with --strict), 2 usage
|
|
2482
|
-
error or could not
|
|
2771
|
+
error, could not run, or could not write the --output-file report.
|
|
2483
2772
|
Runs the target in the current directory without a shell, with stdin closed
|
|
2484
2773
|
(the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
|
|
2485
2774
|
temporary HOME and a minimal environment. Only run programs you trust. When a
|
|
@@ -2533,8 +2822,14 @@ async function run(argv, io) {
|
|
|
2533
2822
|
err("cliprobe: Windows is not supported yet (the closed-pipe check needs mkfifo).\n");
|
|
2534
2823
|
return 2;
|
|
2535
2824
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2825
|
+
const problem = commandProblem(opts.command);
|
|
2826
|
+
if (problem !== void 0) {
|
|
2827
|
+
err(`cliprobe: ${safe(problem)}\n`);
|
|
2828
|
+
return 2;
|
|
2829
|
+
}
|
|
2830
|
+
const pathProblem = opts.outputFile === void 0 ? void 0 : reportPathProblem(opts.outputFile);
|
|
2831
|
+
if (pathProblem !== void 0) {
|
|
2832
|
+
err(`cliprobe: cannot write the report to ${safe(opts.outputFile ?? "")}: ${safe(pathProblem)}\n`);
|
|
2538
2833
|
return 2;
|
|
2539
2834
|
}
|
|
2540
2835
|
const own = opts.bare || opts.args.length > 0;
|
|
@@ -2575,14 +2870,17 @@ async function run(argv, io) {
|
|
|
2575
2870
|
};
|
|
2576
2871
|
const { color } = io;
|
|
2577
2872
|
if (opts.outputFile) {
|
|
2873
|
+
let failure;
|
|
2578
2874
|
try {
|
|
2579
|
-
writeReportFile(opts.outputFile, FORMATS[opts.format](report, { color: false }));
|
|
2875
|
+
await writeReportFile(opts.outputFile, FORMATS[opts.format](report, { color: false }));
|
|
2580
2876
|
} catch (error) {
|
|
2581
|
-
|
|
2582
|
-
err(`cliprobe: could not write ${safe(opts.outputFile)}: ${safe(reason)}\n`);
|
|
2583
|
-
return 2;
|
|
2877
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
2584
2878
|
}
|
|
2585
2879
|
out(FORMATS.human(report, { color }));
|
|
2880
|
+
if (failure !== void 0) {
|
|
2881
|
+
err(`cliprobe: could not write ${safe(opts.outputFile)}: ${safe(failure)}\n`);
|
|
2882
|
+
return 2;
|
|
2883
|
+
}
|
|
2586
2884
|
} else out(FORMATS[opts.format](report, { color }));
|
|
2587
2885
|
return exitCodeFor(results, opts.strict);
|
|
2588
2886
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), color and control codes leaking into pipes, hangs waiting on stdin, broken Ctrl-C handling, child processes left running after SIGTERM, a terminal left broken after Ctrl-C, and control characters from file names reaching your terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|