cliprobe 1.4.4 → 1.5.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 CHANGED
@@ -265,15 +265,17 @@ Many classic tools (git, BSD `ls` and `grep`) color correctly but don't implemen
265
265
 
266
266
  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:
267
267
 
268
- | Verdict | Meaning |
269
- | ------- | --------------------------------------------------------------------------------- |
270
- | `PASS` | None of those codes reached the pipe (color is the color check's business) |
271
- | `FAIL` | An escape sequence reached stdout or stderr; the reason lists which kinds |
272
- | `WARN` | Only carriage returns reached the pipe, redrawing a line as a progress meter does |
273
- | `SKIP` | Printed nothing |
268
+ | Verdict | Meaning |
269
+ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
270
+ | `PASS` | None of those codes reached the pipe (color is the color check's business) |
271
+ | `FAIL` | An escape sequence reached stdout or stderr; the reason lists which kinds |
272
+ | `WARN` | Only carriage returns reached the pipe, redrawing a line as a progress meter does, or only control codes this check started looking for in 1.5 |
273
+ | `SKIP` | Printed nothing |
274
274
 
275
275
  A carriage-return redraw only warns because some tools draw a progress meter on stderr into a pipe by design: curl does, unless you pass `-s`. Before this check could fail, it ran on 78 commands doing real work (builds, linters, test runners, scaffolders, package managers and system tools) and 38 watch modes and dev servers, offline in a throwaway container. Every escape sequence it found was a real bug, such as a prompt hiding the cursor in a pipe (`changeset init`), `mocha --watch` hiding the cursor and `tsc --watch` clearing the screen; none was a false failure. Probe a command that does real work, such as an install or a build: `--help` and `--version` rarely draw spinners. 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, passes. If the codes come from data you passed in (a file you `cat`), they are yours, not the program's.
276
276
 
277
+ Since 1.5 the check also finds the other escape sequences: saving and restoring the cursor (`ESC 7`, `ESC 8`), a full reset that clears the screen (`ESC c`), character set and keypad switches, device control strings (DCS, APC, PM, SOS), OSC codes without a `;` (`ESC ] 104`), and their 8-bit forms (C1 CSI and OSC, such as `0x9b 2J`). These only warn until a census of real tools shows they flag no working program; `details.stdoutKinds` and `details.stderrKinds` name them as `escape`, `reset`, `string`, `osc` and `c1`. A program that also prints one of the sequences above still fails.
278
+
277
279
  ### stdin
278
280
 
279
281
  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, with a pipe it closes partway through. Finishing only after the close proves stdin was the cause. The open pipe gets 3 seconds, or twice the time the command took with stdin closed plus 1 second if that is longer, so a program that is just slow to answer isn't mistaken for one that waits. The pipe in the third run is closed after 1 second, or after that longer time for a slow command. Each run still stops at `--timeout`. Results:
@@ -291,15 +293,17 @@ In the census of the top 100 npm CLIs, 9 of 238 `--help` and `--version` runs fa
291
293
 
292
294
  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. stdin is left open, as a terminal leaves it, so a server that stops at the end of stdin (`esbuild --serve`) keeps running until the Ctrl-C. Results:
293
295
 
294
- | Verdict | Meaning |
295
- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
296
- | `PASS` | Stopped by SIGINT, exited 130 (the convention), or exited with another failure code |
297
- | `FAIL` | Still running 3 seconds later, or printed a stack trace or traceback after the Ctrl-C |
298
- | `WARN` | Exited 0, so a script or an agent can't tell the work was interrupted, or exited but left processes running that ignored the Ctrl-C (the evidence names the first) |
299
- | `SKIP` | Finished before the Ctrl-C, as `--version` and `--help` do: probe a command that keeps running |
296
+ | Verdict | Meaning |
297
+ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
298
+ | `PASS` | Stopped by SIGINT, exited 130 (the convention), or exited with another failure code |
299
+ | `FAIL` | Still running 3 seconds later, or printed a stack trace or traceback after the Ctrl-C |
300
+ | `WARN` | Exited 0, so a script or an agent can't tell the work was interrupted, or exited but left processes running that ignored the Ctrl-C (the evidence names the first) |
301
+ | `SKIP` | Finished before the Ctrl-C, as `--version` and `--help` do: probe a command that keeps running. With `--bare`, also a command still running after the Ctrl-C that never printed anything, as a REPL does |
300
302
 
301
303
  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. Across 42 watch modes, dev servers and long tasks run offline (vite, webpack, tsc, jest, Next.js, Nuxt, Astro, wrangler, nodemon and more), every one stopped within 60 ms of the Ctrl-C, whether it came after 1, 3 or 6 seconds, so the timing rarely matters. 13 of them exit 0 on purpose, among them `tsc --watch`, webpack, `next dev` and `nuxt dev`: that is a warn, not a fail.
302
304
 
305
+ A REPL run with `--bare` (`npx cliprobe --bare -- python3`) gets a pipe as stdin here, not a terminal, so it waits to read a script and may not stop on Ctrl-C, which nobody at a terminal sees. So with `--bare`, a command that is still running 3 seconds after the Ctrl-C and never printed anything is skipped, as restore skips REPLs, rather than failed. One that printed something first, such as a server's banner, still fails. To check a REPL's Ctrl-C, try it in a terminal.
306
+
303
307
  The verdict is about the program itself: it passes once it exits, even if a child still holds its output open. What it leaves running gets 1 more second to follow, then is listed and killed. A process still there ignored the Ctrl-C, as a shell's background job does (`sh -c 'worker & server'`), so it would outlive the terminal's Ctrl-C too: that is a warn, added in 1.4.
304
308
 
305
309
  ### sigterm
package/dist/cli.js CHANGED
@@ -853,12 +853,29 @@ function findStyle(text) {
853
853
  };
854
854
  }
855
855
  }
