cliprobe 1.9.0 → 1.11.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 CHANGED
@@ -31,7 +31,7 @@ npx cliprobe -- tsx
31
31
  ```
32
32
 
33
33
  ```
34
- cliprobe 1.7.0: closed-pipe, write-error, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for tsx
34
+ cliprobe 1.11.0: closed-pipe, write-error, slow-pipe, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for tsx
35
35
 
36
36
  closed-pipe
37
37
  FAIL tsx --version crashed when stdout was closed (exit 0 -> 1)
@@ -43,6 +43,10 @@ write-error
43
43
  Error: ENOSPC: no space left on device, write (at node_modules/tsx/dist/cli.mjs:53:36962)
44
44
  WARN tsx --help exited 0 though every write to stdout failed (no space left on device), so `> file` on a full disk looks like success
45
45
 
46
+ slow-pipe
47
+ SKIP tsx --version wrote 27 bytes to stdout, which a pipe holds whole (64 KiB), so none can be lost
48
+ SKIP tsx --help wrote 26175 bytes to stdout, which a pipe holds whole (64 KiB), so none can be lost
49
+
46
50
  color
47
51
  PASS tsx --version no color in a pipe or in a terminal
48
52
  FAIL tsx --help printed color codes into a pipe
@@ -69,7 +73,7 @@ restore
69
73
  control-chars
70
74
  SKIP tsx no {fixture} in the arguments; add a probe that takes a path, e.g. --probe "ls {fixture}"
71
75
 
