cliprobe 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -10
- package/dist/cli.js +138 -22
- package/package.json +7 -6
- package/schema.json +65 -0
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ When a program's output goes into a reader that stops early (`| head`, `grep -q`
|
|
|
75
75
|
|
|
76
76
|
In a census of the 100 most-downloaded npm packages that ship a command (119 commands, run offline in a throwaway container), **9 crashed this way every time**: esbuild, browserslist, update-browserslist-db, autoprefixer, husky, tsconfck, ts-jest, rolldown, and tsx on `--version`. Since then esbuild and browserslist have fixed it; the other seven still crashed when re-checked at their November 2026 versions. The best-known existing CLI auditor rated the first 8 as passing its SIGPIPE check. The same census found two commands that print color codes into a pipe (`giget --help`, `tsx --help`), five whose `--help` or `--version` waits for stdin (he, cssesc, ansi-html, webpack and webpack-dev-server), and no false failures: every `FAIL` reproduced by hand. (A census of `--help` and `--version` can't exercise ctrl-c, sigterm or control-chars, which need a command that keeps running or takes a path; their fixtures and real-tool tests are in `test/`.)
|
|
77
77
|
|
|
78
|
-
The other checks cover the rest of what goes wrong between a program and the thing reading it: color codes leaking into logs and agent transcripts, Ctrl-C that is ignored or ends in a stack trace, child processes left running after `kill` or `docker stop`, a terminal left with a hidden cursor or no line wrapping after Ctrl-C, and file names that can send escape sequences to your terminal.
|
|
78
|
+
The other checks cover the rest of what goes wrong between a program and the thing reading it: output lost on a full disk while the program exits 0, color codes leaking into logs and agent transcripts, Ctrl-C that is ignored or ends in a stack trace, child processes left running after `kill` or `docker stop`, a terminal left with a hidden cursor or no line wrapping after Ctrl-C, and file names that can send escape sequences to your terminal.
|
|
79
79
|
|
|
80
80
|
- **Evidence, never a score.** Every result is a verdict with the error line, the first stack frame in the target's own code, or the escape sequence that leaked.
|
|
81
81
|
- **No false fails.** A new check starts as warn-only and is calibrated against real tools before it may fail.
|
|
@@ -91,7 +91,7 @@ The other checks cover the rest of what goes wrong between a program and the thi
|
|
|
91
91
|
- [In CI](#in-ci)
|
|
92
92
|
- [JSON output](#json-output)
|
|
93
93
|
- [Stability](#stability)
|
|
94
|
-
- [Checks](#checks): [closed-pipe](#closed-pipe), [color](#color), [pipe-escapes](#pipe-escapes), [stdin](#stdin), [ctrl-c](#ctrl-c), [sigterm](#sigterm), [restore](#restore), [control-chars](#control-chars), [info checks](#info-checks)
|
|
94
|
+
- [Checks](#checks): [closed-pipe](#closed-pipe), [write-error](#write-error), [color](#color), [pipe-escapes](#pipe-escapes), [stdin](#stdin), [ctrl-c](#ctrl-c), [sigterm](#sigterm), [restore](#restore), [control-chars](#control-chars), [info checks](#info-checks)
|
|
95
95
|
- [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
|
|
96
96
|
- [Agent skill](#agent-skill)
|
|
97
97
|
- [Safety](#safety)
|
|
@@ -150,11 +150,11 @@ A probe runs `<command>` with its own args, in place of the args after the comma
|
|
|
150
150
|
|
|
151
151
|
## Exit codes
|
|
152
152
|
|
|
153
|
-
| Code | Meaning
|
|
154
|
-
| ---- |
|
|
155
|
-
| `0` | No check failed
|
|
156
|
-
| `1` | A check failed, or warned with `--strict`
|
|
157
|
-
| `2` | Usage error, the command could not run, or the
|
|
153
|
+
| Code | Meaning |
|
|
154
|
+
| ---- | ------------------------------------------------------------------------------------------------------------- |
|
|
155
|
+
| `0` | No check failed |
|
|
156
|
+
| `1` | A check failed, or warned with `--strict` |
|
|
157
|
+
| `2` | Usage error, the command could not run, or the report could not be written (to stdout or the `--output-file`) |
|
|
158
158
|
|
|
159
159
|
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.
|
|
160
160
|
|
|
@@ -225,7 +225,7 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
|
|
|
225
225
|
|
|
226
226
|
## Checks
|
|
227
227
|
|
|
228
|
-
A default run does the
|
|
228
|
+
A default run does the nine checks below: closed-pipe, write-error, color, pipe-escapes, stdin, ctrl-c, sigterm, restore and control-chars. Each one reports evidence, never a score. Two info checks, startup and baseline, run only when you name them with `--check`.
|
|
229
229
|
|
|
230
230
|
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c, sigterm and restore need. Give it after the command, or add it with `--probe` to keep the `--version` and `--help` probes in the same run; ctrl-c and sigterm only run the probes you name, and control-chars only those with `{fixture}`, so one run covers every check:
|
|
231
231
|
|
|
@@ -248,6 +248,18 @@ cliprobe runs the command twice: once normally, then with stdout set to a pipe w
|
|
|
248
248
|
|
|
249
249
|
Servers and watchers crash the same way. Among 38 watch and serve modes of popular npm tools, 8 died with `Error: write EPIPE` as soon as their stdout reader went away, each confirmed by hand: `jest --watchAll`, `live-server`, `mocha --watch`, `nodemon`, `parcel`, `rolldown -w`, `srvx` and `vite build --watch`. None was flagged falsely.
|
|
250
250
|
|
|
251
|
+
### write-error
|
|
252
|
+
|
|
253
|
+
cliprobe runs the command twice: once normally, then with stdout set to `/dev/full`, a Linux device where every write fails with `ENOSPC` (no space left on device), exactly as on a full disk. A program whose output never arrived must say so and exit non-zero, or `my-cli > report.json` on a full disk looks like success to the script, CI job or agent that ran it. GNU coreutils, git and Python do this. Node.js programs that print with `console.log` don't: it drops the failed write silently, and the program exits 0. Results:
|
|
254
|
+
|
|
255
|
+
| Verdict | Meaning |
|
|
256
|
+
| ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
257
|
+
| `PASS` | Exited non-zero (with its error as evidence) or was stopped by a signal, or, for a command that keeps running, kept running |
|
|
258
|
+
| `WARN` | Exited 0 though its output was lost, crashed with a stack trace, or hung |
|
|
259
|
+
| `SKIP` | Wrote nothing to stdout for this invocation (or before the timeout), or the system has no `/dev/full` (macOS) |
|
|
260
|
+
|
|
261
|
+
The check is new in 1.7 and only warns: it never fails before a census of real tools and the next major release. It runs on Linux only, since macOS has no `/dev/full`; run it in CI on a Linux runner, or in a container.
|
|
262
|
+
|
|
251
263
|
### color
|
|
252
264
|
|
|
253
265
|
cliprobe runs the command up to three times: into a pipe, under a real terminal (a pseudo-terminal through the system's `script` command, 80×24), and under a terminal with `NO_COLOR=1`. Every run gets `TERM=xterm-256color` and no `CI` variable, so a program can't pass just because the terminal type looks colorless, and color libraries that force color in CI don't fail it. Color codes in piped output end up in log files and agent transcripts as `\x1b[31m` noise. Results:
|
|
@@ -353,15 +365,18 @@ These report an observation with the verdict `INFO` and never fail. They run onl
|
|
|
353
365
|
|
|
354
366
|
## Fixing a failure in a Node.js CLI
|
|
355
367
|
|
|
356
|
-
**closed-pipe:** handle
|
|
368
|
+
**closed-pipe** and **write-error:** handle errors on stdout once, near your entry point. A closed pipe (`EPIPE`) means the reader has all it wants, so stop quietly; any other failed write, such as a full disk (`ENOSPC`), lost output, so say so and exit non-zero:
|
|
357
369
|
|
|
358
370
|
```js
|
|
359
371
|
process.stdout.on('error', (error) => {
|
|
360
372
|
if (error.code === 'EPIPE') process.exit(0);
|
|
361
|
-
|
|
373
|
+
console.error(`my-cli: cannot write output: ${error.message}`);
|
|
374
|
+
process.exit(1);
|
|
362
375
|
});
|
|
363
376
|
```
|
|
364
377
|
|
|
378
|
+
The same handler catches writes made with `console.log`, which otherwise drops a failed write silently and lets the program exit 0.
|
|
379
|
+
|
|
365
380
|
**color:** decide once, from the stream you write to:
|
|
366
381
|
|
|
367
382
|
```js
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, lstatSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
4
|
+
import { accessSync, closeSync, constants, existsSync, lstatSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import { delimiter, dirname, join, resolve, sep } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -325,6 +325,10 @@ function shellFallbackError(command, exitCode, stderr, path = process.env["PATH"
|
|
|
325
325
|
}
|
|
326
326
|
// src/core/run.ts
|
|
327
327
|
const STDERR_CAP = 65536;
|
|
328
|
+
/** A device on Linux that accepts no data: every write to it fails with ENOSPC. */
|
|
329
|
+
const DEV_FULL = "/dev/full";
|
|
330
|
+
/** Whether this system has /dev/full (Linux does; macOS doesn't). */
|
|
331
|
+
const hasDevFull = () => existsSync(DEV_FULL);
|
|
328
332
|
const STDOUT_CAP = 1048576;
|
|
329
333
|
/**
|
|
330
334
|
* The longest delay setTimeout takes (2^31 - 1 ms, about 24.8 days). Node turns
|
|
@@ -344,8 +348,9 @@ const delay = (ms) => new Promise((resolve) => {
|
|
|
344
348
|
* Runs one invocation. With `closedStdout`, stdout is the write end of a FIFO
|
|
345
349
|
* whose read end is closed before the program starts, so its first write to
|
|
346
350
|
* stdout fails (EPIPE, or SIGPIPE for programs that keep the default handler).
|
|
351
|
+
* With `fullStdout`, stdout is /dev/full, so every write fails with ENOSPC.
|
|
347
352
|
*/
|
|
348
|
-
function run$1(command, args, { closedStdout = false, timeout, env: overrides = {}, extraGroup, signal, stdin = "null", leftoversMs = 250 }) {
|
|
353
|
+
function run$1(command, args, { closedStdout = false, fullStdout = false, timeout, env: overrides = {}, extraGroup, signal, stdin = "null", leftoversMs = 250 }) {
|
|
349
354
|
const { dir, env: base } = sandbox();
|
|
350
355
|
const env = { ...base };
|
|
351
356
|
for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
|
|
@@ -357,7 +362,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
357
362
|
const reader = openSync(fifo, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
358
363
|
stdoutFd = openSync(fifo, constants.O_WRONLY | constants.O_NONBLOCK);
|
|
359
364
|
closeSync(reader);
|
|
360
|
-
}
|
|
365
|
+
} else if (fullStdout) stdoutFd = openSync(DEV_FULL, "w");
|
|
361
366
|
return new Promise((resolve) => {
|
|
362
367
|
let stdoutBytes = 0;
|
|
363
368
|
const stdoutChunks = [];
|
|
@@ -558,12 +563,12 @@ function firstLine(r) {
|
|
|
558
563
|
const err = lines(r.stderr)[0];
|
|
559
564
|
return err === void 0 ? "" : `stderr: ${err}`;
|
|
560
565
|
}
|
|
561
|
-
const exitText = (r) => r.signal ? `was stopped by ${r.signal}` : `exited ${r.exitCode}`;
|
|
566
|
+
const exitText$1 = (r) => r.signal ? `was stopped by ${r.signal}` : `exited ${r.exitCode}`;
|
|
562
567
|
/** Each describes one convention scripts and agents rely on; observations, never verdicts. */
|
|
563
568
|
function describeVersion(r) {
|
|
564
569
|
const out = lines(r.stdout.toString("utf8"));
|
|
565
570
|
if (r.exitCode !== 0) return {
|
|
566
|
-
reason: `${exitText(r)}; there may be no --version`,
|
|
571
|
+
reason: `${exitText$1(r)}; there may be no --version`,
|
|
567
572
|
evidence: firstLine(r)
|
|
568
573
|
};
|
|
569
574
|
if (out.length === 1) return {
|
|
@@ -587,9 +592,9 @@ function describeHelp(r) {
|
|
|
587
592
|
const noun = out.length === 1 ? "line" : "lines";
|
|
588
593
|
return { reason: `printed ${out.length} ${noun} to stdout and exited 0` };
|
|
589
594
|
}
|
|
590
|
-
if (out.length) return { reason: `printed help to stdout but ${exitText(r)}` };
|
|
591
|
-
if (err.length) return { reason: `printed help to stderr and ${exitText(r)}, so "--help | less" and agents reading stdout get nothing` };
|
|
592
|
-
return { reason: `printed nothing and ${exitText(r)}` };
|
|
595
|
+
if (out.length) return { reason: `printed help to stdout but ${exitText$1(r)}` };
|
|
596
|
+
if (err.length) return { reason: `printed help to stderr and ${exitText$1(r)}, so "--help | less" and agents reading stdout get nothing` };
|
|
597
|
+
return { reason: `printed nothing and ${exitText$1(r)}` };
|
|
593
598
|
}
|
|
594
599
|
function describeUnknownFlag(r) {
|
|
595
600
|
if (r.timedOut) return { reason: `still running after ${UNKNOWN_FLAG_TIMEOUT_MS / 1e3} s; it may have ignored the flag and started its default action` };
|
|
@@ -599,9 +604,9 @@ function describeUnknownFlag(r) {
|
|
|
599
604
|
evidence
|
|
600
605
|
} : { reason };
|
|
601
606
|
if (r.exitCode === 0) return withEvidence("exited 0, so a script cannot tell the flag was wrong");
|
|
602
|
-
if (lines(r.stdout.toString("utf8")).length) return withEvidence(`${exitText(r)}, but printed its message to stdout rather than stderr`);
|
|
603
|
-
if (lines(r.stderr).length) return withEvidence(`${exitText(r)} with its message on stderr`);
|
|
604
|
-
return { reason: `${exitText(r)} without saying why` };
|
|
607
|
+
if (lines(r.stdout.toString("utf8")).length) return withEvidence(`${exitText$1(r)}, but printed its message to stdout rather than stderr`);
|
|
608
|
+
if (lines(r.stderr).length) return withEvidence(`${exitText$1(r)} with its message on stderr`);
|
|
609
|
+
return { reason: `${exitText$1(r)} without saying why` };
|
|
605
610
|
}
|
|
606
611
|
async function probe(command, args, timeout, describe) {
|
|
607
612
|
const r = await run$1(command, args, { timeout });
|
|
@@ -711,7 +716,7 @@ const newWriteError = (base, closed) => ERROR_RE.test(closed.stderr) && !ERROR_R
|
|
|
711
716
|
* For a program that keeps running (a server, a watcher): there is no normal exit
|
|
712
717
|
* to compare with, but a crash once stdout is closed is still a crash.
|
|
713
718
|
*/
|
|
714
|
-
function judgeLongRunning(base, closed) {
|
|
719
|
+
function judgeLongRunning$1(base, closed) {
|
|
715
720
|
if (!closed.timedOut && newWriteError(base, closed)) return {
|
|
716
721
|
verdict: "fail",
|
|
717
722
|
reason: `crashed when stdout was closed, while a normal run kept running (exit ${closed.exitCode})`,
|
|
@@ -740,12 +745,12 @@ function judgeLongRunning(base, closed) {
|
|
|
740
745
|
};
|
|
741
746
|
}
|
|
742
747
|
/** Compares a normal run with a closed-stdout run of the same invocation. */
|
|
743
|
-
function judge(base, closed) {
|
|
748
|
+
function judge$1(base, closed) {
|
|
744
749
|
if (base.spawnError) return {
|
|
745
750
|
verdict: "error",
|
|
746
751
|
reason: `could not start: ${base.spawnError}`
|
|
747
752
|
};
|
|
748
|
-
if (base.timedOut) return judgeLongRunning(base, closed);
|
|
753
|
+
if (base.timedOut) return judgeLongRunning$1(base, closed);
|
|
749
754
|
if (base.stdoutBytes === 0) return noteFailedExit({
|
|
750
755
|
verdict: "skip",
|
|
751
756
|
reason: "wrote nothing to stdout, so a closed stdout is never touched"
|
|
@@ -791,7 +796,7 @@ async function closedPipe(command, args, ctx) {
|
|
|
791
796
|
return {
|
|
792
797
|
check: "closed-pipe",
|
|
793
798
|
invocation: [command, ...args],
|
|
794
|
-
...judge(base, closed),
|
|
799
|
+
...judge$1(base, closed),
|
|
795
800
|
baseline: {
|
|
796
801
|
exitCode: base.exitCode,
|
|
797
802
|
signal: base.signal,
|
|
@@ -2256,22 +2261,127 @@ async function stdinCheck(command, args, defaultProbe, ctx) {
|
|
|
2256
2261
|
finishedAfterCloseMs: proven && runs.closing ? runs.closing.durationMs - (runs.closeAfterMs ?? 1e3) : null
|
|
2257
2262
|
};
|
|
2258
2263
|
}
|
|
2264
|
+
const stdinCheckDefinition = {
|
|
2265
|
+
name: "stdin",
|
|
2266
|
+
kind: "check",
|
|
2267
|
+
summary: "waits for stdin when it is an open pipe, as agents and CI runners leave it",
|
|
2268
|
+
async run(target, ctx) {
|
|
2269
|
+
const results = [];
|
|
2270
|
+
for (const { args, own } of target.probes) results.push(await stdinCheck(target.command, args, !own, ctx));
|
|
2271
|
+
return results;
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
// src/checks/write-error.ts
|
|
2275
|
+
/** A stack trace that only the failed writes brought out. */
|
|
2276
|
+
const newTrace = (base, full) => TRACE_RE.test(full.stderr) && !TRACE_RE.test(base.stderr);
|
|
2277
|
+
/** The first line it printed to stderr, as evidence of how it reported the error. */
|
|
2278
|
+
const stderrLine = (r) => {
|
|
2279
|
+
const message = crashEvidence(r.stderr);
|
|
2280
|
+
return message ? { evidence: message } : {};
|
|
2281
|
+
};
|
|
2282
|
+
const EXITED_ZERO = "exited 0 though every write to stdout failed (no space left on device), so `> file` on a full disk looks like success";
|
|
2283
|
+
/** For a program that keeps running: only how it ends, if it ends, is judged. */
|
|
2284
|
+
function judgeLongRunning(base, full) {
|
|
2285
|
+
if (full.timedOut) return {
|
|
2286
|
+
verdict: "pass",
|
|
2287
|
+
reason: `${stillRunning(base.durationMs)}; with stdout on a full disk it kept running`
|
|
2288
|
+
};
|
|
2289
|
+
if (newTrace(base, full)) return {
|
|
2290
|
+
verdict: "warn",
|
|
2291
|
+
reason: "crashed with a stack trace when a write to stdout failed",
|
|
2292
|
+
evidence: crashEvidence(full.stderr)
|
|
2293
|
+
};
|
|
2294
|
+
if (full.exitCode === 0) return {
|
|
2295
|
+
verdict: "warn",
|
|
2296
|
+
reason: EXITED_ZERO
|
|
2297
|
+
};
|
|
2298
|
+
return {
|
|
2299
|
+
verdict: "pass",
|
|
2300
|
+
reason: `stopped when a write to stdout failed (${exitText(full)})`,
|
|
2301
|
+
...stderrLine(full)
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
2304
|
+
const exitText = (r) => r.signal ? `stopped by ${r.signal}` : `exit ${r.exitCode}`;
|
|
2305
|
+
/**
|
|
2306
|
+
* Compares a normal run with a run whose stdout is /dev/full, where every write
|
|
2307
|
+
* fails with ENOSPC. A careful program says so and exits non-zero, as GNU
|
|
2308
|
+
* coreutils, git and Python do. Warn-only until a census shows no false warns.
|
|
2309
|
+
*/
|
|
2310
|
+
function judge(base, full) {
|
|
2311
|
+
if (base.spawnError) return {
|
|
2312
|
+
verdict: "error",
|
|
2313
|
+
reason: `could not start: ${base.spawnError}`
|
|
2314
|
+
};
|
|
2315
|
+
if (base.stdoutBytes === 0) return noteFailedExit({
|
|
2316
|
+
verdict: "skip",
|
|
2317
|
+
reason: base.timedOut ? `${stillRunning(base.durationMs)} without writing to stdout, so a failed write never happened` : "wrote nothing to stdout, so a failed write never happens"
|
|
2318
|
+
}, base);
|
|
2319
|
+
if (!full) return {
|
|
2320
|
+
verdict: "skip",
|
|
2321
|
+
reason: "no /dev/full on this system (it needs Linux)"
|
|
2322
|
+
};
|
|
2323
|
+
if (base.timedOut) return judgeLongRunning(base, full);
|
|
2324
|
+
if (full.timedOut) return {
|
|
2325
|
+
verdict: "warn",
|
|
2326
|
+
reason: "hung when a write to stdout failed",
|
|
2327
|
+
...stderrLine(full)
|
|
2328
|
+
};
|
|
2329
|
+
if (newTrace(base, full)) return {
|
|
2330
|
+
verdict: "warn",
|
|
2331
|
+
reason: `crashed with a stack trace when a write to stdout failed (${exitText(full)})`,
|
|
2332
|
+
evidence: crashEvidence(full.stderr)
|
|
2333
|
+
};
|
|
2334
|
+
if (full.exitCode === 0) return {
|
|
2335
|
+
verdict: "warn",
|
|
2336
|
+
reason: EXITED_ZERO
|
|
2337
|
+
};
|
|
2338
|
+
return {
|
|
2339
|
+
verdict: "pass",
|
|
2340
|
+
reason: `reported the failed write (${exitText(full)})`,
|
|
2341
|
+
...stderrLine(full)
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
async function writeError(command, args, ctx) {
|
|
2345
|
+
const base = await run$1(command, args, { timeout: probeTimeout(ctx, command, args) });
|
|
2346
|
+
if (base.timedOut) markLongRunning(ctx, command, args);
|
|
2347
|
+
const full = !base.spawnError && base.stdoutBytes > 0 && hasDevFull() ? await run$1(command, args, {
|
|
2348
|
+
fullStdout: true,
|
|
2349
|
+
timeout: base.timedOut ? Math.min(ctx.timeout, LONG_RUN_WINDOW_MS) : ctx.timeout
|
|
2350
|
+
}) : void 0;
|
|
2351
|
+
return {
|
|
2352
|
+
check: "write-error",
|
|
2353
|
+
invocation: [command, ...args],
|
|
2354
|
+
...judge(base, full),
|
|
2355
|
+
baseline: {
|
|
2356
|
+
exitCode: base.exitCode,
|
|
2357
|
+
signal: base.signal,
|
|
2358
|
+
stdoutBytes: base.stdoutBytes
|
|
2359
|
+
},
|
|
2360
|
+
full: full ? {
|
|
2361
|
+
exitCode: full.exitCode,
|
|
2362
|
+
signal: full.signal,
|
|
2363
|
+
timedOut: full.timedOut,
|
|
2364
|
+
stderr: full.stderr.slice(-2e3)
|
|
2365
|
+
} : null
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2259
2368
|
// src/checks/index.ts
|
|
2260
2369
|
/** Every check, in the order they run and are reported. */
|
|
2261
2370
|
const CHECKS = [
|
|
2262
2371
|
closedPipeCheck,
|
|
2263
|
-
colorCheck,
|
|
2264
|
-
pipeEscapesCheck,
|
|
2265
2372
|
{
|
|
2266
|
-
name: "
|
|
2373
|
+
name: "write-error",
|
|
2267
2374
|
kind: "check",
|
|
2268
|
-
summary: "
|
|
2375
|
+
summary: "exits 0 or crashes when writing stdout fails (a full disk)",
|
|
2269
2376
|
async run(target, ctx) {
|
|
2270
2377
|
const results = [];
|
|
2271
|
-
for (const { args
|
|
2378
|
+
for (const { args } of target.probes) results.push(await writeError(target.command, args, ctx));
|
|
2272
2379
|
return results;
|
|
2273
2380
|
}
|
|
2274
2381
|
},
|
|
2382
|
+
colorCheck,
|
|
2383
|
+
pipeEscapesCheck,
|
|
2384
|
+
stdinCheckDefinition,
|
|
2275
2385
|
ctrlCCheck,
|
|
2276
2386
|
sigtermCheck,
|
|
2277
2387
|
restoreCheck,
|
|
@@ -2853,6 +2963,11 @@ Checks:
|
|
|
2853
2963
|
piped into a reader that quits early (head, grep -q, an agent).
|
|
2854
2964
|
A well-behaved program exits quietly; a buggy one crashes with
|
|
2855
2965
|
an EPIPE error and a stack trace.
|
|
2966
|
+
write-error Runs the command with stdout on /dev/full, where every write
|
|
2967
|
+
fails as on a full disk (Linux only; skipped elsewhere). Warns
|
|
2968
|
+
if it exits 0 anyway, so the lost output looks like success,
|
|
2969
|
+
crashes with a stack trace, or hangs. A careful program prints
|
|
2970
|
+
the error and exits non-zero.
|
|
2856
2971
|
color Runs the command into a pipe, then under a terminal, then under
|
|
2857
2972
|
a terminal with NO_COLOR=1. Fails if color codes reach a pipe;
|
|
2858
2973
|
warns if color goes to a piped stderr or NO_COLOR is ignored.
|
|
@@ -2927,7 +3042,7 @@ Options:
|
|
|
2927
3042
|
-v, --version Show the version
|
|
2928
3043
|
|
|
2929
3044
|
Exit codes: 0 no failures, 1 a check failed (or warned, with --strict), 2 usage
|
|
2930
|
-
error, could not run, or could not write the
|
|
3045
|
+
error, could not run, or could not write the report (to stdout or the file).
|
|
2931
3046
|
Runs the target in the current directory without a shell, with stdin closed
|
|
2932
3047
|
(the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
|
|
2933
3048
|
temporary HOME and a minimal environment. Only run programs you trust. When a
|
|
@@ -3046,7 +3161,8 @@ async function run(argv, io) {
|
|
|
3046
3161
|
// src/cli/main.ts
|
|
3047
3162
|
process.stdout.on("error", (error) => {
|
|
3048
3163
|
if (error.code === "EPIPE") process.exit(process.exitCode ?? 0);
|
|
3049
|
-
|
|
3164
|
+
process.stderr.write(`cliprobe: cannot write the report: ${error.message}\n`);
|
|
3165
|
+
process.exit(2);
|
|
3050
3166
|
});
|
|
3051
3167
|
handleInterrupts();
|
|
3052
3168
|
process.exitCode = await run(process.argv.slice(2), {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.
|
|
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.",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), output lost on a full disk while exiting 0, 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": {
|
|
7
7
|
"cliprobe": "dist/cli.js"
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"cli",
|
|
35
35
|
"testing",
|
|
36
36
|
"epipe",
|
|
37
|
+
"enospc",
|
|
37
38
|
"sigpipe",
|
|
38
39
|
"broken-pipe",
|
|
39
40
|
"black-box",
|
|
@@ -87,20 +88,20 @@
|
|
|
87
88
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
88
89
|
"@types/markdown-it": "^14.2.0",
|
|
89
90
|
"@types/node": "^22.20.5",
|
|
90
|
-
"@vitest/coverage-v8": "^5.1.
|
|
91
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
91
92
|
"ajv": "^8.20.0",
|
|
92
93
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
93
94
|
"fast-xml-parser": "^5.12.1",
|
|
94
95
|
"husky": "^9.1.7",
|
|
95
96
|
"markdown-it": "^15.0.3",
|
|
96
|
-
"oxlint": "^1.
|
|
97
|
-
"oxlint-tsgolint": "^7.0.
|
|
97
|
+
"oxlint": "^1.94.0",
|
|
98
|
+
"oxlint-tsgolint": "^7.0.2008",
|
|
98
99
|
"prettier": "^3.10.1",
|
|
99
100
|
"publint": "^0.3.25",
|
|
100
101
|
"semantic-release": "^26.0.1",
|
|
101
102
|
"tsdown": "^0.23.1",
|
|
102
103
|
"typescript": "^7.0.2",
|
|
103
|
-
"vitest": "^5.1.
|
|
104
|
+
"vitest": "^5.1.1"
|
|
104
105
|
},
|
|
105
106
|
"packageManager": "pnpm@12.14.0"
|
|
106
107
|
}
|
package/schema.json
CHANGED
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"checkName": {
|
|
74
74
|
"enum": [
|
|
75
75
|
"closed-pipe",
|
|
76
|
+
"write-error",
|
|
76
77
|
"color",
|
|
77
78
|
"pipe-escapes",
|
|
78
79
|
"stdin",
|
|
@@ -153,6 +154,22 @@
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
},
|
|
157
|
+
{
|
|
158
|
+
"if": {
|
|
159
|
+
"properties": {
|
|
160
|
+
"check": {
|
|
161
|
+
"const": "write-error"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"then": {
|
|
166
|
+
"properties": {
|
|
167
|
+
"details": {
|
|
168
|
+
"$ref": "#/$defs/details.write-error"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
156
173
|
{
|
|
157
174
|
"if": {
|
|
158
175
|
"properties": {
|
|
@@ -347,6 +364,54 @@
|
|
|
347
364
|
}
|
|
348
365
|
}
|
|
349
366
|
},
|
|
367
|
+
"details.write-error": {
|
|
368
|
+
"type": "object",
|
|
369
|
+
"description": "A normal run into a pipe, then a run with stdout on /dev/full, where every write fails with ENOSPC.",
|
|
370
|
+
"required": ["baseline", "full"],
|
|
371
|
+
"properties": {
|
|
372
|
+
"baseline": {
|
|
373
|
+
"type": "object",
|
|
374
|
+
"description": "The normal run.",
|
|
375
|
+
"required": ["exitCode", "signal", "stdoutBytes"],
|
|
376
|
+
"properties": {
|
|
377
|
+
"exitCode": {
|
|
378
|
+
"type": ["integer", "null"],
|
|
379
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
380
|
+
},
|
|
381
|
+
"signal": {
|
|
382
|
+
"type": ["string", "null"],
|
|
383
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
384
|
+
},
|
|
385
|
+
"stdoutBytes": {
|
|
386
|
+
"type": "integer",
|
|
387
|
+
"minimum": 0
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
"full": {
|
|
392
|
+
"type": ["object", "null"],
|
|
393
|
+
"description": "The run with stdout on /dev/full; null if it did not run (nothing written to stdout, the program could not start, or no /dev/full, as on macOS).",
|
|
394
|
+
"required": ["exitCode", "signal", "timedOut", "stderr"],
|
|
395
|
+
"properties": {
|
|
396
|
+
"exitCode": {
|
|
397
|
+
"type": ["integer", "null"],
|
|
398
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
399
|
+
},
|
|
400
|
+
"signal": {
|
|
401
|
+
"type": ["string", "null"],
|
|
402
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
403
|
+
},
|
|
404
|
+
"timedOut": {
|
|
405
|
+
"type": "boolean"
|
|
406
|
+
},
|
|
407
|
+
"stderr": {
|
|
408
|
+
"type": "string",
|
|
409
|
+
"description": "What it printed to stderr, up to 64 KiB."
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
350
415
|
"details.color": {
|
|
351
416
|
"type": "object",
|
|
352
417
|
"description": "Runs into a pipe, under a terminal and under a terminal with NO_COLOR=1; null for a run that was not needed.",
|