cliprobe 1.10.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
 
@@ -98,7 +102,7 @@ The other checks cover the rest of what goes wrong between a program and the thi
98
102
  - [JSON output](#json-output)
99
103
  - [In your test suite](#in-your-test-suite)
100
104
  - [Stability](#stability)
101
- - [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)
102
106
  - [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
103
107
  - [Agent skill](#agent-skill)
104
108
  - [Safety](#safety)
@@ -350,7 +354,7 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
350
354
 
351
355
  ## Checks
352
356
 
353
- 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`.
354
358
 
355
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:
356
360
 
@@ -385,6 +389,20 @@ cliprobe runs the command twice: once normally, then with stdout set to `/dev/fu
385
389
 
386
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.
387
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
+
388
406
  ### color
389
407
 
390
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:
@@ -500,6 +518,16 @@ process.stdout.on('error', (error) => {
500
518
  });
501
519
  ```
502
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
+
503
531
  The same handler catches writes made with `console.log`, which otherwise drops a failed write silently and lets the program exit 0.
504
532
 
505
533
  **color:** decide once, from the stream you write to:
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as shellJoin, D as onInterrupt, E as handleInterrupts, S as MAX_TIMEOUT_MS, T as safe, _ as CONFIG_FILE, b as ProbeError, d as describeAccept, f as mainProbe, h as VERSION, l as prepare, m as planFromConfig, n as FORMAT_NAMES, o as execute, p as planFromArgs, r as isFormat, s as exitCodeFor, t as FORMATS, u as DEFAULT_TIMEOUT_MS, v as loadConfig, w as shellSplit, x as UsageError } from "./report-DuFcZAqG.js";
2
+ import { C as shellJoin, D as onInterrupt, E as handleInterrupts, S as MAX_TIMEOUT_MS, T as safe, _ as CONFIG_FILE, b as ProbeError, d as describeAccept, f as mainProbe, h as VERSION, l as prepare, m as planFromConfig, n as FORMAT_NAMES, o as execute, p as planFromArgs, r as isFormat, s as exitCodeFor, t as FORMATS, u as DEFAULT_TIMEOUT_MS, v as loadConfig, w as shellSplit, x as UsageError } from "./report-6mELXFtT.js";
3
3
  import { accessSync, constants, existsSync, lstatSync, readlinkSync, realpathSync, rmSync, statSync } from "node:fs";
4
4
  import { dirname, resolve, sep } from "node:path";
5
5
  import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
@@ -278,6 +278,11 @@ Checks:
278
278
  if it exits 0 anyway, so the lost output looks like success,
279
279
  crashes with a stack trace, or hangs. A careful program prints
280
280
  the error and exits non-zero.
281
+ slow-pipe Runs the command with stdout in a file, then in a pipe nobody
282
+ reads until it exits. Warns if the end of its output is lost,
283
+ as when a Node.js program calls process.exit() while output
284
+ is still waiting for the pipe. Skips output under 64 KiB,
285
+ which a pipe holds whole.
281
286
  color Runs the command into a pipe, then under a terminal, then under
282
287
  a terminal with NO_COLOR=1. Fails if color codes reach a pipe;
283
288
  warns if color goes to a piped stderr or NO_COLOR is ignored.
package/dist/index.d.ts CHANGED
@@ -31,7 +31,7 @@ interface Result {
31
31
  };
32
32
  }
33
33
  /** The name of every check, in the order they run and are reported. */
34
- export declare const CHECK_NAMES: readonly ["closed-pipe", "write-error", "color", "pipe-escapes", "stdin", "ctrl-c", "sigterm", "restore", "control-chars", "startup", "baseline"];
34
+ export declare const CHECK_NAMES: readonly ["closed-pipe", "write-error", "slow-pipe", "color", "pipe-escapes", "stdin", "ctrl-c", "sigterm", "restore", "control-chars", "startup", "baseline"];
35
35
  type CheckName = (typeof CHECK_NAMES)[number];
36
36
  /** The file `cliprobe` reads from the current directory when no command is given. */
37
37
  export declare const CONFIG_FILE = "cliprobe.config.json";
@@ -152,6 +152,21 @@ interface StdinResult extends Result {
152
152
  /** Milliseconds from closing stdin to the program finishing, when that was measured. */
153
153
  finishedAfterCloseMs: number | null;
154
154
  }
155
+ interface SlowPipeResult extends Result {
156
+ /** The run with stdout in a file, where no write waits: all of the output. */
157
+ baseline: {
158
+ exitCode: number | null;
159
+ signal: SignalName | null;
160
+ stdoutBytes: number;
161
+ };
162
+ /** The run with stdout in a pipe that was read late; null when it didn't run. */
163
+ slow: {
164
+ exitCode: number | null;
165
+ signal: SignalName | null;
166
+ timedOut: boolean;
167
+ stdoutBytes: number;
168
+ } | null;
169
+ }
155
170
  interface WriteErrorResult extends Result {
156
171
  baseline: {
157
172
  exitCode: number | null;
@@ -177,6 +192,7 @@ type Details<T extends Result> = Omit<T, keyof Result>;
177
192
  interface DetailsByCheck {
178
193
  "closed-pipe": Details<ClosedPipeResult>;
179
194
  "write-error": Details<WriteErrorResult>;
195
+ "slow-pipe": Details<SlowPipeResult>;
180
196
  color: Details<ColorResult>;
181
197
  "pipe-escapes": Details<PipeEscapesResult>;
182
198
  stdin: Details<StdinResult>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { O as runInterruptCleanups, _ as CONFIG_FILE, a as toJsonReport, b as ProbeError, c as failsRun, g as CHECK_NAMES, h as VERSION, i as fromJsonReport, l as prepare, m as planFromConfig, n as FORMAT_NAMES, o as execute, r as isFormat, s as exitCodeFor, t as FORMATS, v as loadConfig, x as UsageError, y as validateConfig } from "./report-DuFcZAqG.js";
1
+ import { O as runInterruptCleanups, _ as CONFIG_FILE, a as toJsonReport, b as ProbeError, c as failsRun, g as CHECK_NAMES, h as VERSION, i as fromJsonReport, l as prepare, m as planFromConfig, n as FORMAT_NAMES, o as execute, r as isFormat, s as exitCodeFor, t as FORMATS, v as loadConfig, x as UsageError, y as validateConfig } from "./report-6mELXFtT.js";
2
2
  // src/index.ts
3
3
  /**
4
4
  * cliprobe as a library: run the checks from a test suite or a script and get the
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { accessSync, closeSync, constants, existsSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
2
+ import { accessSync, closeSync, constants, existsSync, fstatSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
3
3
  import { execFile, execFileSync, spawn } from "node:child_process";
4
4
  import { delimiter, join } from "node:path";
5
5
  import { tmpdir } from "node:os";
@@ -411,6 +411,8 @@ const DEV_FULL = "/dev/full";
411
411
  /** Whether this system has /dev/full (Linux does; macOS doesn't). */
412
412
  const hasDevFull = () => existsSync(DEV_FULL);
413
413
  const STDOUT_CAP = 1048576;
414
+ /** How often the size of that file is read. */
415
+ const FILE_POLL_MS = 20;
414
416
  /**
415
417
  * The longest delay setTimeout takes (2^31 - 1 ms, about 24.8 days). Node turns
416
418
  * anything longer into 1 ms, which would kill every probe at once.
@@ -431,7 +433,7 @@ const delay = (ms) => new Promise((resolve) => {
431
433
  * stdout fails (EPIPE, or SIGPIPE for programs that keep the default handler).
432
434
  * With `fullStdout`, stdout is /dev/full, so every write fails with ENOSPC.
433
435
  */
434
- function run(command, args, { closedStdout = false, fullStdout = false, timeout, env: overrides = {}, extraGroup, signal, stdin = "null", leftoversMs = 250 }) {
436
+ function run(command, args, { closedStdout = false, fullStdout = false, fileStdout = false, slowStdout = false, timeout, env: overrides = {}, extraGroup, signal, stdin = "null", leftoversMs = 250 }) {
435
437
  const { dir, env: base } = sandbox();
436
438
  const env = { ...base };
437
439
  for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
@@ -444,11 +446,22 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
444
446
  stdoutFd = openSync(fifo, constants.O_WRONLY | constants.O_NONBLOCK);
445
447
  closeSync(reader);
446
448
  } else if (fullStdout) stdoutFd = openSync(DEV_FULL, "w");
449
+ else if (fileStdout) stdoutFd = openSync(join(dir, "stdout"), "w+");
450
+ let slowFd;
451
+ if (slowStdout) {
452
+ const fifo = join(dir, "stdout.fifo");
453
+ execFileSync("mkfifo", [fifo]);
454
+ const first = openSync(fifo, constants.O_RDONLY | constants.O_NONBLOCK);
455
+ stdoutFd = openSync(fifo, constants.O_WRONLY);
456
+ slowFd = openSync(fifo, constants.O_RDONLY);
457
+ closeSync(first);
458
+ }
447
459
  return new Promise((resolve) => {
448
460
  let stdoutBytes = 0;
449
461
  const stdoutChunks = [];
450
462
  let stderr = "";
451
463
  let timedOut = false;
464
+ let overflowed = false;
452
465
  let finished = false;
453
466
  let exited = false;
454
467
  let signalSentMs;
@@ -478,17 +491,25 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
478
491
  finished = true;
479
492
  clearInterval(pollTimer);
480
493
  unregister();
481
- if (typeof stdoutFd === "number") closeSync(stdoutFd);
494
+ let stdout = Buffer.concat(stdoutChunks).subarray(0, STDOUT_CAP);
495
+ if (fileStdout && typeof stdoutFd === "number") {
496
+ stdoutBytes = fstatSync(stdoutFd).size;
497
+ stdout = Buffer.alloc(Math.min(stdoutBytes, STDOUT_CAP));
498
+ readSync(stdoutFd, stdout, 0, stdout.length, 0);
499
+ }
500
+ if (typeof stdoutFd === "number" && !writeEndClosed) closeSync(stdoutFd);
501
+ if (slowFd !== void 0) closeSync(slowFd);
502
+ reader?.kill("SIGKILL");
482
503
  rmSync(dir, {
483
504
  recursive: true,
484
505
  force: true
485
506
  });
486
- const stdout = Buffer.concat(stdoutChunks).subarray(0, STDOUT_CAP);
487
507
  resolve({
488
508
  stdoutBytes,
489
509
  stdout,
490
510
  stderr,
491
511
  timedOut,
512
+ ...overflowed ? { overflowed } : {},
492
513
  durationMs: exitMs ?? Math.round(performance.now() - start),
493
514
  ...signalSentMs === void 0 ? {} : {
494
515
  signalSentMs,
@@ -498,6 +519,14 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
498
519
  ...outcome
499
520
  });
500
521
  };
522
+ let writeEndClosed = false;
523
+ /** Closes cliprobe's copy of the FIFO's write end, so the reader sees its end. */
524
+ const closeWriteEnd = () => {
525
+ if (!slowStdout || typeof stdoutFd !== "number" || writeEndClosed) return;
526
+ writeEndClosed = true;
527
+ closeSync(stdoutFd);
528
+ };
529
+ let reader;
501
530
  let child;
502
531
  try {
503
532
  child = spawn(command, [...args], {
@@ -518,6 +547,43 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
518
547
  return;
519
548
  }
520
549
  const proc = child;
550
+ closeWriteEnd();
551
+ let onEnded;
552
+ const outputEnded = new Promise((resolveEnd) => {
553
+ onEnded = resolveEnd;
554
+ });
555
+ const resolveEnded = () => onEnded?.();
556
+ const listen = (stream) => {
557
+ if (stream === null) {
558
+ resolveEnded();
559
+ return;
560
+ }
561
+ stream.on("data", (chunk) => {
562
+ if (stdoutBytes < STDOUT_CAP) stdoutChunks.push(chunk);
563
+ stdoutBytes += chunk.length;
564
+ });
565
+ stream.once("close", resolveEnded);
566
+ stream.once("error", resolveEnded);
567
+ };
568
+ /**
569
+ * Starts reading the slow pipe: `cat` reads the FIFO and cliprobe reads `cat`,
570
+ * since Node can't read a FIFO as a stream on macOS (kqueue stops reporting it).
571
+ */
572
+ const startReading = () => {
573
+ if (slowFd === void 0) return;
574
+ const fd = slowFd;
575
+ slowFd = void 0;
576
+ reader = spawn("cat", [], { stdio: [
577
+ fd,
578
+ "pipe",
579
+ "ignore"
580
+ ] });
581
+ closeSync(fd);
582
+ reader.once("error", resolveEnded);
583
+ listen(reader.stdout);
584
+ };
585
+ if (!slowStdout) listen(proc.stdout);
586
+ const readTimer = slowStdout ? setTimeout(startReading, 500) : void 0;
521
587
  if (proc.pid !== void 0) {
522
588
  tree = new ProcessTree(proc.pid, groups);
523
589
  let polling = false;
@@ -539,6 +605,13 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
539
605
  recordTree();
540
606
  killRun();
541
607
  }, Math.min(timeout, MAX_TIMEOUT_MS));
608
+ const sizeTimer = fileStdout && typeof stdoutFd === "number" ? setInterval(() => {
609
+ if (exited || overflowed || typeof stdoutFd !== "number") return;
610
+ if (fstatSync(stdoutFd).size <= 67108864) return;
611
+ overflowed = true;
612
+ recordTree();
613
+ killRun();
614
+ }, FILE_POLL_MS) : void 0;
542
615
  const signalTimer = signal && setTimeout(() => {
543
616
  if (exited || proc.pid === void 0) return;
544
617
  recordTree();
@@ -560,29 +633,33 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
560
633
  clearTimeout(timer);
561
634
  clearTimeout(signalTimer);
562
635
  clearTimeout(closeTimer);
636
+ clearTimeout(readTimer);
637
+ clearInterval(sizeTimer);
563
638
  clearInterval(pollTimer);
639
+ startReading();
564
640
  tree?.programExited();
565
641
  proc.stdin?.destroy();
566
642
  (async () => {
567
643
  if (tree) {
568
- const left = await watchLeftovers(tree, timedOut ? 0 : leftoversMs);
644
+ const left = await watchLeftovers(tree, timedOut || overflowed ? 0 : leftoversMs);
569
645
  killAll(left, groups());
570
646
  leftRunning = left.map((p) => ({
571
647
  pid: p.pid,
572
648
  command: p.command
573
649
  }));
574
650
  }
575
- if (!closed) {
651
+ if (!closed || slowStdout) {
576
652
  let giveUp;
577
653
  const gaveUp = new Promise((resolveWait) => {
578
654
  giveUp = setTimeout(resolveWait, CLOSE_WAIT_MS);
579
655
  });
580
- await Promise.race([outputClosed, gaveUp]);
656
+ await Promise.race([Promise.all([outputClosed, outputEnded]), gaveUp]);
581
657
  clearTimeout(giveUp);
582
658
  }
583
659
  proc.stdout?.destroy();
660
+ reader?.stdout?.destroy();
584
661
  proc.stderr?.destroy();
585
- const notRun = timedOut ? void 0 : shellFallbackError(command, exitCode, stderr);
662
+ const notRun = timedOut || overflowed ? void 0 : shellFallbackError(command, exitCode, stderr);
586
663
  finish({
587
664
  exitCode,
588
665
  signal: exitSignal,
@@ -590,16 +667,14 @@ function run(command, args, { closedStdout = false, fullStdout = false, timeout,
590
667
  });
591
668
  })();
592
669
  });
593
- proc.stdout?.on("data", (chunk) => {
594
- if (stdoutBytes < STDOUT_CAP) stdoutChunks.push(chunk);
595
- stdoutBytes += chunk.length;
596
- });
597
670
  proc.stderr?.on("data", (chunk) => {
598
671
  if (stderr.length < STDERR_CAP) stderr += chunk.toString("utf8");
599
672
  });
600
673
  proc.on("error", (error) => {
601
674
  clearTimeout(timer);
602
675
  clearTimeout(signalTimer);
676
+ clearTimeout(readTimer);
677
+ clearInterval(sizeTimer);
603
678
  finish({
604
679
  exitCode: null,
605
680
  signal: null,
@@ -962,7 +1037,7 @@ function judgeLongRunning$1(base, closed) {
962
1037
  };
963
1038
  }
964
1039
  /** Compares a normal run with a closed-stdout run of the same invocation. */
965
- function judge$1(base, closed) {
1040
+ function judge$2(base, closed) {
966
1041
  if (base.spawnError) return {
967
1042
  verdict: "error",
968
1043
  reason: `could not start: ${base.spawnError}`
@@ -1013,7 +1088,7 @@ async function closedPipe(command, args, ctx) {
1013
1088
  return {
1014
1089
  check: "closed-pipe",
1015
1090
  invocation: [command, ...args],
1016
- ...judge$1(base, closed),
1091
+ ...judge$2(base, closed),
1017
1092
  baseline: {
1018
1093
  exitCode: base.exitCode,
1019
1094
  signal: base.signal,
@@ -2280,6 +2355,100 @@ const restoreCheck = {
2280
2355
  return results;
2281
2356
  }
2282
2357
  };
2358
+ // src/checks/slow-pipe.ts
2359
+ /** Whether what arrived through the pipe is the start of what the file got. */
2360
+ const isPrefix = (file, slow) => file.stdout.subarray(0, slow.stdout.length).equals(slow.stdout);
2361
+ /**
2362
+ * Whether a second run into a file wrote what the first did: output that
2363
+ * changes from run to run can be shorter in the pipe for that reason alone.
2364
+ */
2365
+ const sameOutput = (a, b) => a.stdoutBytes === b.stdoutBytes && a.stdout.equals(b.stdout);
2366
+ /**
2367
+ * Compares a run whose stdout is a file, where every write completes at once,
2368
+ * with a run whose stdout is a pipe that nobody reads until the program exits
2369
+ * (or half a second passes). A program that exits while output is still waiting
2370
+ * for the pipe loses it: in Node.js, `process.exit()` after a large
2371
+ * `console.log` or `process.stdout.write`. A shorter output only counts when
2372
+ * `again`, another run into a file, wrote the same as the first. Warn-only:
2373
+ * new in 1.11. Tried 2026-12-06 on 15 real commands with large output: 12
2374
+ * passed, 3 warned (he, jsesc, cssesc), each reproduced with a shell pipe.
2375
+ */
2376
+ function judge$1(file, slow, again) {
2377
+ if (file.spawnError) return {
2378
+ verdict: "error",
2379
+ reason: `could not start: ${file.spawnError}`
2380
+ };
2381
+ if (file.timedOut) return {
2382
+ verdict: "skip",
2383
+ reason: `${stillRunning(file.durationMs)}, so it has no last output to lose`
2384
+ };
2385
+ if (file.overflowed) return {
2386
+ verdict: "skip",
2387
+ reason: "wrote more than 64 MiB to stdout, more than this check compares"
2388
+ };
2389
+ if (!slow) return noteFailedExit({
2390
+ verdict: "skip",
2391
+ reason: file.stdoutBytes === 0 ? "wrote nothing to stdout, so there is no output to lose" : `wrote ${file.stdoutBytes} bytes to stdout, which a pipe holds whole (64 KiB), so none can be lost`
2392
+ }, file);
2393
+ if (slow.timedOut) return {
2394
+ verdict: "warn",
2395
+ reason: "hung when its stdout pipe was read slowly"
2396
+ };
2397
+ if (slow.stdoutBytes === file.stdoutBytes) return {
2398
+ verdict: "pass",
2399
+ reason: `all ${file.stdoutBytes} bytes of stdout arrived through a slowly read pipe`
2400
+ };
2401
+ if (slow.stdoutBytes < file.stdoutBytes && isPrefix(file, slow) && again && sameOutput(file, again)) return {
2402
+ verdict: "warn",
2403
+ reason: `lost the end of its output when its stdout pipe was read slowly, and exited ${slow.exitCode ?? slow.signal}`,
2404
+ evidence: `stdout stopped at byte ${slow.stdoutBytes} of ${file.stdoutBytes}`
2405
+ };
2406
+ return {
2407
+ verdict: "skip",
2408
+ reason: `its output differs from run to run (${file.stdoutBytes} and ${slow.stdoutBytes} bytes), so the runs can't be compared`
2409
+ };
2410
+ }
2411
+ async function slowPipe(command, args, ctx) {
2412
+ const file = await run(command, args, {
2413
+ fileStdout: true,
2414
+ timeout: probeTimeout(ctx, command, args)
2415
+ });
2416
+ if (file.timedOut) markLongRunning(ctx, command, args);
2417
+ const slow = !file.spawnError && !file.timedOut && !file.overflowed && file.stdoutBytes > 65536 ? await run(command, args, {
2418
+ slowStdout: true,
2419
+ timeout: ctx.timeout
2420
+ }) : void 0;
2421
+ const again = slow && !slow.timedOut && slow.stdoutBytes < file.stdoutBytes && isPrefix(file, slow) ? await run(command, args, {
2422
+ fileStdout: true,
2423
+ timeout: ctx.timeout
2424
+ }) : void 0;
2425
+ return {
2426
+ check: "slow-pipe",
2427
+ invocation: [command, ...args],
2428
+ ...judge$1(file, slow, again),
2429
+ baseline: {
2430
+ exitCode: file.exitCode,
2431
+ signal: file.signal,
2432
+ stdoutBytes: file.stdoutBytes
2433
+ },
2434
+ slow: slow ? {
2435
+ exitCode: slow.exitCode,
2436
+ signal: slow.signal,
2437
+ timedOut: slow.timedOut,
2438
+ stdoutBytes: slow.stdoutBytes
2439
+ } : null
2440
+ };
2441
+ }
2442
+ const slowPipeCheck = {
2443
+ name: "slow-pipe",
2444
+ kind: "check",
2445
+ summary: "loses the end of its output when its pipe is read slowly (| less)",
2446
+ async run(target, ctx) {
2447
+ const results = [];
2448
+ for (const { args } of target.probes) results.push(await slowPipe(target.command, args, ctx));
2449
+ return results;
2450
+ }
2451
+ };
2283
2452
  function median(values) {
2284
2453
  const sorted = [...values].sort((a, b) => a - b);
2285
2454
  const mid = Math.floor(sorted.length / 2);
@@ -2597,6 +2766,7 @@ const writeErrorCheck = {
2597
2766
  const CHECK_NAMES = [
2598
2767
  "closed-pipe",
2599
2768
  "write-error",
2769
+ "slow-pipe",
2600
2770
  "color",
2601
2771
  "pipe-escapes",
2602
2772
  "stdin",
@@ -2611,6 +2781,7 @@ const CHECK_NAMES = [
2611
2781
  const CHECKS = [
2612
2782
  closedPipeCheck,
2613
2783
  writeErrorCheck,
2784
+ slowPipeCheck,
2614
2785
  colorCheck,
2615
2786
  pipeEscapesCheck,
2616
2787
  stdinCheckDefinition,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.10.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.",
3
+ "version": "1.11.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, output cut short when a pipe is read slowly, 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"
package/schema.json CHANGED
@@ -74,6 +74,7 @@
74
74
  "enum": [
75
75
  "closed-pipe",
76
76
  "write-error",
77
+ "slow-pipe",
77
78
  "color",
78
79
  "pipe-escapes",
79
80
  "stdin",
@@ -181,6 +182,22 @@
181
182
  }
182
183
  }
183
184
  },
185
+ {
186
+ "if": {
187
+ "properties": {
188
+ "check": {
189
+ "const": "slow-pipe"
190
+ }
191
+ }
192
+ },
193
+ "then": {
194
+ "properties": {
195
+ "details": {
196
+ "$ref": "#/$defs/details.slow-pipe"
197
+ }
198
+ }
199
+ }
200
+ },
184
201
  {
185
202
  "if": {
186
203
  "properties": {
@@ -423,6 +440,55 @@
423
440
  }
424
441
  }
425
442
  },
443
+ "details.slow-pipe": {
444
+ "type": "object",
445
+ "description": "A run with stdout in a file, where no write waits, then a run with stdout in a pipe that nobody reads until the program exits or half a second passes.",
446
+ "required": ["baseline", "slow"],
447
+ "properties": {
448
+ "baseline": {
449
+ "type": "object",
450
+ "description": "The run into a file: all of the output.",
451
+ "required": ["exitCode", "signal", "stdoutBytes"],
452
+ "properties": {
453
+ "exitCode": {
454
+ "type": ["integer", "null"],
455
+ "description": "Exit code; null if it was killed by a signal or never ran."
456
+ },
457
+ "signal": {
458
+ "type": ["string", "null"],
459
+ "description": "Signal that ended it; null if it exited."
460
+ },
461
+ "stdoutBytes": {
462
+ "type": "integer",
463
+ "minimum": 0
464
+ }
465
+ }
466
+ },
467
+ "slow": {
468
+ "type": ["object", "null"],
469
+ "description": "The run into a slowly read pipe; null when it didn't run (no output, less than 64 KiB, more than 64 MiB, or a program that keeps running).",
470
+ "required": ["exitCode", "signal", "timedOut", "stdoutBytes"],
471
+ "properties": {
472
+ "exitCode": {
473
+ "type": ["integer", "null"],
474
+ "description": "Exit code; null if it was killed by a signal or never ran."
475
+ },
476
+ "signal": {
477
+ "type": ["string", "null"],
478
+ "description": "Signal that ended it; null if it exited."
479
+ },
480
+ "timedOut": {
481
+ "type": "boolean"
482
+ },
483
+ "stdoutBytes": {
484
+ "type": "integer",
485
+ "minimum": 0,
486
+ "description": "Bytes that arrived through the pipe; fewer than the baseline's when output was lost."
487
+ }
488
+ }
489
+ }
490
+ }
491
+ },
426
492
  "details.color": {
427
493
  "type": "object",
428
494
  "description": "Runs into a pipe, under a terminal and under a terminal with NO_COLOR=1; null for a run that was not needed.",