72
- 2 failed, 2 warned, 8 passed, 3 skipped
76
+ 2 failed, 2 warned, 8 passed, 5 skipped
73
77
  ```
74
78
 
75
79
  <sub>tsx 4.23.15 on Linux, run offline in a container in December 2026. On macOS, write-error is skipped.</sub>
@@ -78,7 +82,7 @@ control-chars
78
82
 
79
83
  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.
80
84
 
81
- 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, browserslist and autoprefixer have fixed it; the other six still crash at their December 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/`.) The census is repeatable: [`census/`](https://github.com/KhaledSaeed18/cliprobe/tree/main/census) pins the packages, runs them offline with one command, and keeps [the latest results](https://github.com/KhaledSaeed18/cliprobe/blob/main/census/results/top-100.md).
85
+ 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, browserslist and autoprefixer have fixed it; the other six still crash at their December 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 slow-pipe, ctrl-c, sigterm or control-chars, which need a command that prints a lot, keeps running or takes a path; their fixtures and real-tool tests are in `test/`.) The census is repeatable: [`census/`](https://github.com/KhaledSaeed18/cliprobe/tree/main/census) pins the packages, runs them offline with one command, and keeps [the latest results](https://github.com/KhaledSaeed18/cliprobe/blob/main/census/results/top-100.md).
82
86
 
83
87
  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.
84
88
 
@@ -96,8 +100,9 @@ The other checks cover the rest of what goes wrong between a program and the thi
96
100
  - [Exit codes](#exit-codes)
97
101
  - [In CI](#in-ci)
98
102
  - [JSON output](#json-output)
103
+ - [In your test suite](#in-your-test-suite)
99
104
  - [Stability](#stability)
100
- - [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)
105
+ - [Checks](#checks): [closed-pipe](#closed-pipe), [write-error](#write-error), [slow-pipe](#slow-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)
101
106
  - [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
102
107
  - [Agent skill](#agent-skill)
103
108
  - [Safety](#safety)
@@ -115,7 +120,7 @@ Run it without installing:
115
120
  npx cliprobe -- <command>
116
121
  ```
117
122
 
118
- Or add it to a project, to run in CI against your own CLI:
123
+ Or add it to a project, to run in CI against your own CLI or [from its test suite](#in-your-test-suite):
119
124
 
120
125
  ```sh
121
126
  npm install --save-dev cliprobe # or: pnpm add -D cliprobe
@@ -185,6 +190,7 @@ npx cliprobe # with no command, reads cliprobe.config.json from the current d
185
190
  | `command` | The program, required. Unlike on the command line, everything in it belongs to the program, so with `node ./dist/cli.js` the probes are `--version`, `--help` and each of `probes`, all after the script |
186
191
  | `probes` | More invocations, each the arguments after the program, as `--probe` |
187
192
  | `bare` | `true` probes the program alone instead of `--version` and `--help`, as `--bare` |
193
+ | `defaultProbes` | `false` leaves out `--version` and `--help`, so only `probes` run |
188
194
  | `checks`, `skip` | Arrays of check names, as `--check` and `--skip` |
189
195
  | `strict`, `timeout` | As `--strict` and `--timeout` |
190
196
  | `accept` | Failures and warnings the project knows about; see below |
@@ -260,7 +266,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
260
266
 
261
267
  ## JSON output
262
268
 
263
- `--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`:
269
+ `--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`. [`probe()`](#in-your-test-suite) returns the same report as an object:
264
270
 
265
271
  ```json
266
272
  {
@@ -292,6 +298,49 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
292
298
 
293
299
  `strict` says whether `--strict` was given (added in 1.1). Every result has the same five fields: `check`, `invocation` (the command and arguments that ran), `verdict` (`pass`, `fail`, `warn`, `skip`, `error` for could-not-run, or `info`), `reason` (a sentence for a person) and `details`, plus `evidence` when there is a line to quote and, since 1.8, `accepted` (an object with the `reason`) when the [config file accepts](#accepted-findings) the result; `summary` counts verdicts as before. `details` holds the check's own measurements, such as exit codes, timings, the terminal modes left on or the processes left running; the schema describes each check's. Text from the program under test is escaped: control characters, line separators and bidi overrides appear as `\u` escapes, so the report can't drive a terminal when printed. The human report shows them as `\x1b`-style escapes and doubles a backslash the program printed, so `\\x1b` is text and `\x1b` a real escape character; it cuts evidence longer than 200 characters, which the JSON has in full.
294
300
 
301
+ ## In your test suite
302
+
303
+ cliprobe is also a library: `probe()` runs the checks and returns the report as an object, so your own tests can hold your CLI to them. It works with any test runner; with Vitest:
304
+
305
+ ```ts
306
+ import { expect, test } from 'vitest';
307
+ import { failing, formatReport, probe } from 'cliprobe';
308
+
309
+ test('the CLI behaves in pipes, on Ctrl-C and on a full disk', async () => {
310
+ const report = await probe('node ./dist/cli.js', {
311
+ probes: ['serve --port 0', 'scan {fixture}'],
312
+ });
313
+ // On a failure, the message is the report a person would read.
314
+ expect(failing(report), formatReport(report)).toEqual([]);
315
+ }, 120_000);
316
+ ```
317
+
318
+ `probe(command, options)` takes the program as the [config file](#config-file) does: `command` is all of it, script included, as a string or an array, and the options are the file's other keys (`probes`, `bare`, `defaultProbes`, `checks`, `skip`, `strict`, `timeout`, `accept`). It resolves to the same report as [`--format json`](#json-output), with TypeScript types: `result.check` narrows `result.details` to that check's fields.
319
+
320
+ | Export | What it does |
321
+ | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
322
+ | `probe(command, options?)` | Runs the checks and resolves to the report. A check that fails is a result, never an exception |
323
+ | `failing(report)` | The results that fail the run: every `fail`, plus every `warn` with `strict`, except those `accept` covers |
324
+ | `exitCode(report)` | `0`, `1` or `2`, as the CLI would exit |
325
+ | `formatReport(report, format?)` | The report as text: `human` (default), `json`, `markdown`, `junit` or `github`, escaped as in the CLI. `{ color: true }` paints the verdicts |
326
+ | `readConfig(path?)` | Reads `cliprobe.config.json`, so a test probes exactly what `npx cliprobe` does: `const { command, ...options } = readConfig()` |
327
+ | `ProbeError` | What `probe()` rejects with when the run can't start; its `code` is `USAGE`, `COMMAND` or `PLATFORM` |
328
+ | `CHECK_NAMES`, `FORMAT_NAMES`, `version` | The check names in run order, the format names, and the cliprobe version |
329
+
330
+ To assert on one check, read the results; the verdict and the check name are stable, the wording of `reason` is not:
331
+
332
+ ```ts
333
+ const report = await probe('node ./dist/cli.js', { checks: ['closed-pipe'] });
334
+ expect(report.results.map((r) => r.verdict)).toEqual(['pass', 'pass']);
335
+ ```
336
+
337
+ A few things to know:
338
+
339
+ - **Give the test time.** A probe that keeps running costs a few seconds in each check, so a full run takes from a few seconds to a minute or more. `checks` and `defaultProbes: false` keep a test to exactly what it asserts.
340
+ - **Run probes one after another.** The checks measure time, so several `probe()` calls at once on a busy machine can turn a slow answer into a wrong verdict.
341
+ - **It is the same run as the CLI.** The program starts in the current directory, without a shell, with a temporary `HOME` and [a minimal environment](#the-probes-environment), and anything it leaves running is killed. If the test process exits early, cliprobe kills the probe in progress and removes its temporary files on the way out.
342
+ - **Importing it does nothing.** No output, no signal handlers, no work until `probe()` is called. The package is ESM with types included and no dependencies; `require('cliprobe')` works too.
343
+
295
344
  ## Stability
296
345
 
297
346
  From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
@@ -300,11 +349,12 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
300
349
  - **Names and exit codes.** Check names, verdicts, options, config file keys and exit codes stay as they are.
301
350
  - **`--strict` opts out of the first promise.** It fails on warnings, so a new warning in a minor release can fail your build. Pin an exact version (`cliprobe@1.7.0`) if that matters, or `--skip` the check.
302
351
  - **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
352
+ - **The API.** The functions `cliprobe` exports, their options and the report they return follow the same rules: they are only added to.
303
353
  - **Not covered.** The wording of `reason` and `evidence`, and the human, Markdown and `github` output, are for people and may change. Match on `check` and `verdict`, not on text.
304
354
 
305
355
  ## Checks
306
356
 
307
- 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`.
357
+ A default run does the ten checks below: closed-pipe, write-error, slow-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`.
308
358
 
309
359
  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:
310
360
 
@@ -339,6 +389,20 @@ cliprobe runs the command twice: once normally, then with stdout set to `/dev/fu
339
389
 
340
390
  The check is new in 1.7 and only warns. The December 2026 census shows why it should stay that way for now: of the 157 `--help` and `--version` runs of the top 100 npm commands that print something, 138 warned. 119 exited 0 with their output lost, among them esbuild, eslint, prettier and `tsc`, and 19 crashed with a stack trace; only 19, such as pnpm and uuid, reported the error and exited non-zero. Every one checked by hand was real (`esbuild --version > /dev/full; echo $?` prints 0), so the warning is true, but a check that most tools would fail is not one to gate a build on yet. It runs on Linux only, since macOS has no `/dev/full`; run it in CI on a Linux runner, or in a container.
341
391
 
392
+ ### slow-pipe
393
+
394
+ cliprobe runs the command with stdout in a file, where every write completes at once, then with stdout in a pipe that nobody reads until the program exits (or half a second passes), as a pager, a slow consumer or a busy log collector does. A pipe holds 64 KiB; what a program writes beyond that waits until the reader takes some. A program that exits while output is still waiting loses it, and the reader gets the first 64 KiB and an exit code of 0. In Node.js that is `process.exit()` right after a large `console.log` or `process.stdout.write`: `my-cli list --json | jq` fails on JSON cut off in the middle, only in a pipe and only once the output is large. Results:
395
+
396
+ | Verdict | Meaning |
397
+ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
398
+ | `PASS` | Every byte arrived through the slowly read pipe |
399
+ | `WARN` | The pipe got only the start of the output (the evidence is the byte where it stopped), or the program hung |
400
+ | `SKIP` | Wrote nothing, or less than 64 KiB, which a pipe holds whole; wrote more than 64 MiB; kept running; or wrote something different on every run, so nothing can be compared |
401
+
402
+ The check is new in 1.11 and only warns. `--help` and `--version` rarely print 64 KiB, so it mostly judges the probes you write: give it the command that prints your largest output, such as `--probe "list --json"`. Before it warns, it runs the command into a file once more and compares, so a program whose output changes between runs is skipped, never blamed.
403
+
404
+ The census of `--help` and `--version` says nothing here: all 240 runs printed less than 64 KiB. So it was tried on 15 commands from the same packages doing real work with larger output (parsing, formatting, converting and listing). 12 passed, among them acorn, prettier, marked, js-yaml, json5 and `npm ls --all`. 3 warned, he, jsesc and cssesc, each confirmed by hand with a plain shell pipe: `jsesc "$text" | (sleep 1; wc -c)` prints 65536 for 84002 bytes of output, and exits 0. All three end with `process.exit(0)`.
405
+
342
406
  ### color
343
407
 
344
408
  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:
@@ -454,6 +518,16 @@ process.stdout.on('error', (error) => {
454
518
  });
455
519
  ```
456
520
 
521
+ **slow-pipe:** don't call `process.exit()` while output may still be on its way to a pipe. Set the exit code and let the program end, or exit from the last write's callback:
522
+
523
+ ```js
524
+ process.stdout.write(output);
525
+ process.exitCode = 1; // instead of process.exit(1)
526
+
527
+ // or, when the program must stop here:
528
+ process.stdout.write(output, () => process.exit(1));
529
+ ```
530
+
457
531
  The same handler catches writes made with `console.log`, which otherwise drops a failed write silently and lets the program exit 0.
458
532
 
459
533
  **color:** decide once, from the stream you write to:
@@ -580,6 +654,8 @@ The runs under a terminal are color's second and third, restore's, and control-c
580
654
 
581
655
  **How do I stop repeating the probes in every command?** Put them in a [config file](#config-file): `cliprobe.config.json` holds the command, the probes and any findings you accept, and `npx cliprobe` runs it.
582
656
 
657
+ **Can I run it from my own tests?** Yes: [`probe()`](#in-your-test-suite) returns the report as an object, with helpers to list what fails and to print it.
658
+
583
659
  **Does a pass mean my CLI has no terminal bugs?** No. Each check tests one behavior, on the probes that ran; a subcommand that wasn't probed wasn't checked. cliprobe reports evidence, not a score, so add a `--probe` for each command your users pipe or interrupt.
584
660
 
585
661
  **Does it only work for Node.js programs?** No. It tests any command as a black box, whatever it is written in. Only the [fixes](#fixing-a-failure-in-a-nodejs-cli) are specific to Node.js.
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}