cliprobe 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -20
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<a href="https://www.npmjs.com/package/cliprobe">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/KhaledSaeed18/cliprobe/main/.github/assets/cliprobe-banner.png" alt="cliprobe: black-box tests for the terminal bugs that only show up in a pipe" width="100%" />
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
<h1>cliprobe</h1>
|
|
8
|
+
|
|
9
|
+
<p><strong>Black-box tests any command-line program for terminal-edge bugs:</strong> the ones that only show up when output is piped, cut short, or read by a script or an AI agent.</p>
|
|
10
|
+
|
|
11
|
+
<p>
|
|
12
|
+
<a href="https://www.npmjs.com/package/cliprobe"><img src="https://shieldcn.dev/npm/cliprobe.svg?logo=npm" alt="npm version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/cliprobe"><img src="https://shieldcn.dev/npm/dw/cliprobe.svg" alt="npm downloads" /></a>
|
|
14
|
+
<a href="https://github.com/KhaledSaeed18/cliprobe/actions/workflows/ci.yml"><img src="https://shieldcn.dev/github/ci/KhaledSaeed18/cliprobe.svg" alt="CI status" /></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/cliprobe"><img src="https://shieldcn.dev/npm/node/cliprobe.svg" alt="Node.js version" /></a>
|
|
16
|
+
<a href="https://github.com/KhaledSaeed18/cliprobe/blob/main/LICENSE"><img src="https://shieldcn.dev/npm/license/cliprobe.svg?variant=secondary" alt="License: MIT" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p>
|
|
20
|
+
<a href="https://github.com/KhaledSaeed18/cliprobe/stargazers"><img src="https://shieldcn.dev/github/stars/KhaledSaeed18/cliprobe.svg?variant=outline" alt="GitHub stars" /></a>
|
|
21
|
+
<a href="https://github.com/KhaledSaeed18/cliprobe/issues"><img src="https://shieldcn.dev/github/issues/KhaledSaeed18/cliprobe.svg?variant=outline" alt="GitHub issues" /></a>
|
|
22
|
+
<a href="https://github.com/KhaledSaeed18/cliprobe/releases"><img src="https://shieldcn.dev/github/release/KhaledSaeed18/cliprobe.svg?variant=ghost" alt="Latest release" /></a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
---
|
|
4
28
|
|
|
5
29
|
```sh
|
|
6
30
|
npx cliprobe -- esbuild
|
|
@@ -40,7 +64,7 @@ control-chars
|
|
|
40
64
|
2 failed, 0 warned, 8 passed, 2 skipped
|
|
41
65
|
```
|
|
42
66
|
|
|
43
|
-
## Why
|
|
67
|
+
## Why cliprobe?
|
|
44
68
|
|
|
45
69
|
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.
|
|
46
70
|
|
|
@@ -48,6 +72,38 @@ In a census of the 100 most-downloaded npm packages that ship a command (119 com
|
|
|
48
72
|
|
|
49
73
|
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, 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.
|
|
50
74
|
|
|
75
|
+
- **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.
|
|
76
|
+
- **No false fails.** A new check starts as warn-only and is calibrated against real tools before it may fail.
|
|
77
|
+
- **Deterministic.** A closed pipe is a FIFO closed before the program starts, Ctrl-C is a signal to its process group, and the terminal is always 80×24.
|
|
78
|
+
- **Any language.** It tests the program from the outside, so a Go, Rust, Python or shell CLI works as well as a Node.js one.
|
|
79
|
+
- **Zero dependencies.** Nothing but Node.js and, for the terminal checks, the system's `script` command.
|
|
80
|
+
|
|
81
|
+
## Contents
|
|
82
|
+
|
|
83
|
+
- [Installation](#installation)
|
|
84
|
+
- [Usage](#usage)
|
|
85
|
+
- [Exit codes](#exit-codes)
|
|
86
|
+
- [In CI](#in-ci)
|
|
87
|
+
- [Checks](#checks): [closed-pipe](#closed-pipe), [color](#color), [pipe-escapes](#pipe-escapes), [stdin](#stdin), [ctrl-c](#ctrl-c), [restore](#restore), [control-chars](#control-chars), [info checks](#info-checks)
|
|
88
|
+
- [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
|
|
89
|
+
- [Safety](#safety)
|
|
90
|
+
- [Contributing](#contributing)
|
|
91
|
+
- [License](#license)
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
Requires Node.js 22.12 or later, on macOS or Linux (including Alpine). Windows isn't supported yet. Run it without installing:
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
npx cliprobe -- <command>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or add it to a project, to run in CI against your own CLI:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
npm install --save-dev cliprobe # or: pnpm add -D cliprobe
|
|
105
|
+
```
|
|
106
|
+
|
|
51
107
|
## Usage
|
|
52
108
|
|
|
53
109
|
```sh
|
|
@@ -72,9 +128,17 @@ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, onl
|
|
|
72
128
|
| `-h`, `--help` | Show help |
|
|
73
129
|
| `-v`, `--version` | Show the version |
|
|
74
130
|
|
|
75
|
-
Exit codes
|
|
131
|
+
## Exit codes
|
|
132
|
+
|
|
133
|
+
| Code | Meaning |
|
|
134
|
+
| ---- | ----------------------------------------- |
|
|
135
|
+
| `0` | No check failed |
|
|
136
|
+
| `1` | A check failed |
|
|
137
|
+
| `2` | Usage error, or the command could not run |
|
|
138
|
+
|
|
139
|
+
A command that isn't on `PATH` is reported once, before any check runs, with exit `2` and no report. That makes cliprobe usable as a CI gate.
|
|
76
140
|
|
|
77
|
-
|
|
141
|
+
## In CI
|
|
78
142
|
|
|
79
143
|
A failed check exits 1, so the step fails. In GitHub Actions, write a Markdown report to the job summary while the log keeps the human report:
|
|
80
144
|
|
|
@@ -100,18 +164,24 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
100
164
|
|
|
101
165
|
A default run does the seven checks below: closed-pipe, color, pipe-escapes, stdin, ctrl-c, 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`.
|
|
102
166
|
|
|
103
|
-
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c and restore need. The other checks judge it on what it did before the timeout (`--timeout`, 15 seconds by default): a crash once stdout is closed
|
|
167
|
+
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c and restore need. 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.
|
|
168
|
+
|
|
169
|
+
### closed-pipe
|
|
170
|
+
|
|
171
|
+
cliprobe runs the command twice: once normally, then with stdout set to a pipe whose reading end is already closed, so the first write fails every time, even for fast native programs. Results:
|
|
104
172
|
|
|
105
|
-
|
|
173
|
+
| Verdict | Meaning |
|
|
174
|
+
| ------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
175
|
+
| `PASS` | Exited quietly, or was stopped by SIGPIPE (the Unix convention), or kept running without a write error |
|
|
176
|
+
| `FAIL` | Printed an EPIPE error or stack trace and changed its exit code, or hung, or crashed on it while a normal run kept running |
|
|
177
|
+
| `WARN` | Printed a write error but kept its exit code |
|
|
178
|
+
| `SKIP` | Wrote nothing to stdout for this invocation (or before the timeout), so pass args that print something |
|
|
106
179
|
|
|
107
|
-
|
|
108
|
-
| ------- | ------------------------------------------------------------------------------------------------------ |
|
|
109
|
-
| `PASS` | Exited quietly, or was stopped by SIGPIPE (the Unix convention), or kept running without a write error |
|
|
110
|
-
| `FAIL` | Printed an EPIPE error or stack trace and changed its exit code, or hung |
|
|
111
|
-
| `WARN` | Printed a write error but kept its exit code, or crashed on it while a normal run kept running |
|
|
112
|
-
| `SKIP` | Wrote nothing to stdout for this invocation (or before the timeout), so pass args that print something |
|
|
180
|
+
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.
|
|
113
181
|
|
|
114
|
-
|
|
182
|
+
### color
|
|
183
|
+
|
|
184
|
+
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:
|
|
115
185
|
|
|
116
186
|
| Verdict | Meaning |
|
|
117
187
|
| ------- | -------------------------------------------------------------------------------------------------------------- |
|
|
@@ -122,7 +192,9 @@ A command that keeps running, such as a server, a watcher or a full-screen progr
|
|
|
122
192
|
|
|
123
193
|
Many classic tools (git, BSD `ls` and `grep`) color correctly but don't implement [`NO_COLOR`](https://no-color.org), so they get a `WARN`, never a `FAIL`. Probe a command that prints color in normal use: almost no CLI colors its `--help`.
|
|
124
194
|
|
|
125
|
-
|
|
195
|
+
### pipe-escapes
|
|
196
|
+
|
|
197
|
+
cliprobe runs the command into a pipe, with the same environment as the color check, and looks at stdout and stderr for terminal control codes that only make sense on a screen: cursor movement, line and screen erases, mode switches such as hiding the cursor, hyperlinks (OSC 8), window titles, and carriage returns that redraw a line. Spinners and progress bars are the usual source. In a pipe they turn logs and agent transcripts into `\r\x1b[2K` noise. Results:
|
|
126
198
|
|
|
127
199
|
| Verdict | Meaning |
|
|
128
200
|
| ------- | -------------------------------------------------------------------------- |
|
|
@@ -132,7 +204,9 @@ Many classic tools (git, BSD `ls` and `grep`) color correctly but don't implemen
|
|
|
132
204
|
|
|
133
205
|
It only warns for now, never fails. In the census of the top 100 npm CLIs, no `--help` or `--version` printed any of these codes, which says nothing about their spinners: probe a command that does real work, such as an install or a build. With `{fixture}` in the args, the hostile file names themselves are left to the control-chars check: a lister that prints them raw into a pipe, as `ls` does, isn't warned about.
|
|
134
206
|
|
|
135
|
-
|
|
207
|
+
### stdin
|
|
208
|
+
|
|
209
|
+
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 for 3 seconds, with a pipe it closes after 1 second. Finishing right after the close proves stdin was the cause. Results:
|
|
136
210
|
|
|
137
211
|
| Verdict | Meaning |
|
|
138
212
|
| ------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -143,7 +217,9 @@ It only warns for now, never fails. In the census of the top 100 npm CLIs, no `-
|
|
|
143
217
|
|
|
144
218
|
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.
|
|
145
219
|
|
|
146
|
-
|
|
220
|
+
### ctrl-c
|
|
221
|
+
|
|
222
|
+
cliprobe lets the command run for 1 second, then sends SIGINT to its process group, which is what a terminal does when you press Ctrl-C, and gives it 3 seconds to exit. Results:
|
|
147
223
|
|
|
148
224
|
| Verdict | Meaning |
|
|
149
225
|
| ------- | ---------------------------------------------------------------------------------------------- |
|
|
@@ -154,7 +230,9 @@ In the census of the top 100 npm CLIs, 9 of 238 `--help` and `--version` runs fa
|
|
|
154
230
|
|
|
155
231
|
A stack trace printed before the Ctrl-C doesn't count. Python's default `KeyboardInterrupt` traceback is the classic failure here, so `python3 -c 'import time; time.sleep(30)'` fails.
|
|
156
232
|
|
|
157
|
-
|
|
233
|
+
### restore
|
|
234
|
+
|
|
235
|
+
Spinners, prompts and full-screen programs switch terminal modes on: they hide the cursor, open the alternate screen, turn on mouse reporting or bracketed paste, or turn line wrapping off. If they don't switch them back off on the way out, the shell they return to is broken until you run `reset`: no cursor, a blank screen, mouse clicks typed as junk, long lines cut off at the edge. cliprobe runs the command under a terminal and, for probes you write, types Ctrl-C after 1 second, as a person would. The keystroke goes through the terminal, so a program in raw mode gets it as a key rather than a signal, just as it would from a keyboard. `--version` and `--help` aren't interrupted; they're judged as they exit. Results:
|
|
158
236
|
|
|
159
237
|
| Verdict | Meaning |
|
|
160
238
|
| ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -164,7 +242,9 @@ A stack trace printed before the Ctrl-C doesn't count. Python's default `Keyboar
|
|
|
164
242
|
|
|
165
243
|
It only warns: a terminal left in the wrong mode is a nuisance you can undo, not a failure of the program's job. Across the top 100 npm CLIs, their watch modes and servers, and popular prompt and spinner libraries (about 300 runs), nothing warned falsely, and one tool really did break the terminal: `taze -I` turns line wrapping off for its progress bars and leaves it off after Ctrl-C.
|
|
166
244
|
|
|
167
|
-
|
|
245
|
+
### control-chars
|
|
246
|
+
|
|
247
|
+
Put `{fixture}` in the arguments where your command takes a path, for example `npx cliprobe -- ls {fixture}` or `npx cliprobe -- node ./dist/cli.js scan --dir={fixture}`. 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:
|
|
168
248
|
|
|
169
249
|
| Verdict | Meaning |
|
|
170
250
|
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -241,6 +321,18 @@ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+
|
|
|
241
321
|
|
|
242
322
|
cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin check also uses a pipe that it never writes 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, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal. 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.
|
|
243
323
|
|
|
324
|
+
## Contributing
|
|
325
|
+
|
|
326
|
+
Bug reports and pull requests are welcome. Development needs Node.js 22.12 or later and pnpm (the version is pinned in `package.json`):
|
|
327
|
+
|
|
328
|
+
```sh
|
|
329
|
+
pnpm install
|
|
330
|
+
pnpm dev --check closed-pipe -- printf hi # run the CLI from source
|
|
331
|
+
pnpm check # everything CI runs
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
[AGENTS.md](https://github.com/KhaledSaeed18/cliprobe/blob/main/AGENTS.md) describes the layout, the product rules and how to add a check. Commits follow [Conventional Commits](https://www.conventionalcommits.org), and every `feat` or `fix` merged to `main` is released to npm.
|
|
335
|
+
|
|
244
336
|
## License
|
|
245
337
|
|
|
246
|
-
MIT
|
|
338
|
+
[MIT](https://github.com/KhaledSaeed18/cliprobe/blob/main/LICENSE), by [Khaled Saeed](https://github.com/KhaledSaeed18).
|
package/dist/cli.js
CHANGED
|
@@ -291,7 +291,7 @@ const newWriteError = (base, closed) => ERROR_RE.test(closed.stderr) && !ERROR_R
|
|
|
291
291
|
*/
|
|
292
292
|
function judgeLongRunning(base, closed) {
|
|
293
293
|
if (!closed.timedOut && newWriteError(base, closed)) return {
|
|
294
|
-
verdict: "
|
|
294
|
+
verdict: "fail",
|
|
295
295
|
reason: `crashed when stdout was closed, while a normal run kept running (exit ${closed.exitCode})`,
|
|
296
296
|
evidence: crashEvidence(closed.stderr)
|
|
297
297
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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, a terminal left broken after Ctrl-C, and control characters from file names reaching your terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|