cliprobe 1.4.4 → 1.5.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 +8 -6
- package/dist/cli.js +73 -31
- package/package.json +1 -1
- package/schema.json +14 -1
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:
|
package/dist/cli.js
CHANGED
|
@@ -853,12 +853,29 @@ function findStyle(text) {
|
|
|
853
853
|
};
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
|
-
/**
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
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,
|
|
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(
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
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
|
-
|
|
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. */
|
|
@@ -1791,6 +1817,8 @@ function listLabels$1(kinds) {
|
|
|
1791
1817
|
* Escape sequences (cursor, erase, mode, hyperlink, title, other OSC) in a pipe fail: no
|
|
1792
1818
|
* real tool in the censuses printed one there except by mistake. A carriage-return redraw
|
|
1793
1819
|
* alone only warns, because some tools draw a progress meter on stderr by design (curl).
|
|
1820
|
+
* The sequences added in 1.5 (other ESC sequences, a full reset, control strings, OSC
|
|
1821
|
+
* without ";", 8-bit controls) only warn until a census calibrates them (#42).
|
|
1794
1822
|
*/
|
|
1795
1823
|
function judgePipeEscapes(r) {
|
|
1796
1824
|
if (r.spawnError) return {
|
|
@@ -1805,14 +1833,26 @@ function judgePipeEscapes(r) {
|
|
|
1805
1833
|
stream: "stderr",
|
|
1806
1834
|
hit
|
|
1807
1835
|
}))];
|
|
1808
|
-
const escape = hits.find((h) => h.hit.kind !== "redraw");
|
|
1809
|
-
const
|
|
1836
|
+
const escape = hits.find((h) => h.hit.kind !== "redraw" && !h.hit.warnOnly);
|
|
1837
|
+
const newEscape = hits.find((h) => h.hit.warnOnly);
|
|
1838
|
+
const first = escape ?? newEscape ?? hits[0];
|
|
1810
1839
|
if (first) {
|
|
1811
1840
|
const kinds = [...new Set(hits.map((h) => h.hit.kind))];
|
|
1841
|
+
const evidence = `${first.stream} line ${first.hit.line}: ${first.hit.text}`;
|
|
1842
|
+
if (escape) return {
|
|
1843
|
+
verdict: "fail",
|
|
1844
|
+
reason: `printed terminal control codes into a pipe: ${listLabels$1(kinds)}`,
|
|
1845
|
+
evidence
|
|
1846
|
+
};
|
|
1847
|
+
if (newEscape) return {
|
|
1848
|
+
verdict: "warn",
|
|
1849
|
+
reason: `printed terminal control codes into a pipe: ${listLabels$1(kinds)}; a new finding, so only a warning for now`,
|
|
1850
|
+
evidence
|
|
1851
|
+
};
|
|
1812
1852
|
return {
|
|
1813
|
-
verdict:
|
|
1814
|
-
reason:
|
|
1815
|
-
evidence
|
|
1853
|
+
verdict: "warn",
|
|
1854
|
+
reason: "redrew lines with carriage returns in a pipe, as a progress meter does",
|
|
1855
|
+
evidence
|
|
1816
1856
|
};
|
|
1817
1857
|
}
|
|
1818
1858
|
if (!stdout && !r.stderr) return r.timedOut ? {
|
|
@@ -2750,7 +2790,9 @@ Checks:
|
|
|
2750
2790
|
pipe-escapes Runs the command into a pipe. Fails if cursor movement, erase,
|
|
2751
2791
|
mode switch, hyperlink or window title codes (spinners,
|
|
2752
2792
|
progress bars, prompts) reach stdout or stderr; warns if only
|
|
2753
|
-
carriage returns redraw a line, as a progress meter does
|
|
2793
|
+
carriage returns redraw a line, as a progress meter does, or
|
|
2794
|
+
for other escape sequences (save cursor, full reset, control
|
|
2795
|
+
strings, 8-bit controls), which it does not fail on yet.
|
|
2754
2796
|
stdin Runs the command with stdin as an open pipe nobody writes to,
|
|
2755
2797
|
as agents and CI runners often leave it. Fails if --version or
|
|
2756
2798
|
--help waits for input; for your own probes, warns if it
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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
|
-
"
|
|
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",
|