856
- /** CSI: ESC [ parameter bytes, intermediate bytes, one final byte. */
857
- const CSI = /\x1b\[([0-?]*)[ -/]*([@-~])/g;
858
- /** OSC: ESC ] number ; text, ended by BEL or ESC \. */
859
- const OSC = /\x1b\](\d*);[^\x07\x1b]*(?:\x07|\x1b\\)/g;
860
- /** A carriage return that does not end a CRLF line: a line being redrawn. */
861
- const BARE_CR = /\r(?!\n)/g;
856
+ /**
857
+ * Every control code findControls() knows, as alternatives tried in this order at each
858
+ * position, so one sequence is never counted twice:
859
+ * - csi: ESC [ parameter bytes, intermediate bytes, one final byte;
860
+ * - osc: ESC ] number ; text, ended by BEL or ESC ;
861
+ * - oscOther: any other OSC, such as ESC ] 104 BEL (no ";");
862
+ * - string: DCS, SOS, PM or APC (ESC P, X, ^ or _), with its text when ST ends it;
863
+ * - reset: ESC c, a full reset that clears the screen;
864
+ * - escape: any other ESC sequence: intermediates (ESC ( B) or one final byte (ESC 7);
865
+ * - c1: an 8-bit CSI, OSC, DCS, SOS, PM or APC introducer, with what it carries;
866
+ * - redraw: a carriage return that does not end a CRLF line: a line being redrawn.
867
+ * ESC \ (ST) alone ends a string and starts nothing.
868
+ */
869
+ const CONTROL = new RegExp([
870
+ String.raw`(?<csi>\x1b\[(?<params>[0-?]*)[ -/]*(?<final>[@-~]))`,
871
+ String.raw`(?<osc>\x1b\](?<code>\d*);[^\x07\x1b]*(?:\x07|\x1b\\))`,
872
+ String.raw`(?<oscOther>\x1b\][^\x07\x1b]*(?:\x07|\x1b\\))`,
873
+ String.raw`(?<string>\x1b[PX^_](?:[^\x1b]*\x1b\\)?)`,
874
+ String.raw`(?<reset>\x1bc)`,
875
+ String.raw`(?<escape>\x1b(?:[ -/]+[0-~]|[0-OQ-WYZ\x60-bd-~]))`,
876
+ String.raw`(?<c1>\x9b[0-?]*[ -/]*[@-~]?|[\x90\x98\x9d\x9e\x9f][^\x07\x1b\x9c]*(?:\x07|\x9c|\x1b\\)?)`,
877
+ String.raw`(?<redraw>\r(?!\n))`
878
+ ].join("|"), "g");
862
879
  /** How each kind reads in a report. */
