cliprobe 1.1.0 → 1.2.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 +45 -35
- package/dist/cli.js +120 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,51 +27,53 @@
|
|
|
27
27
|
---
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
-
npx cliprobe --
|
|
30
|
+
npx cliprobe -- tsx
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```
|
|
34
|
-
cliprobe 1.
|
|
34
|
+
cliprobe 1.2.0: closed-pipe, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for tsx
|
|
35
35
|
|
|
36
36
|
closed-pipe
|
|
37
|
-
FAIL
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Error: Command failed: .../esbuild --help (at node_modules/esbuild/bin/esbuild:222:28)
|
|
37
|
+
FAIL tsx --version crashed when stdout was closed (exit 0 -> 1)
|
|
38
|
+
Error: write EPIPE (at node_modules/tsx/dist/cli.mjs:53:36962)
|
|
39
|
+
PASS tsx --help exited quietly
|
|
41
40
|
|
|
42
41
|
color
|
|
43
|
-
PASS
|
|
44
|
-
|
|
42
|
+
PASS tsx --version no color in a pipe or in a terminal
|
|
43
|
+
FAIL tsx --help printed color codes into a pipe
|
|
44
|
+
stdout line 5: \x1b[1mUsage:\x1b[22m
|
|
45
45
|
|
|
46
46
|
pipe-escapes
|
|
47
|
-
PASS
|
|
48
|
-
PASS
|
|
47
|
+
PASS tsx --version no cursor, erase, hyperlink, title or redraw codes in a pipe
|
|
48
|
+
PASS tsx --help no cursor, erase, hyperlink, title or redraw codes in a pipe
|
|
49
49
|
|
|
50
50
|
stdin
|
|
51
|
-
PASS
|
|
52
|
-
PASS
|
|
51
|
+
PASS tsx --version finished without waiting for stdin
|
|
52
|
+
PASS tsx --help finished without waiting for stdin
|
|
53
53
|
|
|
54
54
|
ctrl-c
|
|
55
|
-
SKIP
|
|
55
|
+
SKIP tsx needs a probe that keeps running, such as a watch or serve command (--probe), or --bare
|
|
56
56
|
|
|
57
57
|
sigterm
|
|
58
|
-
SKIP
|
|
58
|
+
SKIP tsx needs a probe that keeps running, such as a watch or serve command (--probe), or --bare
|
|
59
59
|
|
|
60
60
|
restore
|
|
61
|
-
PASS
|
|
62
|
-
PASS
|
|
61
|
+
PASS tsx --version left no terminal mode switched on when it exited
|
|
62
|
+
PASS tsx --help left no terminal mode switched on when it exited
|
|
63
63
|
|
|
64
64
|
control-chars
|
|
65
|
-
SKIP
|
|
65
|
+
SKIP tsx no {fixture} in the arguments; add a probe that takes a path, e.g. --probe "ls {fixture}"
|
|
66
66
|
|
|
67
67
|
2 failed, 0 warned, 8 passed, 3 skipped
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
<sub>tsx 4.23.15, run offline in a container in November 2026.</sub>
|
|
71
|
+
|
|
70
72
|
## Why cliprobe?
|
|
71
73
|
|
|
72
74
|
When a program's output goes into a reader that stops early (`| head`, `grep -q`, a closed agent pipe), its next write to stdout fails. A well-behaved program exits quietly. Many Node.js CLIs instead crash with `Error: write EPIPE`, a stack trace, and exit code 1. That breaks scripts running under `set -o pipefail` and confuses agents that read stderr.
|
|
73
75
|
|
|
74
|
-
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`. 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/`.)
|
|
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/`.)
|
|
75
77
|
|
|
76
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.
|
|
77
79
|
|
|
@@ -114,6 +116,7 @@ npm install --save-dev cliprobe # or: pnpm add -D cliprobe
|
|
|
114
116
|
```sh
|
|
115
117
|
npx cliprobe -- <command> # probes "<command> --version" and "<command> --help"
|
|
116
118
|
npx cliprobe -- <command> [args...] # probes exactly this invocation
|
|
119
|
+
npx cliprobe --probe "watch app.ts" -- tsx # adds a probe: --version, --help and "watch app.ts"
|
|
117
120
|
npx cliprobe -- node ./dist/cli.js list # test your own CLI before publishing
|
|
118
121
|
npx cliprobe --json -- <command> # machine-readable results
|
|
119
122
|
npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; human report on stdout
|
|
@@ -123,18 +126,19 @@ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, onl
|
|
|
123
126
|
npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings fail too, except restore's
|
|
124
127
|
```
|
|
125
128
|
|
|
126
|
-
| Option | Meaning
|
|
127
|
-
| ---------------------------- |
|
|
128
|
-
| `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote
|
|
129
|
-
| `--
|
|
130
|
-
| `--
|
|
131
|
-
| `--
|
|
132
|
-
| `--
|
|
133
|
-
| `--
|
|
134
|
-
|
|
|
135
|
-
| `--
|
|
136
|
-
|
|
|
137
|
-
| `-
|
|
129
|
+
| Option | Meaning |
|
|
130
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
|
|
132
|
+
| `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards) |
|
|
133
|
+
| `--check <name>` | Run only this check; repeat it or use commas for several |
|
|
134
|
+
| `--skip <name>` | Leave this check out; repeat it or use commas for several |
|
|
135
|
+
| `--strict` | Exit 1 on a warning too, not only on a failure |
|
|
136
|
+
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports) |
|
|
137
|
+
| `--json` | Same as `--format json` |
|
|
138
|
+
| `-o`, `--output-file <path>` | Write the `--format` report to a file (atomically, creating parent folders); the human report still prints |
|
|
139
|
+
| `--timeout <ms>` | Kill a probe after this long (default 15000); a command still running then is judged on what it did so far |
|
|
140
|
+
| `-h`, `--help` | Show help |
|
|
141
|
+
| `-v`, `--version` | Show the version |
|
|
138
142
|
|
|
139
143
|
## Exit codes
|
|
140
144
|
|
|
@@ -148,7 +152,7 @@ A command that isn't on `PATH` is reported once, before any check runs, with exi
|
|
|
148
152
|
|
|
149
153
|
## In CI
|
|
150
154
|
|
|
151
|
-
A failed check exits 1, so the step fails. Warnings don't fail it unless you add `--strict`; with `--strict`, `--skip` leaves out a check whose warning you accept. In GitHub Actions, write a Markdown report to the job summary while the log keeps the human report:
|
|
155
|
+
A failed check exits 1, so the step fails. Warnings don't fail it unless you add `--strict`; with `--strict`, `--skip` leaves out a check whose warning you accept. Add `--probe` for a command that keeps running and one with `{fixture}`, so a single step covers every check. In GitHub Actions, write a Markdown report to the job summary while the log keeps the human report:
|
|
152
156
|
|
|
153
157
|
```yaml
|
|
154
158
|
- name: Check the CLI for terminal-edge bugs
|
|
@@ -215,7 +219,13 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
|
|
|
215
219
|
|
|
216
220
|
A default run does the eight checks below: closed-pipe, 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`.
|
|
217
221
|
|
|
218
|
-
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c, sigterm and restore need.
|
|
222
|
+
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:
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
npx cliprobe --probe "serve --port 0" --probe "scan {fixture}" -- my-cli
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The other checks judge it on what it did before the timeout (`--timeout`, 15 seconds by default): a crash once stdout is closed still fails, color or a spinner in a pipe still counts, and stdin is skipped. The timeout is paid once: after the first check sees the command still running, the others watch it for 3 seconds.
|
|
219
229
|
|
|
220
230
|
### closed-pipe
|
|
221
231
|
|
|
@@ -308,7 +318,7 @@ It only warns: a terminal left in the wrong mode is a nuisance you can undo, not
|
|
|
308
318
|
|
|
309
319
|
### control-chars
|
|
310
320
|
|
|
311
|
-
Put `{fixture}` in the arguments where your command takes a path, for example `npx cliprobe -- ls {fixture}
|
|
321
|
+
Put `{fixture}` in the arguments where your command takes a path, for example `npx cliprobe -- ls {fixture}`, `npx cliprobe -- node ./dist/cli.js scan --dir={fixture}` or `npx cliprobe --probe "scan {fixture}" -- my-cli`. cliprobe replaces it with a temporary directory of file names holding escape sequences (one sets the window title, one clears the screen), a C1 control character, a carriage return, a newline and a bidirectional override. It runs the command under a terminal and looks for those characters, unescaped, in what reaches it. A file name that can clear someone's screen or retitle their window is a terminal injection, the same bug class as the `ls`/`find` escaping that GNU coreutils added years ago. Reports show `{fixture}`, never the temporary path, and the directory is removed afterwards. Results:
|
|
312
322
|
|
|
313
323
|
| Verdict | Meaning |
|
|
314
324
|
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -321,7 +331,7 @@ Only the terminal run is judged. Into a pipe, `ls` and `find` print names exactl
|
|
|
321
331
|
|
|
322
332
|
### Info checks
|
|
323
333
|
|
|
324
|
-
These report an observation with the verdict `INFO` and never fail. They run only when named, for example `--check startup,baseline`. With
|
|
334
|
+
These report an observation with the verdict `INFO` and never fail. They run only when named, for example `--check startup,baseline`. With args after the command, those args are treated as the program (`--probe` adds probes, not a different program): `npx cliprobe --check baseline -- node ./dist/cli.js` probes `node ./dist/cli.js --version`, and so on.
|
|
325
335
|
|
|
326
336
|
**startup**. The median wall time over 5 runs, after one warm-up, of `<command> --version`, or of the probe exactly as given. It's skipped if that invocation exits non-zero.
|
|
327
337
|
|
|
@@ -409,7 +419,7 @@ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+
|
|
|
409
419
|
|
|
410
420
|
## Safety
|
|
411
421
|
|
|
412
|
-
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, 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 kills whatever a program leaves running in its group when it exits under the sigterm check. 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.
|
|
422
|
+
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 kills whatever a program leaves running in its group when it exits under the sigterm check. 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.
|
|
413
423
|
|
|
414
424
|
## Contributing
|
|
415
425
|
|
package/dist/cli.js
CHANGED
|
@@ -318,7 +318,8 @@ const baselineCheck = {
|
|
|
318
318
|
kind: "info",
|
|
319
319
|
summary: "--version prints one line, --help goes to stdout, an unknown flag exits non-zero",
|
|
320
320
|
async run(target, ctx) {
|
|
321
|
-
const
|
|
321
|
+
const [first] = target.probes;
|
|
322
|
+
const prefix = first?.own ? first.args : [];
|
|
322
323
|
return [
|
|
323
324
|
await probe(target.command, [...prefix, "--version"], ctx.timeout, describeVersion),
|
|
324
325
|
await probe(target.command, [...prefix, "--help"], ctx.timeout, describeHelp),
|
|
@@ -478,7 +479,7 @@ const closedPipeCheck = {
|
|
|
478
479
|
summary: "crashes or hangs when stdout is closed early (| head, grep -q, an agent)",
|
|
479
480
|
async run(target, ctx) {
|
|
480
481
|
const results = [];
|
|
481
|
-
for (const args of target.
|
|
482
|
+
for (const { args } of target.probes) results.push(await closedPipe(target.command, args, ctx));
|
|
482
483
|
return results;
|
|
483
484
|
}
|
|
484
485
|
};
|
|
@@ -1003,7 +1004,7 @@ const colorCheck = {
|
|
|
1003
1004
|
summary: "prints color codes into pipes, or ignores NO_COLOR in a terminal",
|
|
1004
1005
|
async run(target, ctx) {
|
|
1005
1006
|
const results = [];
|
|
1006
|
-
for (const args of target.
|
|
1007
|
+
for (const { args } of target.probes) results.push(await color(target.command, args, ctx));
|
|
1007
1008
|
return results;
|
|
1008
1009
|
}
|
|
1009
1010
|
};
|
|
@@ -1142,7 +1143,7 @@ const evidenceFor = (names) => `file names printed raw: ${names.map((h) => h.nam
|
|
|
1142
1143
|
function judgeControlChars(runs) {
|
|
1143
1144
|
if (!runs.usesFixture) return {
|
|
1144
1145
|
verdict: "skip",
|
|
1145
|
-
reason: "no {fixture} in the arguments;
|
|
1146
|
+
reason: "no {fixture} in the arguments; add a probe that takes a path, e.g. --probe \"ls {fixture}\""
|
|
1146
1147
|
};
|
|
1147
1148
|
const { pipe, tty } = runs;
|
|
1148
1149
|
if (pipe?.spawnError) return {
|
|
@@ -1231,8 +1232,9 @@ const controlCharsCheck = {
|
|
|
1231
1232
|
terminalRaw: [],
|
|
1232
1233
|
pipeRaw: []
|
|
1233
1234
|
}];
|
|
1235
|
+
const dir = target.fixtureDir;
|
|
1234
1236
|
const results = [];
|
|
1235
|
-
for (const args of target.
|
|
1237
|
+
for (const { args } of target.probes.filter((p) => p.args.some((a) => a.includes(dir)))) results.push(await controlChars(target.command, args, dir, ctx));
|
|
1236
1238
|
return results;
|
|
1237
1239
|
}
|
|
1238
1240
|
};
|
|
@@ -1306,11 +1308,12 @@ const ctrlCCheck = {
|
|
|
1306
1308
|
kind: "check",
|
|
1307
1309
|
summary: "ignores Ctrl-C, or prints a stack trace when interrupted",
|
|
1308
1310
|
async run(target) {
|
|
1309
|
-
|
|
1311
|
+
const own = target.probes.filter((p) => p.own);
|
|
1312
|
+
if (own.length === 0) return [{
|
|
1310
1313
|
check: "ctrl-c",
|
|
1311
1314
|
invocation: [target.command],
|
|
1312
1315
|
verdict: "skip",
|
|
1313
|
-
reason: "needs probe
|
|
1316
|
+
reason: "needs a probe that keeps running, such as a watch or serve command (--probe), or --bare",
|
|
1314
1317
|
sentAfterMs: null,
|
|
1315
1318
|
exitedAfterMs: null,
|
|
1316
1319
|
exitCode: null,
|
|
@@ -1318,7 +1321,7 @@ const ctrlCCheck = {
|
|
|
1318
1321
|
stderrAfter: ""
|
|
1319
1322
|
}];
|
|
1320
1323
|
const results = [];
|
|
1321
|
-
for (const args of
|
|
1324
|
+
for (const { args } of own) results.push(await ctrlC(target.command, args));
|
|
1322
1325
|
return results;
|
|
1323
1326
|
}
|
|
1324
1327
|
};
|
|
@@ -1402,7 +1405,7 @@ const pipeEscapesCheck = {
|
|
|
1402
1405
|
summary: "prints spinners, cursor codes, hyperlinks or titles into a pipe",
|
|
1403
1406
|
async run(target, ctx) {
|
|
1404
1407
|
const results = [];
|
|
1405
|
-
for (const args of target.
|
|
1408
|
+
for (const { args } of target.probes) results.push(await pipeEscapes(target.command, args, ctx, target.fixtureDir !== void 0));
|
|
1406
1409
|
return results;
|
|
1407
1410
|
}
|
|
1408
1411
|
};
|
|
@@ -1493,7 +1496,7 @@ const restoreCheck = {
|
|
|
1493
1496
|
reason: `needs a terminal (${support.reason})`
|
|
1494
1497
|
};
|
|
1495
1498
|
const results = [];
|
|
1496
|
-
for (const args of target.
|
|
1499
|
+
for (const { args, own } of target.probes) {
|
|
1497
1500
|
if (notRun) {
|
|
1498
1501
|
const result = {
|
|
1499
1502
|
check: "restore",
|
|
@@ -1507,7 +1510,7 @@ const restoreCheck = {
|
|
|
1507
1510
|
}
|
|
1508
1511
|
results.push(await restore(target.command, args, {
|
|
1509
1512
|
timeout: ctx.timeout,
|
|
1510
|
-
interrupt:
|
|
1513
|
+
interrupt: own
|
|
1511
1514
|
}));
|
|
1512
1515
|
}
|
|
1513
1516
|
return results;
|
|
@@ -1584,11 +1587,12 @@ const sigtermCheck = {
|
|
|
1584
1587
|
kind: "check",
|
|
1585
1588
|
summary: "ignores SIGTERM, or exits on it and leaves its child processes running",
|
|
1586
1589
|
async run(target) {
|
|
1587
|
-
|
|
1590
|
+
const own = target.probes.filter((p) => p.own);
|
|
1591
|
+
if (own.length === 0) return [{
|
|
1588
1592
|
check: "sigterm",
|
|
1589
1593
|
invocation: [target.command],
|
|
1590
1594
|
verdict: "skip",
|
|
1591
|
-
reason: "needs probe
|
|
1595
|
+
reason: "needs a probe that keeps running, such as a watch or serve command (--probe), or --bare",
|
|
1592
1596
|
sentAfterMs: null,
|
|
1593
1597
|
exitedAfterMs: null,
|
|
1594
1598
|
exitCode: null,
|
|
@@ -1597,7 +1601,7 @@ const sigtermCheck = {
|
|
|
1597
1601
|
stderrAfter: ""
|
|
1598
1602
|
}];
|
|
1599
1603
|
const results = [];
|
|
1600
|
-
for (const args of
|
|
1604
|
+
for (const { args } of own) results.push(await sigterm(target.command, args));
|
|
1601
1605
|
return results;
|
|
1602
1606
|
}
|
|
1603
1607
|
};
|
|
@@ -1664,7 +1668,8 @@ const startupCheck = {
|
|
|
1664
1668
|
kind: "info",
|
|
1665
1669
|
summary: "median wall time of --version, or of the given probe, over 5 runs",
|
|
1666
1670
|
async run(target, ctx) {
|
|
1667
|
-
const
|
|
1671
|
+
const [first] = target.probes;
|
|
1672
|
+
const args = first?.own ? first.args : ["--version"];
|
|
1668
1673
|
return [await startup(target.command, args, ctx.timeout)];
|
|
1669
1674
|
}
|
|
1670
1675
|
};
|
|
@@ -1775,7 +1780,7 @@ const CHECKS = [
|
|
|
1775
1780
|
summary: "waits for stdin when it is an open pipe, as agents and CI runners leave it",
|
|
1776
1781
|
async run(target, ctx) {
|
|
1777
1782
|
const results = [];
|
|
1778
|
-
for (const args of target.
|
|
1783
|
+
for (const { args, own } of target.probes) results.push(await stdinCheck(target.command, args, !own, ctx));
|
|
1779
1784
|
return results;
|
|
1780
1785
|
}
|
|
1781
1786
|
},
|
|
@@ -1831,6 +1836,55 @@ const PLAIN = /^[\w@%+=:,./{}-]+$/;
|
|
|
1831
1836
|
function shellJoin(args) {
|
|
1832
1837
|
return args.map((a) => PLAIN.test(a) ? a : `'${a.replaceAll("'", `'\\''`)}'`).join(" ");
|
|
1833
1838
|
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Splits `text` into arguments the way a POSIX shell splits a command line:
|
|
1841
|
+
* on unquoted whitespace, with '...' taken literally, "..." honoring \" \\ \$ \`,
|
|
1842
|
+
* and a backslash escaping the next character. Nothing is expanded: no
|
|
1843
|
+
* variables, wildcards or ~. Throws on an unclosed quote or a trailing backslash.
|
|
1844
|
+
*/
|
|
1845
|
+
function shellSplit(text) {
|
|
1846
|
+
const words = [];
|
|
1847
|
+
let word = "";
|
|
1848
|
+
let inWord = false;
|
|
1849
|
+
for (let i = 0; i < text.length; i++) {
|
|
1850
|
+
const c = text.charAt(i);
|
|
1851
|
+
if (c === "'") {
|
|
1852
|
+
const end = text.indexOf("'", i + 1);
|
|
1853
|
+
if (end < 0) throw new Error("has an unclosed single quote");
|
|
1854
|
+
word += text.slice(i + 1, end);
|
|
1855
|
+
inWord = true;
|
|
1856
|
+
i = end;
|
|
1857
|
+
} else if (c === "\"") {
|
|
1858
|
+
inWord = true;
|
|
1859
|
+
for (i++;; i++) {
|
|
1860
|
+
if (i >= text.length) throw new Error("has an unclosed double quote");
|
|
1861
|
+
const d = text.charAt(i);
|
|
1862
|
+
if (d === "\"") break;
|
|
1863
|
+
const next = text.charAt(i + 1);
|
|
1864
|
+
if (d === "\\" && next !== "" && "\"\\$`\n".includes(next)) {
|
|
1865
|
+
i++;
|
|
1866
|
+
if (next !== "\n") word += next;
|
|
1867
|
+
} else word += d;
|
|
1868
|
+
}
|
|
1869
|
+
} else if (c === "\\") {
|
|
1870
|
+
if (i + 1 >= text.length) throw new Error("ends with a backslash");
|
|
1871
|
+
i++;
|
|
1872
|
+
if (text.charAt(i) !== "\n") {
|
|
1873
|
+
word += text.charAt(i);
|
|
1874
|
+
inWord = true;
|
|
1875
|
+
}
|
|
1876
|
+
} else if (c === " " || c === " " || c === "\n") {
|
|
1877
|
+
if (inWord) words.push(word);
|
|
1878
|
+
word = "";
|
|
1879
|
+
inWord = false;
|
|
1880
|
+
} else {
|
|
1881
|
+
word += c;
|
|
1882
|
+
inWord = true;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
if (inWord) words.push(word);
|
|
1886
|
+
return words;
|
|
1887
|
+
}
|
|
1834
1888
|
// src/report/summary.ts
|
|
1835
1889
|
function countVerdicts(results) {
|
|
1836
1890
|
const counts = {
|
|
@@ -2059,7 +2113,8 @@ function parseArgs(argv) {
|
|
|
2059
2113
|
skip: [],
|
|
2060
2114
|
strict: false,
|
|
2061
2115
|
command: void 0,
|
|
2062
|
-
args: []
|
|
2116
|
+
args: [],
|
|
2117
|
+
probes: []
|
|
2063
2118
|
};
|
|
2064
2119
|
for (let i = 0; i < argv.length; i++) {
|
|
2065
2120
|
const a = argv[i] ?? "";
|
|
@@ -2084,6 +2139,17 @@ function parseArgs(argv) {
|
|
|
2084
2139
|
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2085
2140
|
opts.timeout = Number(value);
|
|
2086
2141
|
if (!Number.isInteger(opts.timeout) || opts.timeout <= 0) throw new UsageError(`--timeout needs a positive whole number of milliseconds, got "${String(value)}"`);
|
|
2142
|
+
} else if (a === "--probe" || a.startsWith("--probe=")) {
|
|
2143
|
+
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
2144
|
+
if (value === void 0) throw new UsageError("--probe needs the arguments to probe");
|
|
2145
|
+
let words;
|
|
2146
|
+
try {
|
|
2147
|
+
words = shellSplit(value);
|
|
2148
|
+
} catch (error) {
|
|
2149
|
+
throw new UsageError(`--probe ${shellJoin([value])} ${error instanceof Error ? error.message : String(error)}`);
|
|
2150
|
+
}
|
|
2151
|
+
if (words.length === 0) throw new UsageError("--probe needs the arguments to probe; use --bare for none");
|
|
2152
|
+
opts.probes.push(words);
|
|
2087
2153
|
} else if (/^--(check|skip)(=|$)/.test(a)) {
|
|
2088
2154
|
const flag = a.split("=")[0] ?? a;
|
|
2089
2155
|
const names = ((a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i]) ?? "").split(",").map((n) => n.trim()).filter(Boolean);
|
|
@@ -2096,8 +2162,19 @@ function parseArgs(argv) {
|
|
|
2096
2162
|
}
|
|
2097
2163
|
}
|
|
2098
2164
|
if (opts.bare && opts.args.length) throw new UsageError("--bare probes the command with no arguments, so give none after it");
|
|
2165
|
+
const seen = new Set(mainProbe(opts).map((args) => JSON.stringify(args)));
|
|
2166
|
+
for (const args of opts.probes) {
|
|
2167
|
+
const key = JSON.stringify(args);
|
|
2168
|
+
if (seen.has(key)) throw new UsageError(`--probe ${shellJoin(args)} repeats a probe that already runs`);
|
|
2169
|
+
seen.add(key);
|
|
2170
|
+
}
|
|
2099
2171
|
return opts;
|
|
2100
2172
|
}
|
|
2173
|
+
/** The arguments given after the command, the empty --bare probe, or the default --version and --help. */
|
|
2174
|
+
function mainProbe(opts) {
|
|
2175
|
+
if (opts.bare) return [[]];
|
|
2176
|
+
return opts.args.length ? [opts.args] : [["--version"], ["--help"]];
|
|
2177
|
+
}
|
|
2101
2178
|
// src/cli/help.ts
|
|
2102
2179
|
const HELP = `cliprobe ${VERSION}: test a command-line program for terminal-edge bugs
|
|
2103
2180
|
|
|
@@ -2106,9 +2183,10 @@ Usage:
|
|
|
2106
2183
|
|
|
2107
2184
|
With no args after <command>, cliprobe probes "<command> --version" and
|
|
2108
2185
|
"<command> --help". With args, it probes exactly that invocation; with --bare,
|
|
2109
|
-
the command alone.
|
|
2110
|
-
|
|
2111
|
-
control
|
|
2186
|
+
the command alone. --probe adds more invocations to the same run, such as a
|
|
2187
|
+
watch or serve command for ctrl-c and sigterm. An argument containing
|
|
2188
|
+
{fixture} gets the path of a temporary directory of file names with control
|
|
2189
|
+
characters in them, for the control-chars check.
|
|
2112
2190
|
|
|
2113
2191
|
Checks:
|
|
2114
2192
|
closed-pipe Runs the command with stdout already closed, as when output is
|
|
@@ -2130,7 +2208,7 @@ Checks:
|
|
|
2130
2208
|
terminal. Fails if the command is still running 3 s later or
|
|
2131
2209
|
prints a stack trace; warns if it exits 0. Skipped when the
|
|
2132
2210
|
command finishes first, so probe a command that keeps running
|
|
2133
|
-
(a watcher, a server, a long task).
|
|
2211
|
+
(a watcher, a server, a long task), e.g. with --probe "serve".
|
|
2134
2212
|
sigterm Sends SIGTERM to the command alone after 1 s, as kill, docker
|
|
2135
2213
|
stop and process managers do. Warns if it is still running 3 s
|
|
2136
2214
|
later, prints a stack trace, or exits and leaves child
|
|
@@ -2145,11 +2223,12 @@ Checks:
|
|
|
2145
2223
|
directory of file names holding escape sequences, a carriage
|
|
2146
2224
|
return, a newline and more. Fails if an escape sequence reaches
|
|
2147
2225
|
the terminal unescaped; warns for the others. Skipped without
|
|
2148
|
-
{fixture}, e.g. cliprobe -- ls {fixture}
|
|
2226
|
+
{fixture}, e.g. cliprobe --probe "ls {fixture}" -- tool
|
|
2149
2227
|
|
|
2150
2228
|
Info checks (never fail; run only when named with --check):
|
|
2151
|
-
startup Median wall time over 5 runs of "<command> --version", or of
|
|
2152
|
-
|
|
2229
|
+
startup Median wall time over 5 runs of "<command> --version", or of
|
|
2230
|
+
the args after <command>, e.g.
|
|
2231
|
+
cliprobe --check startup -- node cli.js -v
|
|
2153
2232
|
baseline Appends --version, --help and an unknown flag to the probe and
|
|
2154
2233
|
reports what scripts rely on: one version line, help on stdout,
|
|
2155
2234
|
non-zero exit for a bad flag. A program that ignores unknown
|
|
@@ -2158,6 +2237,9 @@ Info checks (never fail; run only when named with --check):
|
|
|
2158
2237
|
Options:
|
|
2159
2238
|
--bare Probe the command with no arguments (a REPL, a full-screen
|
|
2160
2239
|
program, a server) instead of --version and --help
|
|
2240
|
+
--probe <args> Also probe "<command> <args>"; repeat it for several. Split
|
|
2241
|
+
like a shell command line: quotes and backslashes work,
|
|
2242
|
+
variables and wildcards are not expanded
|
|
2161
2243
|
--check <name> Run only this check; repeat it or use commas for several
|
|
2162
2244
|
--skip <name> Leave this check out; repeat it or use commas for several
|
|
2163
2245
|
--strict Exit 1 on a warning too, not only on a failure
|
|
@@ -2197,7 +2279,7 @@ async function run(argv, io) {
|
|
|
2197
2279
|
opts = parseArgs(argv);
|
|
2198
2280
|
} catch (error) {
|
|
2199
2281
|
if (!(error instanceof UsageError)) throw error;
|
|
2200
|
-
err(`cliprobe: ${error.message}\nRun "cliprobe --help" for usage.\n`);
|
|
2282
|
+
err(`cliprobe: ${safe(error.message)}\nRun "cliprobe --help" for usage.\n`);
|
|
2201
2283
|
return 2;
|
|
2202
2284
|
}
|
|
2203
2285
|
if (opts.help) {
|
|
@@ -2230,14 +2312,23 @@ async function run(argv, io) {
|
|
|
2230
2312
|
err(`cliprobe: command not found: ${safe(opts.command)}\n`);
|
|
2231
2313
|
return 2;
|
|
2232
2314
|
}
|
|
2233
|
-
const
|
|
2234
|
-
const
|
|
2315
|
+
const own = opts.bare || opts.args.length > 0;
|
|
2316
|
+
const probes = [...mainProbe(opts).map((args) => ({
|
|
2317
|
+
args,
|
|
2318
|
+
own
|
|
2319
|
+
})), ...opts.probes.map((args) => ({
|
|
2320
|
+
args,
|
|
2321
|
+
own: true
|
|
2322
|
+
}))];
|
|
2323
|
+
const fixture = probes.some((p) => usesFixture(p.args)) ? createFixture() : void 0;
|
|
2235
2324
|
const results = [];
|
|
2236
2325
|
try {
|
|
2237
2326
|
const target = {
|
|
2238
2327
|
command: opts.command,
|
|
2239
|
-
|
|
2240
|
-
|
|
2328
|
+
probes: fixture ? probes.map((p) => ({
|
|
2329
|
+
...p,
|
|
2330
|
+
args: expandFixture(p.args, fixture.dir)
|
|
2331
|
+
})) : probes,
|
|
2241
2332
|
...fixture ? { fixtureDir: fixture.dir } : {}
|
|
2242
2333
|
};
|
|
2243
2334
|
const ctx = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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": {
|