cliprobe 1.4.2 → 1.4.3

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.
Files changed (3) hide show
  1. package/README.md +34 -12
  2. package/dist/cli.js +35 -16
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -31,7 +31,7 @@ npx cliprobe -- tsx
31
31
  ```
32
32
 
33
33
  ```
34
- cliprobe 1.2.0: closed-pipe, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for tsx
34
+ cliprobe 1.4.3: closed-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)
@@ -101,7 +101,9 @@ The other checks cover the rest of what goes wrong between a program and the thi
101
101
 
102
102
  ## Installation
103
103
 
104
- Requires Node.js 22.12 or later, on macOS or Linux (including Alpine). Windows isn't supported yet. Run it without installing:
104
+ Requires Node.js 22.12 or later, on macOS or Linux (including Alpine). Windows isn't supported yet. The terminal checks (color, restore and control-chars) also need the system's `script` command, which macOS has and most Linux distributions install by default. Without it they're skipped, and each skip says so. If it's missing, install the package that has it: `bsdutils` on Debian and Ubuntu, `util-linux-script` on Fedora, `util-linux-misc` on Alpine.
105
+
106
+ Run it without installing:
105
107
 
106
108
  ```sh
107
109
  npx cliprobe -- <command>
@@ -131,7 +133,7 @@ npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings f
131
133
  | Option | Meaning |
132
134
  | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
135
  | `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
134
- | `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards) |
136
+ | `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards). The args after `<command>` aren't kept: with `-- node ./cli.js`, write `--probe "./cli.js watch"` |
135
137
  | `--check <name>` | Run only this check; repeat it or use commas for several |
136
138
  | `--skip <name>` | Leave this check out; repeat it or use commas for several |
137
139
  | `--strict` | Exit 1 on a warning too, not only on a failure |
@@ -144,6 +146,8 @@ npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings f
144
146
 
145
147
  An option's value follows it or comes after `=` (`--format=json`). A value that is another option, as in `-o --strict`, is a usage error rather than a file named `--strict`. `--probe` is the exception: its value may start with `-`, to probe a flag (`--probe --json`).
146
148
 
149
+ A probe runs `<command>` with its own args, in place of the args after the command, not after them. So when the command is an interpreter, name the script in every probe: `npx cliprobe --probe "./dist/cli.js watch" -- node ./dist/cli.js` probes `node ./dist/cli.js` and `node ./dist/cli.js watch`, while `--probe watch` would run `node watch`. A probe that exits with a failure code and is skipped says so in its reason, with the error line from stderr as evidence, so a probe that never ran as intended doesn't pass for a quiet skip.
150
+
147
151
  ## Exit codes
148
152
 
149
153
  | Code | Meaning |
@@ -248,12 +252,12 @@ Servers and watchers crash the same way. Among 38 watch and serve modes of popul
248
252
 
249
253
  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:
250
254
 
