cliprobe 1.5.1 → 1.6.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 +10 -8
- package/dist/cli.js +79 -20
- package/package.json +1 -1
- package/schema.json +17 -0
package/README.md
CHANGED
|
@@ -58,8 +58,8 @@ sigterm
|
|
|
58
58
|
SKIP tsx needs a probe that keeps running, such as a watch or serve command (--probe), or --bare
|
|
59
59
|
|
|
60
60
|
restore
|
|
61
|
-
PASS tsx --version left no terminal mode switched on when it exited
|
|
62
|
-
PASS tsx --help left no terminal mode switched on when it exited
|
|
61
|
+
PASS tsx --version left no terminal mode switched on and the terminal's settings as it found them when it exited
|
|
62
|
+
PASS tsx --help left no terminal mode switched on and the terminal's settings as it found them when it exited
|
|
63
63
|
|
|
64
64
|
control-chars
|
|
65
65
|
SKIP tsx no {fixture} in the arguments; add a probe that takes a path, e.g. --probe "ls {fixture}"
|
|
@@ -320,13 +320,13 @@ It only warns for now. Across 44 watch modes, dev servers and long tasks run off
|
|
|
320
320
|
|
|
321
321
|
### restore
|
|
322
322
|
|
|
323
|
-
Spinners, prompts and full-screen programs switch terminal modes on: they hide the cursor, open the alternate screen, turn on mouse reporting or bracketed paste, or turn line wrapping off. If they don't switch them back off on the way out, the shell they return to is broken until you run `reset`: no cursor, a blank screen, mouse clicks typed as junk, long lines cut off at the edge. cliprobe runs the command under a terminal and, for probes you write, types Ctrl-C after 1 second, as a person would. The keystroke goes through the terminal, so a program in raw mode gets it as a key rather than a signal, just as it would from a keyboard. `--version` and `--help` aren't interrupted; they're judged as they exit. Results:
|
|
323
|
+
Spinners, prompts and full-screen programs switch terminal modes on: they hide the cursor, open the alternate screen, turn on mouse reporting or bracketed paste, or turn line wrapping off. If they don't switch them back off on the way out, the shell they return to is broken until you run `reset`: no cursor, a blank screen, mouse clicks typed as junk, long lines cut off at the edge. Prompts and full-screen programs also put the terminal in raw mode (echo and line editing off, from `stty`), and one that exits without switching it back leaves a shell that shows nothing you type. cliprobe runs the command under a terminal and, for probes you write, types Ctrl-C after 1 second, as a person would. The keystroke goes through the terminal, so a program in raw mode gets it as a key rather than a signal, just as it would from a keyboard. `--version` and `--help` aren't interrupted; they're judged as they exit. Since 1.6, cliprobe also reads the terminal's settings with `stty -a` just before the program starts and just after it exits, and compares them: line editing (`icanon`), `echo`, `isig`, `iexten`, output processing (`opost`, `onlcr`), `icrnl` and `ixon`. Results:
|
|
324
324
|
|
|
325
|
-
| Verdict | Meaning
|
|
326
|
-
| ------- |
|
|
327
|
-
| `PASS` | Left no mode switched on, either because it never switched one or because it switched each back off (or reset the terminal) |
|
|
328
|
-
| `WARN` | Left one or more on; the evidence quotes each sequence that was never undone and its line
|
|
329
|
-
| `SKIP` | Still running 3 seconds after Ctrl-C (REPLs quit on a second one), more than 1 MiB of output, or no usable `script` command
|
|
325
|
+
| Verdict | Meaning |
|
|
326
|
+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
327
|
+
| `PASS` | Left no mode switched on, either because it never switched one or because it switched each back off (or reset the terminal), and left the terminal's settings as it found them |
|
|
328
|
+
| `WARN` | Left one or more on, or switched a setting off and left it off (raw mode); the evidence quotes each sequence that was never undone and its line, and the settings as `stty` flags such as `-icanon -echo` |
|
|
329
|
+
| `SKIP` | Still running 3 seconds after Ctrl-C (REPLs quit on a second one), more than 1 MiB of output, or no usable `script` command |
|
|
330
330
|
|
|
331
331
|
It only warns: a terminal left in the wrong mode is a nuisance you can undo, not a failure of the program's job. Across the top 100 npm CLIs, their watch modes and servers, and popular prompt and spinner libraries (about 300 runs), nothing warned falsely, and one tool really did break the terminal: `taze -I` turns line wrapping off for its progress bars and leaves it off after Ctrl-C.
|
|
332
332
|
|
|
@@ -420,6 +420,8 @@ process.on('exit', () => process.stdout.write('\x1b[?25h')); // and always show
|
|
|
420
420
|
process.once('SIGINT', () => process.exit(130));
|
|
421
421
|
```
|
|
422
422
|
|
|
423
|
+
Node switches raw mode (`setRawMode`) back off on its own as it exits, but not when it is killed. In other languages, restore the terminal's settings yourself: in Python, save `termios.tcgetattr(fd)` and put it back with `tcsetattr` in a `finally`, instead of calling `os._exit()` while the terminal is raw.
|
|
424
|
+
|
|
423
425
|
**control-chars:** escape names (and any other text you didn't write) before printing them for a person. `JSON.stringify` alone isn't enough: it leaves C1 controls and bidi overrides raw.
|
|
424
426
|
|
|
425
427
|
```js
|
package/dist/cli.js
CHANGED
|
@@ -1094,12 +1094,18 @@ function shellQuote(arg) {
|
|
|
1094
1094
|
* program as argv; only the util-linux form needs quoting, because its -c takes
|
|
1095
1095
|
* a single string.
|
|
1096
1096
|
*/
|
|
1097
|
-
function ptyArgs(flavor, pidFile, command, args, cols = 80, rows = 24) {
|
|
1098
|
-
const
|
|
1099
|
-
const
|
|
1097
|
+
function ptyArgs(flavor, pidFile, command, args, cols = 80, rows = 24, settingsFile) {
|
|
1098
|
+
const size = `stty cols ${cols} rows ${rows} 2>/dev/null`;
|
|
1099
|
+
const setup = settingsFile === void 0 ? `echo $$ > "$1"; shift; ${size}; exec "$@"` : `echo $$ > "$1"; s=$2; shift 2; ${size}; stty -a > "$s.before" 2>/dev/null; trap true INT; "$@"; c=$?; stty -a > "$s.after" 2>/dev/null; exit $c`;
|
|
1100
|
+
const argv = settingsFile === void 0 ? [
|
|
1100
1101
|
pidFile,
|
|
1101
1102
|
command,
|
|
1102
1103
|
...args
|
|
1104
|
+
] : [
|
|
1105
|
+
pidFile,
|
|
1106
|
+
settingsFile,
|
|
1107
|
+
command,
|
|
1108
|
+
...args
|
|
1103
1109
|
];
|
|
1104
1110
|
if (flavor === "bsd") return [
|
|
1105
1111
|
"-q",
|
|
@@ -1116,6 +1122,28 @@ function ptyArgs(flavor, pidFile, command, args, cols = 80, rows = 24) {
|
|
|
1116
1122
|
"/dev/null"
|
|
1117
1123
|
];
|
|
1118
1124
|
}
|
|
1125
|
+
/** The terminal settings that leave a shell unusable when a program exits with them off. */
|
|
1126
|
+
const WATCHED_SETTINGS = [
|
|
1127
|
+
"icanon",
|
|
1128
|
+
"echo",
|
|
1129
|
+
"isig",
|
|
1130
|
+
"iexten",
|
|
1131
|
+
"opost",
|
|
1132
|
+
"onlcr",
|
|
1133
|
+
"icrnl",
|
|
1134
|
+
"ixon"
|
|
1135
|
+
];
|
|
1136
|
+
/**
|
|
1137
|
+
* The watched settings that were on in `before` and are off in `after`, both the
|
|
1138
|
+
* output of `stty -a`, where BSD and GNU stty alike print a setting that is off as
|
|
1139
|
+
* `-name`. Compared with the terminal as the program found it, not fixed values.
|
|
1140
|
+
*/
|
|
1141
|
+
function settingsOff(before, after) {
|
|
1142
|
+
const words = (text) => new Set(text.split(/[\s;]+/));
|
|
1143
|
+
const was = words(before);
|
|
1144
|
+
const now = words(after);
|
|
1145
|
+
return WATCHED_SETTINGS.filter((name) => was.has(name) && now.has(`-${name}`));
|
|
1146
|
+
}
|
|
1119
1147
|
/** BSD script echoes the EOF it forwards from /dev/null as "^D" and two backspaces. */
|
|
1120
1148
|
const BSD_EOF_ECHO = "^D\b\b";
|
|
1121
1149
|
/** Undoes the terminal's output processing: the EOF echo, and \n turned into \r\n. */
|
|
@@ -1131,7 +1159,7 @@ function cleanPtyOutput(raw, flavor) {
|
|
|
1131
1159
|
* the terminal's line discipline handles what is typed, so Ctrl-C (\x03) becomes
|
|
1132
1160
|
* SIGINT for the program, or a keypress if the program turned that off.
|
|
1133
1161
|
*/
|
|
1134
|
-
async function runPty(command, args, { timeout, env = {}, input }) {
|
|
1162
|
+
async function runPty(command, args, { timeout, env = {}, input, settings = false }) {
|
|
1135
1163
|
const support = ptySupport();
|
|
1136
1164
|
if (!support.ok) throw new Error(`no PTY: ${support.reason}`);
|
|
1137
1165
|
const dir = mkdtempSync(join(tmpdir(), "cliprobe-pty-"));
|
|
@@ -1141,7 +1169,8 @@ async function runPty(command, args, { timeout, env = {}, input }) {
|
|
|
1141
1169
|
}));
|
|
1142
1170
|
const pidFile = join(dir, "pid");
|
|
1143
1171
|
let launcher = "script";
|
|
1144
|
-
|
|
1172
|
+
const settingsFile = settings ? join(dir, "stty") : void 0;
|
|
1173
|
+
let argv = ptyArgs(support.flavor, pidFile, command, args, 80, 24, settingsFile);
|
|
1145
1174
|
let keyboard;
|
|
1146
1175
|
let inputSentMs;
|
|
1147
1176
|
let typeTimer;
|
|
@@ -1191,7 +1220,8 @@ async function runPty(command, args, { timeout, env = {}, input }) {
|
|
|
1191
1220
|
...result.spawnError === void 0 ? {} : { spawnError: result.spawnError },
|
|
1192
1221
|
scriptStderr: result.stderr,
|
|
1193
1222
|
truncated: result.stdoutBytes > result.stdout.length,
|
|
1194
|
-
...inputSentMs === void 0 ? {} : { inputSentMs }
|
|
1223
|
+
...inputSentMs === void 0 ? {} : { inputSentMs },
|
|
1224
|
+
...readSettings(settingsFile, result.timedOut)
|
|
1195
1225
|
};
|
|
1196
1226
|
} finally {
|
|
1197
1227
|
clearTimeout(typeTimer);
|
|
@@ -1204,6 +1234,15 @@ async function runPty(command, args, { timeout, env = {}, input }) {
|
|
|
1204
1234
|
});
|
|
1205
1235
|
}
|
|
1206
1236
|
}
|
|
1237
|
+
/** The settings the program left off, when the wrapper could read them after it. */
|
|
1238
|
+
function readSettings(file, timedOut) {
|
|
1239
|
+
if (file === void 0 || timedOut) return {};
|
|
1240
|
+
try {
|
|
1241
|
+
return { settingsOff: settingsOff(readFileSync(`${file}.before`, "utf8"), readFileSync(`${file}.after`, "utf8")) };
|
|
1242
|
+
} catch {
|
|
1243
|
+
return {};
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1207
1246
|
/** How often to look for the end of a program that is being typed to. */
|
|
1208
1247
|
const EXIT_POLL_MS = 50;
|
|
1209
1248
|
function programGroup(pidFile) {
|
|
@@ -1216,7 +1255,8 @@ function programGroup(pidFile) {
|
|
|
1216
1255
|
}
|
|
1217
1256
|
/**
|
|
1218
1257
|
* Whether the program under the PTY has started, is running, or has exited.
|
|
1219
|
-
* Asks about the program itself
|
|
1258
|
+
* Asks about the program itself (or the wrapper that runs it and reads the
|
|
1259
|
+
* settings it left, which ends right after it), which script(1) reaps, not its group: a child
|
|
1220
1260
|
* it left behind can stay a zombie for good where nothing reaps orphans, as in
|
|
1221
1261
|
* a container without an init process.
|
|
1222
1262
|
*/
|
|
@@ -1913,7 +1953,9 @@ const pipeEscapesCheck = {
|
|
|
1913
1953
|
};
|
|
1914
1954
|
// src/checks/restore.ts
|
|
1915
1955
|
function listLabels(modes) {
|
|
1916
|
-
|
|
1956
|
+
return listWords(modes.map((m) => m.label));
|
|
1957
|
+
}
|
|
1958
|
+
function listWords(labels) {
|
|
1917
1959
|
return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
|
|
1918
1960
|
}
|
|
1919
1961
|
/** The PTY wrapper's own complaint when it can't exec the program. */
|
|
@@ -1936,14 +1978,26 @@ function judgeRestore(r) {
|
|
|
1936
1978
|
};
|
|
1937
1979
|
const when = interrupted ? "after Ctrl-C" : "when it exited";
|
|
1938
1980
|
const open = findOpenModes(r.output);
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
evidence
|
|
1943
|
-
|
|
1981
|
+
const off = r.settingsOff ?? [];
|
|
1982
|
+
if (open.length > 0 || off.length > 0) {
|
|
1983
|
+
const parts = open.length > 0 ? [`with ${listLabels(open)}`] : [];
|
|
1984
|
+
const evidence = open.map((m) => `${m.sequence} on line ${m.line}, never undone`);
|
|
1985
|
+
if (off.length > 0) {
|
|
1986
|
+
const raw = off.includes("icanon") && off.includes("echo");
|
|
1987
|
+
const flags = off.map((name) => `-${name}`);
|
|
1988
|
+
parts.push(raw ? `in raw mode (${listWords(off)} off)` : `with ${listWords(off)} off (${flags.join(" ")})`);
|
|
1989
|
+
evidence.push(`stty settings never restored: ${flags.join(" ")}`);
|
|
1990
|
+
}
|
|
1991
|
+
const fix = off.length > 0 ? "; `stty sane` undoes it" : "";
|
|
1992
|
+
return {
|
|
1993
|
+
verdict: "warn",
|
|
1994
|
+
reason: `left the terminal ${parts.join(" and ")} ${when}${fix}`,
|
|
1995
|
+
evidence: evidence.join("; ")
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1944
1998
|
return {
|
|
1945
1999
|
verdict: "pass",
|
|
1946
|
-
reason: `left no terminal mode switched on ${when}`
|
|
2000
|
+
reason: `left no terminal mode switched on${r.settingsOff === void 0 ? "" : " and the terminal's settings as it found them"} ${when}`
|
|
1947
2001
|
};
|
|
1948
2002
|
}
|
|
1949
2003
|
async function restore(command, args, { timeout, interrupt }) {
|
|
@@ -1952,9 +2006,11 @@ async function restore(command, args, { timeout, interrupt }) {
|
|
|
1952
2006
|
...interrupt ? { input: {
|
|
1953
2007
|
data: CTRL_C_KEY,
|
|
1954
2008
|
afterMs: CTRL_C_DELAY_MS
|
|
1955
|
-
} } : {}
|
|
2009
|
+
} } : {},
|
|
2010
|
+
settings: true
|
|
1956
2011
|
});
|
|
1957
|
-
const
|
|
2012
|
+
const notRun = r.spawnError === void 0 && (r.exitCode === 126 || r.exitCode === 127 || WRAPPER_EXEC_FAILED.test(r.output)) && cannotExecute(command);
|
|
2013
|
+
const judgement = judgeRestore(notRun ? {
|
|
1958
2014
|
...r,
|
|
1959
2015
|
spawnError: notAProgram(command, "the terminal's shell could not exec it")
|
|
1960
2016
|
} : r);
|
|
@@ -1963,7 +2019,8 @@ async function restore(command, args, { timeout, interrupt }) {
|
|
|
1963
2019
|
invocation: [command, ...args],
|
|
1964
2020
|
...judgement,
|
|
1965
2021
|
interrupted: r.inputSentMs !== void 0,
|
|
1966
|
-
openModes: judgement.verdict === "warn" ? findOpenModes(r.output) : []
|
|
2022
|
+
openModes: judgement.verdict === "warn" ? findOpenModes(r.output) : [],
|
|
2023
|
+
settingsOff: notRun ? null : r.settingsOff ?? null
|
|
1967
2024
|
};
|
|
1968
2025
|
}
|
|
1969
2026
|
const restoreCheck = {
|
|
@@ -1987,7 +2044,8 @@ const restoreCheck = {
|
|
|
1987
2044
|
invocation: [target.command, ...args],
|
|
1988
2045
|
...notRun,
|
|
1989
2046
|
interrupted: false,
|
|
1990
|
-
openModes: []
|
|
2047
|
+
openModes: [],
|
|
2048
|
+
settingsOff: null
|
|
1991
2049
|
};
|
|
1992
2050
|
results.push(result);
|
|
1993
2051
|
continue;
|
|
@@ -2824,8 +2882,9 @@ Checks:
|
|
|
2824
2882
|
restore Runs the command under a terminal and, for your own probes,
|
|
2825
2883
|
types Ctrl-C after 1 s, as a person would. Warns if it leaves
|
|
2826
2884
|
the cursor hidden, the alternate screen, mouse or focus
|
|
2827
|
-
reporting, bracketed paste or line wrapping off,
|
|
2828
|
-
|
|
2885
|
+
reporting, bracketed paste or line wrapping off, or the
|
|
2886
|
+
terminal in raw mode (echo and line editing off, from stty),
|
|
2887
|
+
which breaks the shell it returns to.
|
|
2829
2888
|
control-chars Runs the command under a terminal with {fixture} replaced by a
|
|
2830
2889
|
directory of file names holding escape sequences, a carriage
|
|
2831
2890
|
return, a newline and more. Fails if an escape sequence reaches
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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
|
@@ -532,6 +532,23 @@
|
|
|
532
532
|
"type": "boolean",
|
|
533
533
|
"description": "Whether Ctrl-C was typed; false when the program exited first."
|
|
534
534
|
},
|
|
535
|
+
"settingsOff": {
|
|
536
|
+
"type": ["array", "null"],
|
|
537
|
+
"description": "The terminal settings (stty) it switched off and left off, such as icanon and echo for raw mode; null when they could not be read. Added in 1.6.",
|
|
538
|
+
"items": {
|
|
539
|
+
"type": "string",
|
|
540
|
+
"enum": [
|
|
541
|
+
"icanon",
|
|
542
|
+
"echo",
|
|
543
|
+
"isig",
|
|
544
|
+
"iexten",
|
|
545
|
+
"opost",
|
|
546
|
+
"onlcr",
|
|
547
|
+
"icrnl",
|
|
548
|
+
"ixon"
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
},
|
|
535
552
|
"openModes": {
|
|
536
553
|
"type": "array",
|
|
537
554
|
"description": "The terminal modes it left switched on.",
|