863
880
  const CONTROL_LABELS = {
864
881
  cursor: "cursor movement",
@@ -867,7 +884,11 @@ const CONTROL_LABELS = {
867
884
  hyperlink: "hyperlink (OSC 8)",
868
885
  title: "window title",
869
886
  osc: "operating system command (OSC)",
870
- redraw: "carriage-return redraw"
887
+ redraw: "carriage-return redraw",
888
+ escape: "other escape sequence (such as saving the cursor or switching the character set)",
889
+ reset: "full terminal reset (ESC c)",
890
+ string: "device control string (DCS, APC, PM or SOS)",
891
+ c1: "8-bit control sequence (C1)"
871
892
  };
872
893
  function csiKind(params, final) {
873
894
  if (final === "m") return void 0;
@@ -880,7 +901,7 @@ function oscKind(code) {
880
901
  if (code === "0" || code === "1" || code === "2") return "title";
881
902
  return "osc";
882
903
  }
883
- function hitAt(text, index, sequence, kind) {
904
+ function hitAt(text, index, sequence, kind, warnOnly) {
884
905
  const before = text.slice(0, index);
885
906
  const start = before.lastIndexOf("\n") + 1;
886
907
  const newline = text.indexOf("\n", index);
@@ -889,32 +910,37 @@ function hitAt(text, index, sequence, kind) {
889
910
  kind,
890
911
  sequence,
891
912
  line: before.split("\n").length,
892
- text: text.slice(start, end).slice(0, 120)
913
+ text: text.slice(start, end).slice(0, 120),
914
+ warnOnly
893
915
  };
894
916
  }
917
+ /** The kind of one CONTROL match, and whether it may only warn; undefined for SGR. */
918
+ function classify(g) {
919
+ if (g["csi"] !== void 0) {
920
+ const kind = csiKind(g["params"] ?? "", g["final"] ?? "");
921
+ return kind && [kind, false];
922
+ }
923
+ if (g["osc"] !== void 0) return [oscKind(g["code"] ?? ""), false];
924
+ if (g["redraw"] !== void 0) return ["redraw", false];
925
+ if (g["oscOther"] !== void 0) return ["osc", true];
926
+ if (g["string"] !== void 0) return ["string", true];
927
+ if (g["reset"] !== void 0) return ["reset", true];
928
+ if (g["escape"] !== void 0) return ["escape", true];
929
+ return ["c1", true];
930
+ }
895
931
  /**
896
932
  * Every terminal control code in the text other than color and style (SGR):
897
933
  * cursor movement, erases, mode switches, OSC sequences such as hyperlinks and
898
- * window titles, and carriage returns that redraw a line. In reading order.
934
+ * window titles, carriage returns that redraw a line, and (warn-only) the other
935
+ * ESC sequences, control strings and 8-bit controls. In reading order.
899
936
  */
900
937
  function findControls(text) {
901
938
  const hits = [];
902
- for (const m of text.matchAll(CSI)) {
903
- const kind = csiKind(m[1] ?? "", m[2] ?? "");
904
- if (kind) hits.push({
905
- index: m.index,
906
- hit: hitAt(text, m.index, m[0], kind)
907
- });
939
+ for (const m of text.matchAll(CONTROL)) {
940
+ const found = classify(m.groups ?? {});
941
+ if (found) hits.push(hitAt(text, m.index, m[0], ...found));
908
942
  }
909
- for (const m of text.matchAll(OSC)) hits.push({
910
- index: m.index,
911
- hit: hitAt(text, m.index, m[0], oscKind(m[1] ?? ""))
912
- });
913
- for (const m of text.matchAll(BARE_CR)) hits.push({
914
- index: m.index,
915
- hit: hitAt(text, m.index, m[0], "redraw")
916
- });
917
- return hits.sort((a, b) => a.index - b.index).map((h) => h.hit);
943
+ return hits;
918
944
  }
919
945
  const ANY_ESCAPE = /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;
920
946
  /** The text with CSI and OSC escape sequences (color, cursor, links, titles) removed. */
@@ -1684,7 +1710,12 @@ const CTRL_C_GRACE_MS = 3e3;
1684
1710
  const CTRL_C_LEFTOVERS_MS = 1e3;
1685
1711
  /** Lines worth quoting from a trace printed on Ctrl-C, best first. */
1686
1712
  const TRACE_MESSAGES = [/^(KeyboardInterrupt|\w*Error\b|\w*Exception\b|panic:)/, TRACE_RE];
1687
- function judgeCtrlC(r) {
1713
+ /**
1714
+ * `bare` is true for the --bare probe, the command with no arguments. A REPL run that
1715
+ * way (python3) gets a pipe as stdin, reads it as a script and doesn't stop on SIGINT,
1716
+ * which no one at a terminal sees; restore, under a terminal, skips REPLs too (#43).
1717
+ */
1718
+ function judgeCtrlC(r, bare = false) {
1688
1719
  if (r.spawnError) return {
1689
1720
  verdict: "error",
1690
1721
  reason: `could not start: ${r.spawnError}`
@@ -1693,10 +1724,16 @@ function judgeCtrlC(r) {
1693
1724
  verdict: "skip",
1694
1725
  reason: `finished in ${r.durationMs} ms, before Ctrl-C at ${CTRL_C_DELAY_MS} ms; probe a command that keeps running`
1695
1726
  }, r);
1696
- if (r.timedOut) return {
1697
- verdict: "fail",
1698
- reason: `ignored Ctrl-C: still running ${CTRL_C_GRACE_MS / 1e3} s later`
1699
- };
1727
+ if (r.timedOut) {
1728
+ if (bare && r.stdoutBytes === 0 && r.stderr === "") return {
1729
+ verdict: "skip",
1730
+ reason: `still running ${CTRL_C_GRACE_MS / 1e3} s after Ctrl-C without printing anything, as a REPL does when stdin is a pipe (it waits for a script, not a keypress); run it in a terminal to check its Ctrl-C`
1731
+ };
1732
+ return {
1733
+ verdict: "fail",
1734
+ reason: `ignored Ctrl-C: still running ${CTRL_C_GRACE_MS / 1e3} s later`
1735
+ };
1736
+ }
1700
1737
  const after = r.stderr.slice(r.stderrAtSignal ?? 0);
1701
1738
  const ms = `${r.durationMs - r.signalSentMs} ms`;
1702
1739
  if (TRACE_RE.test(after)) return {
@@ -1744,7 +1781,7 @@ async function ctrlC(command, args) {
1744
1781
  return {
1745
1782
  check: "ctrl-c",
1746
1783
  invocation: [command, ...args],
1747
- ...judgeCtrlC(r),
1784
+ ...judgeCtrlC(r, args.length === 0),
1748
1785
  sentAfterMs: sent ?? null,
1749
1786
  exitedAfterMs: sent === void 0 || r.timedOut ? null : r.durationMs - sent,
1750
1787
  exitCode: r.exitCode,
@@ -1791,6 +1828,8 @@ function listLabels$1(kinds) {
1791
1828
  * Escape sequences (cursor, erase, mode, hyperlink, title, other OSC) in a pipe fail: no
1792
1829
  * real tool in the censuses printed one there except by mistake. A carriage-return redraw
1793
1830
  * alone only warns, because some tools draw a progress meter on stderr by design (curl).
1831
+ * The sequences added in 1.5 (other ESC sequences, a full reset, control strings, OSC
1832
+ * without ";", 8-bit controls) only warn until a census calibrates them (#42).
1794
1833
  */
1795
1834
  function judgePipeEscapes(r) {
1796
1835
  if (r.spawnError) return {
@@ -1805,14 +1844,26 @@ function judgePipeEscapes(r) {
1805
1844
  stream: "stderr",
1806
1845
  hit
1807
1846
  }))];
1808
- const escape = hits.find((h) => h.hit.kind !== "redraw");
1809
- const first = escape ?? hits[0];
1847
+ const escape = hits.find((h) => h.hit.kind !== "redraw" && !h.hit.warnOnly);
1848
+ const newEscape = hits.find((h) => h.hit.warnOnly);
1849
+ const first = escape ?? newEscape ?? hits[0];
1810
1850
  if (first) {
1811
1851
  const kinds = [...new Set(hits.map((h) => h.hit.kind))];
1852
+ const evidence = `${first.stream} line ${first.hit.line}: ${first.hit.text}`;
1853
+ if (escape) return {
1854
+ verdict: "fail",
1855
+ reason: `printed terminal control codes into a pipe: ${listLabels$1(kinds)}`,
1856
+ evidence
1857
+ };
1858
+ if (newEscape) return {
1859
+ verdict: "warn",
1860
+ reason: `printed terminal control codes into a pipe: ${listLabels$1(kinds)}; a new finding, so only a warning for now`,
1861
+ evidence
1862
+ };
1812
1863
  return {
1813
- verdict: escape ? "fail" : "warn",
1814
- reason: escape ? `printed terminal control codes into a pipe: ${listLabels$1(kinds)}` : "redrew lines with carriage returns in a pipe, as a progress meter does",
1815
- evidence: `${first.stream} line ${first.hit.line}: ${first.hit.text}`
1864
+ verdict: "warn",
1865
+ reason: "redrew lines with carriage returns in a pipe, as a progress meter does",
1866
+ evidence
1816
1867
  };
1817
1868
  }
1818
1869
  if (!stdout && !r.stderr) return r.timedOut ? {
@@ -2750,7 +2801,9 @@ Checks:
2750
2801
  pipe-escapes Runs the command into a pipe. Fails if cursor movement, erase,
2751
2802
  mode switch, hyperlink or window title codes (spinners,
2752
2803
  progress bars, prompts) reach stdout or stderr; warns if only
2753
- carriage returns redraw a line, as a progress meter does.
2804
+ carriage returns redraw a line, as a progress meter does, or
2805
+ for other escape sequences (save cursor, full reset, control
2806
+ strings, 8-bit controls), which it does not fail on yet.
2754
2807
  stdin Runs the command with stdin as an open pipe nobody writes to,
2755
2808
  as agents and CI runners often leave it. Fails if --version or
2756
2809
  --help waits for input; for your own probes, warns if it
@@ -2760,7 +2813,9 @@ Checks:
2760
2813
  prints a stack trace; warns if it exits 0, or exits and leaves
2761
2814
  processes running that ignored the Ctrl-C. Skipped when the
2762
2815
  command finishes first, so probe a command that keeps running
2763
- (a watcher, a server, a long task), e.g. with --probe "serve".
2816
+ (a watcher, a server, a long task), e.g. with --probe "serve";
2817
+ with --bare, also when a silent command outlives the Ctrl-C,
2818
+ as a REPL reading a pipe does.
2764
2819
  sigterm Sends SIGTERM to the command alone after 1 s, as kill, docker
2765
2820
  stop and process managers do. Warns if it is still running 3 s
2766
2821
  later, prints a stack trace, or exits and leaves child
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.4.4",
3
+ "version": "1.5.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, 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": {
package/schema.json CHANGED
@@ -89,7 +89,20 @@
89
89
  "description": "fail sets exit code 1; error means the probe could not run; info comes only from info checks."
90
90
  },
91
91
  "controlKind": {
92
- "enum": ["cursor", "erase", "mode", "hyperlink", "title", "osc", "redraw"]
92
+ "description": "A kind of terminal control code. escape, reset, string and c1 were added in 1.5 and only warn for now.",
93
+ "enum": [
94
+ "cursor",
95
+ "erase",
96
+ "mode",
97
+ "hyperlink",
98
+ "title",
99
+ "osc",
100
+ "redraw",
101
+ "escape",
102
+ "reset",
103
+ "string",
104
+ "c1"
105
+ ]
93
106
  },
94
107
  "result": {
95
108
  "type": "object",