251
- | Verdict | Meaning |
252
- | ------- | -------------------------------------------------------------------------------------------------------------- |
253
- | `PASS` | No color in a pipe; in a terminal, either no color at all or color that `NO_COLOR` turns off |
254
- | `FAIL` | Printed color or style codes (bold counts, a bare reset doesn't) to stdout in a pipe |
255
- | `WARN` | Printed color to stderr in a pipe, or kept printing color under `NO_COLOR` |
256
- | `SKIP` | Printed nothing, waited for input in a terminal, or no `script` command (on Alpine, install `util-linux-misc`) |
255
+ | Verdict | Meaning |
256
+ | ------- | ----------------------------------------------------------------------------------------------------------- |
257
+ | `PASS` | No color in a pipe; in a terminal, either no color at all or color that `NO_COLOR` turns off |
258
+ | `FAIL` | Printed color or style codes (bold counts, a bare reset doesn't) to stdout in a pipe |
259
+ | `WARN` | Printed color to stderr in a pipe, or kept printing color under `NO_COLOR` |
260
+ | `SKIP` | Printed nothing, waited for input in a terminal, or no `script` command (see [Installation](#installation)) |
257
261
 
258
262
  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`.
259
263
 
@@ -435,15 +439,33 @@ Then ask in your own words, for example "check my CLI for pipe and Ctrl-C bugs b
435
439
 
436
440
  ## Safety
437
441
 
438
- cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin, ctrl-c and sigterm checks use a pipe that they never write to), a temporary `HOME`, and a minimal environment (no tokens from your shell). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal, and when a program exits it kills whatever it left running, in its group or started in another one, in every check. If cliprobe itself is stopped by Ctrl-C, SIGTERM or SIGHUP, it first kills the probe it is running and removes its temporary directories and any half-written report file, then exits by the same signal (130, 143 or 129). It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command, which Alpine ships in `util-linux-misc`. Windows isn't supported yet.
442
+ 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; see [the probe's environment](#the-probes-environment)). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal, and when a program exits it kills whatever it left running, in its group or started in another one, in every check. If cliprobe itself is stopped by Ctrl-C, SIGTERM or SIGHUP, it first kills the probe it is running and removes its temporary directories and any half-written report file, then exits by the same signal (130, 143 or 129). It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command (see [Installation](#installation)). Windows isn't supported yet.
443
+
444
+ ### The probe's environment
445
+
446
+ A probe gets only these variables. Nothing else from your shell reaches it, not even `LC_ALL` or the other `LC_*` variables, so only `LANG` sets the locale:
447
+
448
+ | Variable | Value |
449
+ | -------------------- | --------------------------------------------------------------------------------------------------------- |
450
+ | `PATH` | Yours |
451
+ | `LANG` | Yours, or `C.UTF-8` if you have none |
452
+ | `HOME`, `TMPDIR` | A new temporary directory for each run, removed afterwards |
453
+ | `TERM` | `dumb`; `xterm-256color` in color, pipe-escapes and control-chars, and in every run under a terminal |
454
+ | `CI` | `1`; unset in color, pipe-escapes and control-chars, so color libraries that force color in CI don't fail |
455
+ | `NO_UPDATE_NOTIFIER` | `1`, so update checks stay quiet |
456
+ | `NO_COLOR` | `1` in the color check's last run only |
457
+ | `SHELL` | `/bin/sh` in runs under a terminal, which `script` needs |
458
+ | `SCRIPT` | `/dev/null` in runs under a terminal on macOS, set by `script` itself |
459
+
460
+ The runs under a terminal are color's second and third, restore's, and control-chars'.
439
461
 
440
462
  ## FAQ
441
463
 
442
- **Why were ctrl-c, sigterm and control-chars skipped?** They need probes that a plain `--version` and `--help` run doesn't have: ctrl-c and sigterm need a command that keeps running, such as a server or a watcher, and control-chars needs one that prints file names from `{fixture}`. Add them with `--probe`, so one run covers every check: `npx cliprobe --probe "serve --port 0" --probe "list {fixture}" -- my-cli`.
464
+ **Why were ctrl-c, sigterm and control-chars skipped?** They need probes that a plain `--version` and `--help` run doesn't have: ctrl-c and sigterm need a command that keeps running, such as a server or a watcher, and control-chars needs one that prints file names from `{fixture}`. Add them with `--probe`, so one run covers every check: `npx cliprobe --probe "serve --port 0" --probe "list {fixture}" -- my-cli`. If the reason adds that the probe exited with a failure code, it never ran as intended: check its arguments, and with `-- node ./cli.js`, name the script in the probe (`--probe "./cli.js serve"`).
443
465
 
444
466
  **My program works when I run it, so why does a check fail?** cliprobe sets up conditions that are rare by hand: stdout closed before the program starts, output into a pipe, stdin that nobody writes to, a minimal environment. Reproduce the failure the way the check's section shows, for example `my-cli --help | head -n 1` for closed-pipe or `my-cli --help | cat -v` for color, and read the evidence in `--json`. If you still believe the verdict is wrong, [open a wrong verdict issue](https://github.com/KhaledSaeed18/cliprobe/issues/new?template=wrong_verdict.yml).
445
467
 
446
- **Why does my program behave differently under cliprobe?** It runs without your shell's variables or your home directory: the environment has only `PATH`, `LANG`, `TERM`, `CI` and a temporary `HOME` and `TMPDIR`. A program that needs a token or a config file from your home directory sees neither, as on a fresh CI runner.
468
+ **Why does my program behave differently under cliprobe?** It runs without your shell's variables or your home directory, with `TERM=dumb` and `CI=1` in most checks: [the probe's environment](#the-probes-environment) lists every variable. A program that needs a token or a config file from your home directory sees neither, as on a fresh CI runner.
447
469
 
448
470
  **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.
449
471
 
package/dist/cli.js CHANGED
@@ -667,6 +667,20 @@ function crashEvidence(stderr, messages = CRASH_MESSAGES) {
667
667
  const cwd = process.cwd() + "/";
668
668
  return `${message} (at ${frame.startsWith(cwd) ? frame.slice(cwd.length) : frame})`;
669
669
  }
670
+ /**
671
+ * Adds to a SKIP that a probe exited with a failure code, so a probe that never ran
672
+ * as intended (a typo, `--probe watch` running `node watch`) doesn't pass for a quiet
673
+ * skip. The evidence is the error line from stderr, when there is one.
674
+ */
675
+ function noteFailedExit(judgement, r) {
676
+ if (judgement.verdict !== "skip" || r.exitCode === null || r.exitCode === 0) return judgement;
677
+ const message = crashEvidence(r.stderr);
678
+ return {
679
+ ...judgement,
680
+ reason: `${judgement.reason}; it exited ${r.exitCode}, so the probe may not have run as intended`,
681
+ ...message && judgement.evidence === void 0 ? { evidence: `stderr: ${message}` } : {}
682
+ };
683
+ }
670
684
  // src/core/long-running.ts
671
685
  /**
672
686
  * Once one check has seen a probe still running at the timeout (a server, a
@@ -729,10 +743,10 @@ function judge(base, closed) {
729
743
  reason: `could not start: ${base.spawnError}`
730
744
  };
731
745
  if (base.timedOut) return judgeLongRunning(base, closed);
732
- if (base.stdoutBytes === 0) return {
746
+ if (base.stdoutBytes === 0) return noteFailedExit({
733
747
  verdict: "skip",
734
748
  reason: "wrote nothing to stdout, so a closed stdout is never touched"
735
- };
749
+ }, base);
736
750
  if (closed.timedOut) return {
737
751
  verdict: "fail",
738
752
  reason: "hung after stdout was closed"
@@ -1025,7 +1039,7 @@ function detect() {
1025
1039
  } catch (error) {
1026
1040
  if (error instanceof Error && "code" in error && error.code === "ENOENT") return {
1027
1041
  ok: false,
1028
- reason: "script(1) not found; install util-linux (Debian and Ubuntu: bsdutils; Alpine: util-linux-misc)"
1042
+ reason: "script(1) not found; install the package that has it (Debian and Ubuntu: bsdutils; Fedora: util-linux-script; Alpine: util-linux-misc)"
1029
1043
  };
1030
1044
  }
1031
1045
  return {
@@ -1234,10 +1248,10 @@ function judgeColor(runs) {
1234
1248
  reason: "no color in a pipe; in a terminal it waited for input, so it was not compared"
1235
1249
  };
1236
1250
  if (!findStyle(tty.output)) {
1237
- if (!(runs.pipe.stdoutBytes > 0 || runs.pipe.stderr.length > 0 || tty.output)) return {
1251
+ if (!(runs.pipe.stdoutBytes > 0 || runs.pipe.stderr.length > 0 || tty.output)) return noteFailedExit({
1238
1252
  verdict: "skip",
1239
1253
  reason: "printed nothing, so there is no color to check"
1240
- };
1254
+ }, runs.pipe);
1241
1255
  return {
1242
1256
  verdict: "pass",
1243
1257
  reason: "no color in a pipe or in a terminal"
@@ -1472,10 +1486,13 @@ function judgeControlChars(runs) {
1472
1486
  verdict: "skip",
1473
1487
  reason: "still running in a terminal at the timeout, and had not printed the file names in {fixture}"
1474
1488
  };
1475
- if (!tty.output.includes("plain.txt")) return {
1476
- verdict: "skip",
1477
- reason: "did not print the file names in {fixture}, so there was nothing to escape"
1478
- };
1489
+ if (!tty.output.includes("plain.txt")) {
1490
+ const skip = {
1491
+ verdict: "skip",
1492
+ reason: "did not print the file names in {fixture}, so there was nothing to escape"
1493
+ };
1494
+ return pipe ? noteFailedExit(skip, pipe) : skip;
1495
+ }
1479
1496
  const raw = rawNames(tty.output);
1480
1497
  const failing = raw.filter((h) => h.severity === "fail");
1481
1498
  if (failing.length) return {
@@ -1576,10 +1593,10 @@ function judgeSigterm(r) {
1576
1593
  verdict: "error",
1577
1594
  reason: `could not start: ${r.spawnError}`
1578
1595
  };
1579
- if (r.signalSentMs === void 0) return {
1596
+ if (r.signalSentMs === void 0) return noteFailedExit({
1580
1597
  verdict: "skip",
1581
1598
  reason: `finished in ${r.durationMs} ms, before SIGTERM at ${SIGTERM_DELAY_MS} ms; probe a command that keeps running`
1582
- };
1599
+ }, r);
1583
1600
  if (r.timedOut) return {
1584
1601
  verdict: "warn",
1585
1602
  reason: `ignored SIGTERM: still running ${SIGTERM_GRACE_MS / 1e3} s later, so docker stop or a process manager has to kill it`
@@ -1666,10 +1683,10 @@ function judgeCtrlC(r) {
1666
1683
  verdict: "error",
1667
1684
  reason: `could not start: ${r.spawnError}`
1668
1685
  };
1669
- if (r.signalSentMs === void 0) return {
1686
+ if (r.signalSentMs === void 0) return noteFailedExit({
1670
1687
  verdict: "skip",
1671
1688
  reason: `finished in ${r.durationMs} ms, before Ctrl-C at ${CTRL_C_DELAY_MS} ms; probe a command that keeps running`
1672
- };
1689
+ }, r);
1673
1690
  if (r.timedOut) return {
1674
1691
  verdict: "fail",
1675
1692
  reason: `ignored Ctrl-C: still running ${CTRL_C_GRACE_MS / 1e3} s later`
@@ -1795,10 +1812,10 @@ function judgePipeEscapes(r) {
1795
1812
  if (!stdout && !r.stderr) return r.timedOut ? {
1796
1813
  verdict: "skip",
1797
1814
  reason: `${stillRunning(r.durationMs)} and printed nothing so far`
1798
- } : {
1815
+ } : noteFailedExit({
1799
1816
  verdict: "skip",
1800
1817
  reason: "printed nothing, so there is nothing to check"
1801
- };
1818
+ }, r);
1802
1819
  if (r.timedOut) return {
1803
1820
  verdict: "pass",
1804
1821
  reason: `no cursor, erase, hyperlink, title or redraw codes in a pipe (${stillRunning(r.durationMs)})`
@@ -2748,7 +2765,9 @@ Options:
2748
2765
  program, a server) instead of --version and --help
2749
2766
  --probe <args> Also probe "<command> <args>"; repeat it for several. Split
2750
2767
  like a shell command line: quotes and backslashes work,
2751
- variables and wildcards are not expanded
2768
+ variables and wildcards are not expanded. The args after
2769
+ <command> are not kept, so name the script in each probe:
2770
+ cliprobe --probe "./cli.js watch" -- node ./cli.js
2752
2771
  --check <name> Run only this check; repeat it or use commas for several
2753
2772
  --skip <name> Leave this check out; repeat it or use commas for several
2754
2773
  --strict Exit 1 on a warning too, not only on a failure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
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": {
@@ -97,7 +97,7 @@
97
97
  "oxlint-tsgolint": "^7.0.2007",
98
98
  "prettier": "^3.10.1",
99
99
  "publint": "^0.3.25",
100
- "semantic-release": "^25.0.9",
100
+ "semantic-release": "^26.0.1",
101
101
  "tsdown": "^0.23.1",
102
102
  "typescript": "^7.0.2",
103
103
  "vitest": "^5.1.0"