cliprobe 0.2.0 → 0.3.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 +18 -8
- package/dist/cli.js +175 -34
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
84
84
|
|
|
85
85
|
## Checks
|
|
86
86
|
|
|
87
|
-
A default run does the
|
|
87
|
+
A default run does the five checks below: closed-pipe, color, pipe-escapes, ctrl-c and control-chars. Each one reports evidence, never a score. Two info checks, startup and baseline, run only when you name them with `--check`.
|
|
88
88
|
|
|
89
89
|
**closed-pipe**. cliprobe runs the command twice: once normally, then with stdout set to a pipe whose reading end is already closed, so the first write fails every time, even for fast native programs. Results:
|
|
90
90
|
|
|
@@ -97,15 +97,25 @@ A default run does the four checks below: closed-pipe, color, ctrl-c and control
|
|
|
97
97
|
|
|
98
98
|
**color**. 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:
|
|
99
99
|
|
|
100
|
-
| Verdict | Meaning
|
|
101
|
-
| ------- |
|
|
102
|
-
| `PASS` | No color in a pipe; in a terminal, either no color at all or color that `NO_COLOR` turns off
|
|
103
|
-
| `FAIL` | Printed color or style codes (bold counts, a bare reset doesn't) to stdout in a pipe
|
|
104
|
-
| `WARN` | Printed color to stderr in a pipe, or kept printing color under `NO_COLOR`
|
|
105
|
-
| `SKIP` | Printed nothing, waited for input in a terminal, or no
|
|
100
|
+
| Verdict | Meaning |
|
|
101
|
+
| ------- | -------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `PASS` | No color in a pipe; in a terminal, either no color at all or color that `NO_COLOR` turns off |
|
|
103
|
+
| `FAIL` | Printed color or style codes (bold counts, a bare reset doesn't) to stdout in a pipe |
|
|
104
|
+
| `WARN` | Printed color to stderr in a pipe, or kept printing color under `NO_COLOR` |
|
|
105
|
+
| `SKIP` | Printed nothing, waited for input in a terminal, or no `script` command (on Alpine, install `util-linux-misc`) |
|
|
106
106
|
|
|
107
107
|
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`.
|
|
108
108
|
|
|
109
|
+
**pipe-escapes**. 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:
|
|
110
|
+
|
|
111
|
+
| Verdict | Meaning |
|
|
112
|
+
| ------- | -------------------------------------------------------------------------- |
|
|
113
|
+
| `PASS` | None of those codes reached the pipe (color is the color check's business) |
|
|
114
|
+
| `WARN` | One or more reached stdout or stderr; the reason lists which kinds |
|
|
115
|
+
| `SKIP` | Printed nothing |
|
|
116
|
+
|
|
117
|
+
It only warns for now, never fails. In the census of the top 100 npm CLIs, no `--help` or `--version` printed any of these codes, which says nothing about their spinners: probe a command that does real work, such as an install or a build.
|
|
118
|
+
|
|
109
119
|
**ctrl-c**. 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. Results:
|
|
110
120
|
|
|
111
121
|
| Verdict | Meaning |
|
|
@@ -177,7 +187,7 @@ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+
|
|
|
177
187
|
|
|
178
188
|
## Safety
|
|
179
189
|
|
|
180
|
-
cliprobe runs the target in your current directory without a shell, with stdin closed, 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, or `--version` and `--help`; only the baseline check, when you name it, adds an unknown flag. It kills each run's whole process group on timeout, including under a pseudo-terminal. macOS and Linux
|
|
190
|
+
cliprobe runs the target in your current directory without a shell, with stdin closed, 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, or `--version` and `--help`; only the baseline check, when you name it, adds an unknown flag. It kills each run's whole process group on timeout, including under a pseudo-terminal. 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.
|
|
181
191
|
|
|
182
192
|
## License
|
|
183
193
|
|
package/dist/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ const STDOUT_CAP = 1048576;
|
|
|
29
29
|
* whose read end is closed before the program starts, so its first write to
|
|
30
30
|
* stdout fails (EPIPE, or SIGPIPE for programs that keep the default handler).
|
|
31
31
|
*/
|
|
32
|
-
function run(command, args, { closedStdout = false, timeout, env: overrides = {}, beforeKill, signal }) {
|
|
32
|
+
function run$1(command, args, { closedStdout = false, timeout, env: overrides = {}, beforeKill, signal }) {
|
|
33
33
|
const { dir, env: base } = sandbox();
|
|
34
34
|
const env = { ...base };
|
|
35
35
|
for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
|
|
@@ -188,7 +188,7 @@ function describeUnknownFlag(r) {
|
|
|
188
188
|
return { reason: `${exitText(r)} without saying why` };
|
|
189
189
|
}
|
|
190
190
|
async function probe(command, args, timeout, describe) {
|
|
191
|
-
const r = await run(command, args, { timeout });
|
|
191
|
+
const r = await run$1(command, args, { timeout });
|
|
192
192
|
const base = {
|
|
193
193
|
check: "baseline",
|
|
194
194
|
invocation: [command, ...args]
|
|
@@ -297,11 +297,11 @@ function judge(base, closed) {
|
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
299
|
async function closedPipe(command, args, timeout) {
|
|
300
|
-
const base = await run(command, args, {
|
|
300
|
+
const base = await run$1(command, args, {
|
|
301
301
|
closedStdout: false,
|
|
302
302
|
timeout
|
|
303
303
|
});
|
|
304
|
-
const closed = await run(command, args, {
|
|
304
|
+
const closed = await run$1(command, args, {
|
|
305
305
|
closedStdout: true,
|
|
306
306
|
timeout
|
|
307
307
|
});
|
|
@@ -370,6 +370,69 @@ function findStyle(text) {
|
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
|
+
/** CSI: ESC [ parameter bytes, intermediate bytes, one final byte. */
|
|
374
|
+
const CSI = /\x1b\[([0-?]*)[ -/]*([@-~])/g;
|
|
375
|
+
/** OSC: ESC ] number ; text, ended by BEL or ESC \. */
|
|
376
|
+
const OSC = /\x1b\](\d*);[^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
|
377
|
+
/** A carriage return that does not end a CRLF line: a line being redrawn. */
|
|
378
|
+
const BARE_CR = /\r(?!\n)/g;
|
|
379
|
+
/** How each kind reads in a report. */
|
|
380
|
+
const CONTROL_LABELS = {
|
|
381
|
+
cursor: "cursor movement",
|
|
382
|
+
erase: "line or screen erase",
|
|
383
|
+
mode: "terminal mode switch (such as hiding the cursor)",
|
|
384
|
+
hyperlink: "hyperlink (OSC 8)",
|
|
385
|
+
title: "window title",
|
|
386
|
+
osc: "operating system command (OSC)",
|
|
387
|
+
redraw: "carriage-return redraw"
|
|
388
|
+
};
|
|
389
|
+
function csiKind(params, final) {
|
|
390
|
+
if (final === "m") return void 0;
|
|
391
|
+
if (final === "K" || final === "J") return "erase";
|
|
392
|
+
if ((final === "h" || final === "l") && params.startsWith("?")) return "mode";
|
|
393
|
+
return "cursor";
|
|
394
|
+
}
|
|
395
|
+
function oscKind(code) {
|
|
396
|
+
if (code === "8") return "hyperlink";
|
|
397
|
+
if (code === "0" || code === "1" || code === "2") return "title";
|
|
398
|
+
return "osc";
|
|
399
|
+
}
|
|
400
|
+
function hitAt(text, index, sequence, kind) {
|
|
401
|
+
const before = text.slice(0, index);
|
|
402
|
+
const start = before.lastIndexOf("\n") + 1;
|
|
403
|
+
const newline = text.indexOf("\n", index);
|
|
404
|
+
const end = newline === -1 ? text.length : newline;
|
|
405
|
+
return {
|
|
406
|
+
kind,
|
|
407
|
+
sequence,
|
|
408
|
+
line: before.split("\n").length,
|
|
409
|
+
text: text.slice(start, end).slice(0, 120)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Every terminal control code in the text other than color and style (SGR):
|
|
414
|
+
* cursor movement, erases, mode switches, OSC sequences such as hyperlinks and
|
|
415
|
+
* window titles, and carriage returns that redraw a line. In reading order.
|
|
416
|
+
*/
|
|
417
|
+
function findControls(text) {
|
|
418
|
+
const hits = [];
|
|
419
|
+
for (const m of text.matchAll(CSI)) {
|
|
420
|
+
const kind = csiKind(m[1] ?? "", m[2] ?? "");
|
|
421
|
+
if (kind) hits.push({
|
|
422
|
+
index: m.index,
|
|
423
|
+
hit: hitAt(text, m.index, m[0], kind)
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
for (const m of text.matchAll(OSC)) hits.push({
|
|
427
|
+
index: m.index,
|
|
428
|
+
hit: hitAt(text, m.index, m[0], oscKind(m[1] ?? ""))
|
|
429
|
+
});
|
|
430
|
+
for (const m of text.matchAll(BARE_CR)) hits.push({
|
|
431
|
+
index: m.index,
|
|
432
|
+
hit: hitAt(text, m.index, m[0], "redraw")
|
|
433
|
+
});
|
|
434
|
+
return hits.sort((a, b) => a.index - b.index).map((h) => h.hit);
|
|
435
|
+
}
|
|
373
436
|
let cached;
|
|
374
437
|
/** Whether this machine can run a program under a PTY, detected once. */
|
|
375
438
|
function ptySupport() {
|
|
@@ -413,7 +476,7 @@ function detect() {
|
|
|
413
476
|
} catch (error) {
|
|
414
477
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return {
|
|
415
478
|
ok: false,
|
|
416
|
-
reason: "script(1) not found; install util-linux (
|
|
479
|
+
reason: "script(1) not found; install util-linux (Debian and Ubuntu: bsdutils; Alpine: util-linux-misc)"
|
|
417
480
|
};
|
|
418
481
|
}
|
|
419
482
|
return {
|
|
@@ -480,7 +543,7 @@ async function runPty(command, args, { timeout, env = {} }) {
|
|
|
480
543
|
const dir = mkdtempSync(join(tmpdir(), "cliprobe-pty-"));
|
|
481
544
|
const pidFile = join(dir, "pid");
|
|
482
545
|
try {
|
|
483
|
-
const result = await run("script", ptyArgs(support.flavor, pidFile, command, args), {
|
|
546
|
+
const result = await run$1("script", ptyArgs(support.flavor, pidFile, command, args), {
|
|
484
547
|
timeout,
|
|
485
548
|
env: {
|
|
486
549
|
TERM: "xterm-256color",
|
|
@@ -582,7 +645,7 @@ function judgeColor(runs) {
|
|
|
582
645
|
}
|
|
583
646
|
/** Runs only as many probes as the verdict needs: a pipe, then a terminal, then NO_COLOR. */
|
|
584
647
|
async function colorRuns(command, args, timeout) {
|
|
585
|
-
const pipe = await run(command, args, {
|
|
648
|
+
const pipe = await run$1(command, args, {
|
|
586
649
|
timeout,
|
|
587
650
|
env: COLOR_ENV
|
|
588
651
|
});
|
|
@@ -730,7 +793,7 @@ function collapseFixture(text, fixture) {
|
|
|
730
793
|
return text.replaceAll(fixture.realDir, FIXTURE_PLACEHOLDER).replaceAll(fixture.dir, FIXTURE_PLACEHOLDER);
|
|
731
794
|
}
|
|
732
795
|
// src/checks/control-chars.ts
|
|
733
|
-
const ENV = {
|
|
796
|
+
const ENV$1 = {
|
|
734
797
|
TERM: "xterm-256color",
|
|
735
798
|
CI: void 0
|
|
736
799
|
};
|
|
@@ -738,7 +801,7 @@ const ENV = {
|
|
|
738
801
|
function rawNames(output) {
|
|
739
802
|
return HOSTILE_NAMES.filter((h) => output.includes(h.marker));
|
|
740
803
|
}
|
|
741
|
-
const listLabels = (names) => {
|
|
804
|
+
const listLabels$1 = (names) => {
|
|
742
805
|
const labels = names.map((h) => h.label);
|
|
743
806
|
return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
|
|
744
807
|
};
|
|
@@ -779,21 +842,21 @@ function judgeControlChars(runs) {
|
|
|
779
842
|
const warning = raw.filter((h) => h.severity === "warn");
|
|
780
843
|
if (warning.length) return {
|
|
781
844
|
verdict: "warn",
|
|
782
|
-
reason: `printed ${listLabels(warning)} from file names unescaped, which can hide or forge output`,
|
|
845
|
+
reason: `printed ${listLabels$1(warning)} from file names unescaped, which can hide or forge output`,
|
|
783
846
|
evidence: evidenceFor(warning)
|
|
784
847
|
};
|
|
785
848
|
const noted = raw.filter((h) => h.severity === "note");
|
|
786
849
|
return {
|
|
787
850
|
verdict: "pass",
|
|
788
|
-
reason: `escaped control characters in file names${noted.length ? `; printed ${listLabels(noted)} as is` : ""}`
|
|
851
|
+
reason: `escaped control characters in file names${noted.length ? `; printed ${listLabels$1(noted)} as is` : ""}`
|
|
789
852
|
};
|
|
790
853
|
}
|
|
791
854
|
async function controlCharsRuns(command, args, fixtureDir, timeout) {
|
|
792
855
|
const usesFixture = fixtureDir !== void 0 && args.some((a) => a.includes(fixtureDir));
|
|
793
856
|
if (!usesFixture) return { usesFixture };
|
|
794
|
-
const pipe = await run(command, args, {
|
|
857
|
+
const pipe = await run$1(command, args, {
|
|
795
858
|
timeout,
|
|
796
|
-
env: ENV
|
|
859
|
+
env: ENV$1
|
|
797
860
|
});
|
|
798
861
|
if (pipe.spawnError || pipe.timedOut) return {
|
|
799
862
|
usesFixture,
|
|
@@ -810,7 +873,7 @@ async function controlCharsRuns(command, args, fixtureDir, timeout) {
|
|
|
810
873
|
pipe,
|
|
811
874
|
tty: await runPty(command, args, {
|
|
812
875
|
timeout,
|
|
813
|
-
env: ENV
|
|
876
|
+
env: ENV$1
|
|
814
877
|
})
|
|
815
878
|
};
|
|
816
879
|
}
|
|
@@ -888,7 +951,7 @@ function judgeCtrlC(r) {
|
|
|
888
951
|
};
|
|
889
952
|
}
|
|
890
953
|
async function ctrlC(command, args) {
|
|
891
|
-
const r = await run(command, args, {
|
|
954
|
+
const r = await run$1(command, args, {
|
|
892
955
|
timeout: 4e3,
|
|
893
956
|
signal: {
|
|
894
957
|
name: "SIGINT",
|
|
@@ -928,6 +991,73 @@ const ctrlCCheck = {
|
|
|
928
991
|
return results;
|
|
929
992
|
}
|
|
930
993
|
};
|
|
994
|
+
// src/checks/pipe-escapes.ts
|
|
995
|
+
/** As in the color check: a capable TERM, so a program can't pass by seeing TERM=dumb, and no CI. */
|
|
996
|
+
const ENV = {
|
|
997
|
+
TERM: "xterm-256color",
|
|
998
|
+
CI: void 0
|
|
999
|
+
};
|
|
1000
|
+
const kindsOf = (hits) => [...new Set(hits.map((h) => h.kind))];
|
|
1001
|
+
function listLabels(kinds) {
|
|
1002
|
+
const labels = kinds.map((k) => CONTROL_LABELS[k]);
|
|
1003
|
+
return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
|
|
1004
|
+
}
|
|
1005
|
+
function judgePipeEscapes(r) {
|
|
1006
|
+
if (r.spawnError) return {
|
|
1007
|
+
verdict: "error",
|
|
1008
|
+
reason: `could not start: ${r.spawnError}`
|
|
1009
|
+
};
|
|
1010
|
+
if (r.timedOut) return {
|
|
1011
|
+
verdict: "error",
|
|
1012
|
+
reason: "timed out on a normal run"
|
|
1013
|
+
};
|
|
1014
|
+
const stdout = r.stdout.toString("utf8");
|
|
1015
|
+
const outHits = findControls(stdout);
|
|
1016
|
+
const errHits = findControls(r.stderr);
|
|
1017
|
+
const first = outHits[0] ? {
|
|
1018
|
+
stream: "stdout",
|
|
1019
|
+
hit: outHits[0]
|
|
1020
|
+
} : errHits[0] && {
|
|
1021
|
+
stream: "stderr",
|
|
1022
|
+
hit: errHits[0]
|
|
1023
|
+
};
|
|
1024
|
+
if (first) return {
|
|
1025
|
+
verdict: "warn",
|
|
1026
|
+
reason: `printed terminal control codes into a pipe: ${listLabels([.../* @__PURE__ */ new Set([...kindsOf(outHits), ...kindsOf(errHits)])])}`,
|
|
1027
|
+
evidence: `${first.stream} line ${first.hit.line}: ${first.hit.text}`
|
|
1028
|
+
};
|
|
1029
|
+
if (!stdout && !r.stderr) return {
|
|
1030
|
+
verdict: "skip",
|
|
1031
|
+
reason: "printed nothing, so there is nothing to check"
|
|
1032
|
+
};
|
|
1033
|
+
return {
|
|
1034
|
+
verdict: "pass",
|
|
1035
|
+
reason: "no cursor, erase, hyperlink, title or redraw codes in a pipe"
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
async function pipeEscapes(command, args, timeout) {
|
|
1039
|
+
const r = await run$1(command, args, {
|
|
1040
|
+
timeout,
|
|
1041
|
+
env: ENV
|
|
1042
|
+
});
|
|
1043
|
+
return {
|
|
1044
|
+
check: "pipe-escapes",
|
|
1045
|
+
invocation: [command, ...args],
|
|
1046
|
+
...judgePipeEscapes(r),
|
|
1047
|
+
stdoutKinds: kindsOf(findControls(r.stdout.toString("utf8"))),
|
|
1048
|
+
stderrKinds: kindsOf(findControls(r.stderr))
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
const pipeEscapesCheck = {
|
|
1052
|
+
name: "pipe-escapes",
|
|
1053
|
+
kind: "check",
|
|
1054
|
+
summary: "prints spinners, cursor codes, hyperlinks or titles into a pipe",
|
|
1055
|
+
async run(target, ctx) {
|
|
1056
|
+
const results = [];
|
|
1057
|
+
for (const args of target.invocations) results.push(await pipeEscapes(target.command, args, ctx.timeout));
|
|
1058
|
+
return results;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
931
1061
|
function median(values) {
|
|
932
1062
|
const sorted = [...values].sort((a, b) => a - b);
|
|
933
1063
|
const mid = Math.floor(sorted.length / 2);
|
|
@@ -943,7 +1073,7 @@ async function startup(command, args, timeout) {
|
|
|
943
1073
|
check: "startup",
|
|
944
1074
|
invocation: [command, ...args]
|
|
945
1075
|
};
|
|
946
|
-
const warmUp = await run(command, args, { timeout });
|
|
1076
|
+
const warmUp = await run$1(command, args, { timeout });
|
|
947
1077
|
if (warmUp.spawnError) return {
|
|
948
1078
|
...base,
|
|
949
1079
|
verdict: "error",
|
|
@@ -967,7 +1097,7 @@ async function startup(command, args, timeout) {
|
|
|
967
1097
|
};
|
|
968
1098
|
const runsMs = [];
|
|
969
1099
|
for (let i = 0; i < 5; i++) {
|
|
970
|
-
const r = await run(command, args, { timeout });
|
|
1100
|
+
const r = await run$1(command, args, { timeout });
|
|
971
1101
|
if (r.timedOut || r.spawnError) return {
|
|
972
1102
|
...base,
|
|
973
1103
|
verdict: "error",
|
|
@@ -991,6 +1121,7 @@ async function startup(command, args, timeout) {
|
|
|
991
1121
|
const CHECKS = [
|
|
992
1122
|
closedPipeCheck,
|
|
993
1123
|
colorCheck,
|
|
1124
|
+
pipeEscapesCheck,
|
|
994
1125
|
ctrlCCheck,
|
|
995
1126
|
controlCharsCheck,
|
|
996
1127
|
{
|
|
@@ -1286,7 +1417,7 @@ function parseArgs(argv) {
|
|
|
1286
1417
|
}
|
|
1287
1418
|
return opts;
|
|
1288
1419
|
}
|
|
1289
|
-
// src/cli/
|
|
1420
|
+
// src/cli/help.ts
|
|
1290
1421
|
const HELP = `cliprobe ${VERSION}: test a command-line program for terminal-edge bugs
|
|
1291
1422
|
|
|
1292
1423
|
Usage:
|
|
@@ -1305,6 +1436,9 @@ Checks:
|
|
|
1305
1436
|
color Runs the command into a pipe, then under a terminal, then under
|
|
1306
1437
|
a terminal with NO_COLOR=1. Fails if color codes reach a pipe;
|
|
1307
1438
|
warns if color goes to a piped stderr or NO_COLOR is ignored.
|
|
1439
|
+
pipe-escapes Runs the command into a pipe and warns if cursor movement,
|
|
1440
|
+
erase, hyperlink, window title or carriage-return redraw
|
|
1441
|
+
codes (spinners, progress bars) reach stdout or stderr.
|
|
1308
1442
|
ctrl-c Sends Ctrl-C (SIGINT) after 1 s. Fails if the command is still
|
|
1309
1443
|
running 3 s later or prints a stack trace; warns if it exits 0.
|
|
1310
1444
|
Skipped when the command finishes first, so probe a command
|
|
@@ -1338,16 +1472,20 @@ Options:
|
|
|
1338
1472
|
Exit codes: 0 no failures, 1 a check failed, 2 usage error or could not run.
|
|
1339
1473
|
Runs the target in the current directory without a shell, with stdin closed,
|
|
1340
1474
|
a temporary HOME and a minimal environment. Only run programs you trust.`;
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1475
|
+
// src/cli/program.ts
|
|
1476
|
+
/** 0 no failures, 1 a check failed, 2 nothing could be judged because something could not run. */
|
|
1477
|
+
function exitCodeFor(results) {
|
|
1478
|
+
if (results.some((r) => r.verdict === "fail")) return 1;
|
|
1479
|
+
if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
|
|
1480
|
+
return 0;
|
|
1481
|
+
}
|
|
1482
|
+
/** The whole CLI: parses argv, runs the checks, reports, and returns the exit code. */
|
|
1483
|
+
async function run(argv, io) {
|
|
1484
|
+
const out = io.stdout;
|
|
1485
|
+
const err = io.stderr;
|
|
1348
1486
|
let opts;
|
|
1349
1487
|
try {
|
|
1350
|
-
opts = parseArgs(
|
|
1488
|
+
opts = parseArgs(argv);
|
|
1351
1489
|
} catch (error) {
|
|
1352
1490
|
if (!(error instanceof UsageError)) throw error;
|
|
1353
1491
|
err(`cliprobe: ${error.message}\nRun "cliprobe --help" for usage.\n`);
|
|
@@ -1364,15 +1502,14 @@ async function main() {
|
|
|
1364
1502
|
const { checks, unknown } = selectChecks(opts.checks);
|
|
1365
1503
|
if (unknown.length) {
|
|
1366
1504
|
const available = CHECKS.map((c) => c.name).join(", ");
|
|
1367
|
-
|
|
1368
|
-
err(`cliprobe: unknown check ${quoted} (available: ${available})\n`);
|
|
1505
|
+
err(`cliprobe: unknown check ${unknown.map((n) => `"${n}"`).join(", ")} (available: ${available})\n`);
|
|
1369
1506
|
return 2;
|
|
1370
1507
|
}
|
|
1371
1508
|
if (!opts.command) {
|
|
1372
1509
|
err("cliprobe: no command given\nUsage: cliprobe [options] -- <command> [args...]\n");
|
|
1373
1510
|
return 2;
|
|
1374
1511
|
}
|
|
1375
|
-
if (
|
|
1512
|
+
if (io.platform === "win32") {
|
|
1376
1513
|
err("cliprobe: Windows is not supported yet (the closed-pipe check needs mkfifo).\n");
|
|
1377
1514
|
return 2;
|
|
1378
1515
|
}
|
|
@@ -1397,7 +1534,7 @@ async function main() {
|
|
|
1397
1534
|
checks: checks.map((c) => c.name),
|
|
1398
1535
|
results
|
|
1399
1536
|
};
|
|
1400
|
-
const color =
|
|
1537
|
+
const { color } = io;
|
|
1401
1538
|
if (opts.outputFile) {
|
|
1402
1539
|
try {
|
|
1403
1540
|
writeReportFile(opts.outputFile, collapse(FORMATS[opts.format](report, { color: false })));
|
|
@@ -1408,13 +1545,17 @@ async function main() {
|
|
|
1408
1545
|
}
|
|
1409
1546
|
out(collapse(FORMATS.human(report, { color })));
|
|
1410
1547
|
} else out(collapse(FORMATS[opts.format](report, { color })));
|
|
1411
|
-
|
|
1412
|
-
if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
|
|
1413
|
-
return 0;
|
|
1548
|
+
return exitCodeFor(results);
|
|
1414
1549
|
}
|
|
1550
|
+
// src/cli/main.ts
|
|
1415
1551
|
process.stdout.on("error", (error) => {
|
|
1416
1552
|
if (error.code === "EPIPE") process.exit(process.exitCode ?? 0);
|
|
1417
1553
|
throw error;
|
|
1418
1554
|
});
|
|
1419
|
-
process.exitCode = await
|
|
1555
|
+
process.exitCode = await run(process.argv.slice(2), {
|
|
1556
|
+
stdout: (text) => process.stdout.write(text),
|
|
1557
|
+
stderr: (text) => process.stderr.write(text),
|
|
1558
|
+
color: process.stdout.isTTY && !process.env["NO_COLOR"],
|
|
1559
|
+
platform: process.platform
|
|
1560
|
+
});
|
|
1420
1561
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), color codes leaking into pipes, broken Ctrl-C handling, and control characters from file names reaching your terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
"format": "prettier --write .",
|
|
19
19
|
"format:check": "prettier --check .",
|
|
20
20
|
"test": "vitest run",
|
|
21
|
-
"check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build && pnpm test && pnpm check:package",
|
|
21
|
+
"check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build && pnpm test:coverage && pnpm check:package",
|
|
22
22
|
"check:package": "publint --strict",
|
|
23
23
|
"prepublishOnly": "pnpm build",
|
|
24
24
|
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
25
26
|
"prepare": "husky"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
76
77
|
"@types/markdown-it": "^14.2.0",
|
|
77
78
|
"@types/node": "^22.20.5",
|
|
79
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
78
80
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
79
81
|
"fast-xml-parser": "^5.12.0",
|
|
80
82
|
"husky": "^9.1.7",
|