cliprobe 1.4.1 → 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 +22 -20
- package/dist/cli.js +209 -41
- 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 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. That makes cliprobe usable as a CI gate.
|
|
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
|
|
|
@@ -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. */
|
|
@@ -325,6 +326,11 @@ function shellFallbackError(command, exitCode, stderr, path = process.env["PATH"
|
|
|
325
326
|
// src/core/run.ts
|
|
326
327
|
const STDERR_CAP = 65536;
|
|
327
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;
|
|
328
334
|
/** How often the process table is read while the program runs, to learn its descendants. */
|
|
329
335
|
const TREE_POLL_MS = 200;
|
|
330
336
|
/** How long to wait for the output pipes to close once everything the run started is gone. */
|
|
@@ -446,7 +452,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
446
452
|
timedOut = true;
|
|
447
453
|
recordTree();
|
|
448
454
|
killRun();
|
|
449
|
-
}, timeout);
|
|
455
|
+
}, Math.min(timeout, MAX_TIMEOUT_MS));
|
|
450
456
|
const signalTimer = signal && setTimeout(() => {
|
|
451
457
|
if (exited || proc.pid === void 0) return;
|
|
452
458
|
recordTree();
|
|
@@ -2423,20 +2429,144 @@ const FORMATS = {
|
|
|
2423
2429
|
junit: formatJunit
|
|
2424
2430
|
};
|
|
2425
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
|
+
}
|
|
2426
2471
|
/**
|
|
2427
|
-
*
|
|
2428
|
-
*
|
|
2429
|
-
*
|
|
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.
|
|
2430
2475
|
*/
|
|
2431
|
-
function
|
|
2432
|
-
|
|
2433
|
-
|
|
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
|
+
}
|
|
2513
|
+
/**
|
|
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".
|
|
2516
|
+
*/
|
|
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) {
|
|
2529
|
+
try {
|
|
2530
|
+
reportTarget(path);
|
|
2531
|
+
return;
|
|
2532
|
+
} catch (error) {
|
|
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 }));
|
|
2434
2560
|
try {
|
|
2435
|
-
|
|
2436
|
-
|
|
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);
|
|
2437
2565
|
} catch (error) {
|
|
2438
|
-
|
|
2439
|
-
throw error;
|
|
2566
|
+
await rm(temp, { force: true }).catch(() => void 0);
|
|
2567
|
+
throw new Error(describeWriteError(error), { cause: error });
|
|
2568
|
+
} finally {
|
|
2569
|
+
unregister();
|
|
2440
2570
|
}
|
|
2441
2571
|
}
|
|
2442
2572
|
// src/version.ts
|
|
@@ -2452,6 +2582,27 @@ function readVersion() {
|
|
|
2452
2582
|
const VERSION = readVersion();
|
|
2453
2583
|
// src/cli/args.ts
|
|
2454
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;
|
|
2455
2606
|
function parseArgs(argv) {
|
|
2456
2607
|
const opts = {
|
|
2457
2608
|
format: "human",
|
|
@@ -2473,37 +2624,43 @@ function parseArgs(argv) {
|
|
|
2473
2624
|
[opts.command, ...opts.args] = argv.slice(i + 1);
|
|
2474
2625
|
break;
|
|
2475
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
|
+
};
|
|
2476
2636
|
if (a === "--json") opts.format = "json";
|
|
2477
2637
|
else if (a === "--bare") opts.bare = true;
|
|
2478
2638
|
else if (a === "--strict") opts.strict = true;
|
|
2479
|
-
else if (
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2485
|
-
if (value === void 0 || !isFormat(value)) throw new UsageError(`--format needs one of ${FORMAT_NAMES.join(", ")}, got "${String(value)}"`);
|
|
2486
|
-
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;
|
|
2487
2644
|
} else if (a === "-h" || a === "--help") opts.help = true;
|
|
2488
2645
|
else if (a === "-v" || a === "--version") opts.version = true;
|
|
2489
|
-
else if (
|
|
2490
|
-
const
|
|
2491
|
-
opts.timeout = Number(
|
|
2492
|
-
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}"`);
|
|
2493
2650
|
} else if (a === "--probe" || a.startsWith("--probe=")) {
|
|
2494
|
-
const
|
|
2495
|
-
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");
|
|
2496
2653
|
let words;
|
|
2497
2654
|
try {
|
|
2498
|
-
words = shellSplit(
|
|
2655
|
+
words = shellSplit(probe);
|
|
2499
2656
|
} catch (error) {
|
|
2500
|
-
throw new UsageError(`--probe ${shellJoin([
|
|
2657
|
+
throw new UsageError(`--probe ${shellJoin([probe])} ${error instanceof Error ? error.message : String(error)}`);
|
|
2501
2658
|
}
|
|
2502
2659
|
if (words.length === 0) throw new UsageError("--probe needs the arguments to probe; use --bare for none");
|
|
2503
2660
|
opts.probes.push(words);
|
|
2504
2661
|
} else if (/^--(check|skip)(=|$)/.test(a)) {
|
|
2505
|
-
const flag = a
|
|
2506
|
-
const names = (
|
|
2662
|
+
const flag = flagOf(a);
|
|
2663
|
+
const names = value("a check name").split(",").map((n) => n.trim()).filter(Boolean);
|
|
2507
2664
|
if (names.length === 0) throw new UsageError(`${flag} needs a check name`);
|
|
2508
2665
|
(flag === "--skip" ? opts.skip : opts.checks).push(...names);
|
|
2509
2666
|
} else if (a.startsWith("-")) throw new UsageError(`unknown option "${a}"`);
|
|
@@ -2599,16 +2756,19 @@ Options:
|
|
|
2599
2756
|
summary or PR comment) or junit (XML for CI test reports)
|
|
2600
2757
|
--json Same as --format json
|
|
2601
2758
|
-o, --output-file <path>
|
|
2602
|
-
Write the --format report to a file (
|
|
2603
|
-
with parent folders
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
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
|
|
2607
2767
|
-h, --help Show this help
|
|
2608
2768
|
-v, --version Show the version
|
|
2609
2769
|
|
|
2610
2770
|
Exit codes: 0 no failures, 1 a check failed (or warned, with --strict), 2 usage
|
|
2611
|
-
error or could not
|
|
2771
|
+
error, could not run, or could not write the --output-file report.
|
|
2612
2772
|
Runs the target in the current directory without a shell, with stdin closed
|
|
2613
2773
|
(the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
|
|
2614
2774
|
temporary HOME and a minimal environment. Only run programs you trust. When a
|
|
@@ -2667,6 +2827,11 @@ async function run(argv, io) {
|
|
|
2667
2827
|
err(`cliprobe: ${safe(problem)}\n`);
|
|
2668
2828
|
return 2;
|
|
2669
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`);
|
|
2833
|
+
return 2;
|
|
2834
|
+
}
|
|
2670
2835
|
const own = opts.bare || opts.args.length > 0;
|
|
2671
2836
|
const probes = [...mainProbe(opts).map((args) => ({
|
|
2672
2837
|
args,
|
|
@@ -2705,14 +2870,17 @@ async function run(argv, io) {
|
|
|
2705
2870
|
};
|
|
2706
2871
|
const { color } = io;
|
|
2707
2872
|
if (opts.outputFile) {
|
|
2873
|
+
let failure;
|
|
2708
2874
|
try {
|
|
2709
|
-
writeReportFile(opts.outputFile, FORMATS[opts.format](report, { color: false }));
|
|
2875
|
+
await writeReportFile(opts.outputFile, FORMATS[opts.format](report, { color: false }));
|
|
2710
2876
|
} catch (error) {
|
|
2711
|
-
|
|
2712
|
-
err(`cliprobe: could not write ${safe(opts.outputFile)}: ${safe(reason)}\n`);
|
|
2713
|
-
return 2;
|
|
2877
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
2714
2878
|
}
|
|
2715
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
|
+
}
|
|
2716
2884
|
} else out(FORMATS[opts.format](report, { color }));
|
|
2717
2885
|
return exitCodeFor(results, opts.strict);
|
|
2718
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": {
|