cliprobe 0.9.0 → 1.0.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 +81 -11
- package/dist/cli.js +207 -12
- package/package.json +11 -3
- package/schema.json +595 -0
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ npx cliprobe -- esbuild
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```
|
|
34
|
-
cliprobe 0.
|
|
34
|
+
cliprobe 1.0.0: closed-pipe, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for esbuild
|
|
35
35
|
|
|
36
36
|
closed-pipe
|
|
37
37
|
FAIL esbuild --version crashed when stdout was closed (exit 0 -> 1)
|
|
@@ -54,6 +54,9 @@ stdin
|
|
|
54
54
|
ctrl-c
|
|
55
55
|
SKIP esbuild needs probe args that keep it running, such as a watch or serve command, or --bare
|
|
56
56
|
|
|
57
|
+
sigterm
|
|
58
|
+
SKIP esbuild needs probe args that keep it running, such as a watch or serve command, or --bare
|
|
59
|
+
|
|
57
60
|
restore
|
|
58
61
|
PASS esbuild --version left no terminal mode switched on when it exited
|
|
59
62
|
PASS esbuild --help left no terminal mode switched on when it exited
|
|
@@ -61,16 +64,16 @@ restore
|
|
|
61
64
|
control-chars
|
|
62
65
|
SKIP esbuild no {fixture} in the arguments; put it where the command takes a path, e.g. ls {fixture}
|
|
63
66
|
|
|
64
|
-
2 failed, 0 warned, 8 passed,
|
|
67
|
+
2 failed, 0 warned, 8 passed, 3 skipped
|
|
65
68
|
```
|
|
66
69
|
|
|
67
70
|
## Why cliprobe?
|
|
68
71
|
|
|
69
72
|
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.
|
|
70
73
|
|
|
71
|
-
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`. 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 or control-chars, which need a command that keeps running or takes a path; their fixtures and real-tool tests are in `test/`.)
|
|
74
|
+
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`. 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/`.)
|
|
72
75
|
|
|
73
|
-
The other checks cover the rest of what goes wrong between a program and the thing reading it: color codes leaking into logs and agent transcripts, Ctrl-C that is ignored or ends in a stack trace, 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.
|
|
76
|
+
The other checks cover the rest of what goes wrong between a program and the thing reading it: 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.
|
|
74
77
|
|
|
75
78
|
- **Evidence, never a score.** Every result is a verdict with the error line, the first stack frame in the target's own code, or the escape sequence that leaked.
|
|
76
79
|
- **No false fails.** A new check starts as warn-only and is calibrated against real tools before it may fail.
|
|
@@ -84,7 +87,9 @@ The other checks cover the rest of what goes wrong between a program and the thi
|
|
|
84
87
|
- [Usage](#usage)
|
|
85
88
|
- [Exit codes](#exit-codes)
|
|
86
89
|
- [In CI](#in-ci)
|
|
87
|
-
- [
|
|
90
|
+
- [JSON output](#json-output)
|
|
91
|
+
- [Stability](#stability)
|
|
92
|
+
- [Checks](#checks): [closed-pipe](#closed-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)
|
|
88
93
|
- [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
|
|
89
94
|
- [Safety](#safety)
|
|
90
95
|
- [Contributing](#contributing)
|
|
@@ -144,13 +149,13 @@ A failed check exits 1, so the step fails. In GitHub Actions, write a Markdown r
|
|
|
144
149
|
|
|
145
150
|
```yaml
|
|
146
151
|
- name: Check the CLI for terminal-edge bugs
|
|
147
|
-
run: npx --yes cliprobe@
|
|
152
|
+
run: npx --yes cliprobe@1 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
|
|
148
153
|
```
|
|
149
154
|
|
|
150
155
|
For CI systems that read test results, write JUnit XML instead and keep it even when the step fails:
|
|
151
156
|
|
|
152
157
|
```yaml
|
|
153
|
-
- run: npx --yes cliprobe@
|
|
158
|
+
- run: npx --yes cliprobe@1 --format junit --output-file reports/cliprobe.xml -- node ./dist/cli.js
|
|
154
159
|
- uses: actions/upload-artifact@v7
|
|
155
160
|
if: always()
|
|
156
161
|
with:
|
|
@@ -160,11 +165,52 @@ For CI systems that read test results, write JUnit XML instead and keep it even
|
|
|
160
165
|
|
|
161
166
|
In JUnit, each check is a test suite and each probe a test case: `FAIL` is a failure, could-not-run an error, `SKIP` skipped; `WARN`, `INFO` and `PASS` pass, with the verdict and reason in the case's output.
|
|
162
167
|
|
|
168
|
+
## JSON output
|
|
169
|
+
|
|
170
|
+
`--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"tool": "cliprobe",
|
|
175
|
+
"schemaVersion": 1,
|
|
176
|
+
"version": "1.0.0",
|
|
177
|
+
"command": "node",
|
|
178
|
+
"checks": ["ctrl-c"],
|
|
179
|
+
"summary": { "pass": 0, "fail": 1, "warn": 0, "skip": 0, "error": 0, "info": 0 },
|
|
180
|
+
"results": [
|
|
181
|
+
{
|
|
182
|
+
"check": "ctrl-c",
|
|
183
|
+
"invocation": ["node", "server.js"],
|
|
184
|
+
"verdict": "fail",
|
|
185
|
+
"reason": "ignored Ctrl-C: still running 3 s later",
|
|
186
|
+
"details": {
|
|
187
|
+
"sentAfterMs": 1003,
|
|
188
|
+
"exitedAfterMs": null,
|
|
189
|
+
"exitCode": null,
|
|
190
|
+
"signal": "SIGKILL",
|
|
191
|
+
"stderrAfter": ""
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Every result has the same five fields: `check`, `invocation` (the command and arguments that ran), `verdict` (`pass`, `fail`, `warn`, `skip`, `error` for could-not-run, or `info`), `reason` (a sentence for a person) and `details`, plus `evidence` when there is a line to quote. `details` holds the check's own measurements, such as exit codes, timings, the terminal modes left on or the processes left running; the schema describes each check's. Text from the program under test is escaped: control characters, line separators and bidi overrides appear as `\u` escapes, so the report can't drive a terminal when printed.
|
|
199
|
+
|
|
200
|
+
## Stability
|
|
201
|
+
|
|
202
|
+
From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
|
|
203
|
+
|
|
204
|
+
- **No new failures.** A minor release never makes a passing or warning program fail. New checks, and new things an existing check notices, only warn until the next major release. So `cliprobe@1` in CI turns red only when your program changes.
|
|
205
|
+
- **Names and exit codes.** Check names, verdicts, options and exit codes stay as they are.
|
|
206
|
+
- **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
|
|
207
|
+
- **Not covered.** The wording of `reason` and `evidence`, and the human and Markdown output, are for people and may change. Match on `check` and `verdict`, not on text.
|
|
208
|
+
|
|
163
209
|
## Checks
|
|
164
210
|
|
|
165
|
-
A default run does the
|
|
211
|
+
A default run does the eight checks below: closed-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`.
|
|
166
212
|
|
|
167
|
-
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c and restore need. The other checks judge it on what it did before the timeout (`--timeout`, 15 seconds by default): a crash once stdout is closed still fails, color or a spinner in a pipe still counts, and stdin is skipped. The timeout is paid once: after the first check sees the command still running, the others watch it for 3 seconds.
|
|
213
|
+
A command that keeps running, such as a server, a watcher or a full-screen program, is what ctrl-c, sigterm and restore need. The other checks judge it on what it did before the timeout (`--timeout`, 15 seconds by default): a crash once stdout is closed still fails, color or a spinner in a pipe still counts, and stdin is skipped. The timeout is paid once: after the first check sees the command still running, the others watch it for 3 seconds.
|
|
168
214
|
|
|
169
215
|
### closed-pipe
|
|
170
216
|
|
|
@@ -231,6 +277,18 @@ cliprobe lets the command run for 1 second, then sends SIGINT to its process gro
|
|
|
231
277
|
|
|
232
278
|
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.
|
|
233
279
|
|
|
280
|
+
### sigterm
|
|
281
|
+
|
|
282
|
+
`kill <pid>`, `docker stop`, systemd, pm2 and CI runners that cancel a job send SIGTERM to the program alone, not to its process group as a terminal sends Ctrl-C. So a program that started children (a dev server, a worker pool, a shell running a command) has to stop them itself. If it exits without doing so, they keep running with nobody to stop them, holding their ports and files. cliprobe lets the command run for 1 second, sends SIGTERM to it alone, and gives it 3 seconds to exit and 1 more second for its children to follow, then lists what is still running in its process group and kills it. stdin is left open, as for ctrl-c. Results:
|
|
283
|
+
|
|
284
|
+
| Verdict | Meaning |
|
|
285
|
+
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
286
|
+
| `PASS` | Exited, by the signal or with any exit code, and left nothing running in its process group |
|
|
287
|
+
| `WARN` | Exited but left processes running (the evidence names the first), still running 3 seconds later, or printed a stack trace after the SIGTERM |
|
|
288
|
+
| `SKIP` | Finished before the SIGTERM, as `--version` and `--help` do: probe a command that keeps running |
|
|
289
|
+
|
|
290
|
+
It only warns for now. Across 44 watch modes, dev servers and long tasks run offline, every one exited within 90 ms of the SIGTERM, and 37 left nothing behind: vite, webpack, tsc, jest, Next.js, Nuxt, Astro, wrangler, nodemon, concurrently and more stop their own children. All 7 warnings were real, with the process still running 5 seconds later: `npm run dev`, `npm run serve` and `npx vite`, because npm dies on SIGTERM without passing it on (run `node` directly in a container or a process manager), and shell wrappers such as `sh -c 'node server.js'` or `bash -c 'sleep 30; echo done'`. Nothing ignored SIGTERM or printed a stack trace.
|
|
291
|
+
|
|
234
292
|
### restore
|
|
235
293
|
|
|
236
294
|
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:
|
|
@@ -254,7 +312,7 @@ Put `{fixture}` in the arguments where your command takes a path, for example `n
|
|
|
254
312
|
| `WARN` | Printed a C1 control, carriage return or newline from a file name unescaped, which can hide or forge output |
|
|
255
313
|
| `SKIP` | No `{fixture}` in the arguments, the command never printed the file names (before the timeout, for one that keeps running), or no usable `script` |
|
|
256
314
|
|
|
257
|
-
Only the terminal run is judged. Into a pipe, `ls` and `find` print names exactly, by design; that is recorded in the JSON (`pipeRaw`) but doesn't affect the verdict. BSD `find` on macOS fails this check: unlike GNU `find`, it prints names raw even to a terminal.
|
|
315
|
+
Only the terminal run is judged. Into a pipe, `ls` and `find` print names exactly, by design; that is recorded in the JSON (`details.pipeRaw`) but doesn't affect the verdict. BSD `find` on macOS fails this check: unlike GNU `find`, it prints names raw even to a terminal.
|
|
258
316
|
|
|
259
317
|
### Info checks
|
|
260
318
|
|
|
@@ -313,6 +371,18 @@ process.once('SIGINT', async () => {
|
|
|
313
371
|
|
|
314
372
|
That matters to the shell that started you: bash stops a script on Ctrl-C only when the program died by the signal. After an exit with 130 or 0, the script carries on to its next command; 130 at least stops `&&` chains and `set -e`, which 0 doesn't.
|
|
315
373
|
|
|
374
|
+
**sigterm:** stop what you started before you exit. Pass the signal on to each child and wait for it:
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
const server = spawn(process.execPath, ['server.js'], { stdio: 'inherit' });
|
|
378
|
+
process.once('SIGTERM', () => {
|
|
379
|
+
server.once('exit', () => process.exit(0));
|
|
380
|
+
server.kill('SIGTERM');
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
A shell wrapper should `exec` its last command (`sh -c 'exec node server.js'`), so the signal goes straight to it instead of to a shell that dies and leaves it running.
|
|
385
|
+
|
|
316
386
|
**restore:** switch every mode back off on the way out, including after Ctrl-C. Node runs `exit` handlers on `process.exit()` but not when a signal kills it, so turn SIGINT into an exit, and in raw mode, where Ctrl-C arrives as the key `\x03`, exit on that key too:
|
|
317
387
|
|
|
318
388
|
```js
|
|
@@ -334,7 +404,7 @@ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+
|
|
|
334
404
|
|
|
335
405
|
## Safety
|
|
336
406
|
|
|
337
|
-
cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin
|
|
407
|
+
cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin, ctrl-c and sigterm checks use a pipe that they never write to), 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`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal, and kills whatever a program leaves running in its group when it exits under the sigterm check. 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.
|
|
338
408
|
|
|
339
409
|
## Contributing
|
|
340
410
|
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { execFileSync, spawn } from "node:child_process";
|
|
4
|
-
import { accessSync, closeSync, constants, mkdirSync, mkdtempSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
4
|
+
import { accessSync, closeSync, constants, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import { delimiter, dirname, join } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
+
// src/core/group.ts
|
|
8
|
+
/**
|
|
9
|
+
* The processes of group `pgid` that are still running. Zombies are left out:
|
|
10
|
+
* where nothing reaps orphans, as in a container without an init process, they
|
|
11
|
+
* stay in the group for good although they have exited.
|
|
12
|
+
*/
|
|
13
|
+
function groupMembers(pgid) {
|
|
14
|
+
return process.platform === "linux" ? membersFromProc(pgid) : membersFromPs(pgid);
|
|
15
|
+
}
|
|
16
|
+
/** Linux: reads `<root>/<pid>/stat` and `cmdline` for every process. */
|
|
17
|
+
function membersFromProc(pgid, root = "/proc") {
|
|
18
|
+
const members = [];
|
|
19
|
+
for (const entry of readdirSync(root)) {
|
|
20
|
+
if (!/^\d+$/.test(entry)) continue;
|
|
21
|
+
try {
|
|
22
|
+
const stat = parseProcStat(readFileSync(`${root}/${entry}/stat`, "utf8"));
|
|
23
|
+
if (stat.pgid !== pgid || isGone(stat.state)) continue;
|
|
24
|
+
const cmdline = readFileSync(`${root}/${entry}/cmdline`, "utf8").split("\0").filter(Boolean).join(" ");
|
|
25
|
+
members.push({
|
|
26
|
+
pid: Number(entry),
|
|
27
|
+
command: cmdline || stat.name
|
|
28
|
+
});
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
return members.sort((a, b) => a.pid - b.pid);
|
|
32
|
+
}
|
|
33
|
+
/** macOS and other systems without /proc: asks ps. */
|
|
34
|
+
function membersFromPs(pgid) {
|
|
35
|
+
return parsePs(execFileSync("ps", [
|
|
36
|
+
"-A",
|
|
37
|
+
"-o",
|
|
38
|
+
"pid=,pgid=,stat=,args="
|
|
39
|
+
], { encoding: "utf8" }), pgid);
|
|
40
|
+
}
|
|
41
|
+
const isGone = (state) => state.startsWith("Z") || state.startsWith("X");
|
|
42
|
+
/** Name, state and group from a /proc/<pid>/stat line; the name may hold spaces and parentheses. */
|
|
43
|
+
function parseProcStat(line) {
|
|
44
|
+
const open = line.indexOf("(");
|
|
45
|
+
const close = line.lastIndexOf(")");
|
|
46
|
+
const [state = "", , pgid = ""] = line.slice(close + 1).trim().split(" ");
|
|
47
|
+
return {
|
|
48
|
+
name: line.slice(open + 1, close),
|
|
49
|
+
state,
|
|
50
|
+
pgid: Number(pgid)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Running members of group `pgid` from `ps -A -o pid=,pgid=,stat=,args=` output. */
|
|
54
|
+
function parsePs(out, pgid) {
|
|
55
|
+
const members = [];
|
|
56
|
+
for (const line of out.split("\n")) {
|
|
57
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
58
|
+
if (!m || Number(m[2]) !== pgid || isGone(m[3] ?? "")) continue;
|
|
59
|
+
members.push({
|
|
60
|
+
pid: Number(m[1]),
|
|
61
|
+
command: (m[4] ?? "").trim()
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return members.sort((a, b) => a.pid - b.pid);
|
|
65
|
+
}
|
|
7
66
|
// src/core/sandbox.ts
|
|
8
67
|
/** A minimal environment: no tokens or config from the caller's shell. */
|
|
9
68
|
function sandbox() {
|
|
@@ -29,7 +88,7 @@ const STDOUT_CAP = 1048576;
|
|
|
29
88
|
* whose read end is closed before the program starts, so its first write to
|
|
30
89
|
* stdout fails (EPIPE, or SIGPIPE for programs that keep the default handler).
|
|
31
90
|
*/
|
|
32
|
-
function run$1(command, args, { closedStdout = false, timeout, env: overrides = {}, beforeKill, signal, stdin = "null" }) {
|
|
91
|
+
function run$1(command, args, { closedStdout = false, timeout, env: overrides = {}, beforeKill, signal, stdin = "null", leftoversMs }) {
|
|
33
92
|
const { dir, env: base } = sandbox();
|
|
34
93
|
const env = { ...base };
|
|
35
94
|
for (const [key, value] of Object.entries(overrides)) if (value === void 0) delete env[key];
|
|
@@ -51,6 +110,9 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
51
110
|
let exited = false;
|
|
52
111
|
let signalSentMs;
|
|
53
112
|
let stderrAtSignal;
|
|
113
|
+
let leftRunning;
|
|
114
|
+
let afterExit = Promise.resolve();
|
|
115
|
+
let exitMs;
|
|
54
116
|
const start = performance.now();
|
|
55
117
|
const finish = (outcome) => {
|
|
56
118
|
if (finished) return;
|
|
@@ -66,11 +128,12 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
66
128
|
stdout,
|
|
67
129
|
stderr,
|
|
68
130
|
timedOut,
|
|
69
|
-
durationMs: Math.round(performance.now() - start),
|
|
131
|
+
durationMs: exitMs ?? Math.round(performance.now() - start),
|
|
70
132
|
...signalSentMs === void 0 ? {} : {
|
|
71
133
|
signalSentMs,
|
|
72
134
|
stderrAtSignal: stderrAtSignal ?? 0
|
|
73
135
|
},
|
|
136
|
+
...leftRunning === void 0 ? {} : { leftRunning },
|
|
74
137
|
...outcome
|
|
75
138
|
});
|
|
76
139
|
};
|
|
@@ -105,7 +168,7 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
105
168
|
signalSentMs = Math.round(performance.now() - start);
|
|
106
169
|
stderrAtSignal = stderr.length;
|
|
107
170
|
try {
|
|
108
|
-
process.kill(-child.pid, signal.name);
|
|
171
|
+
process.kill(signal.to === "process" ? child.pid : -child.pid, signal.name);
|
|
109
172
|
} catch {}
|
|
110
173
|
}, signal.afterMs);
|
|
111
174
|
const closeTimer = typeof stdin === "object" ? setTimeout(() => child.stdin?.destroy(), stdin.closeAfterMs) : void 0;
|
|
@@ -114,6 +177,14 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
114
177
|
clearTimeout(signalTimer);
|
|
115
178
|
clearTimeout(closeTimer);
|
|
116
179
|
child.stdin?.destroy();
|
|
180
|
+
if (leftoversMs !== void 0 && !timedOut && child.pid !== void 0) {
|
|
181
|
+
clearTimeout(timer);
|
|
182
|
+
exitMs = Math.round(performance.now() - start);
|
|
183
|
+
const pgid = child.pid;
|
|
184
|
+
afterExit = (async () => {
|
|
185
|
+
leftRunning = await watchLeftovers(pgid, leftoversMs);
|
|
186
|
+
})();
|
|
187
|
+
}
|
|
117
188
|
});
|
|
118
189
|
child.stdout?.on("data", (chunk) => {
|
|
119
190
|
if (stdoutBytes < STDOUT_CAP) stdoutChunks.push(chunk);
|
|
@@ -134,13 +205,31 @@ function run$1(command, args, { closedStdout = false, timeout, env: overrides =
|
|
|
134
205
|
child.on("close", (exitCode, exitSignal) => {
|
|
135
206
|
clearTimeout(timer);
|
|
136
207
|
clearTimeout(signalTimer);
|
|
137
|
-
finish({
|
|
208
|
+
afterExit.then(() => finish({
|
|
138
209
|
exitCode,
|
|
139
210
|
signal: exitSignal
|
|
140
|
-
});
|
|
211
|
+
}));
|
|
141
212
|
});
|
|
142
213
|
});
|
|
143
214
|
}
|
|
215
|
+
/** How often to look at the group while waiting for it to empty. */
|
|
216
|
+
const GROUP_POLL_MS = 50;
|
|
217
|
+
/**
|
|
218
|
+
* Waits up to `ms` for group `pgid` to empty, as children stopped by their
|
|
219
|
+
* parent take a moment to exit, then kills whatever is left and returns it.
|
|
220
|
+
*/
|
|
221
|
+
async function watchLeftovers(pgid, ms) {
|
|
222
|
+
const deadline = performance.now() + ms;
|
|
223
|
+
let members = groupMembers(pgid);
|
|
224
|
+
while (members.length > 0 && performance.now() < deadline) {
|
|
225
|
+
await new Promise((resolve) => setTimeout(resolve, GROUP_POLL_MS));
|
|
226
|
+
members = groupMembers(pgid);
|
|
227
|
+
}
|
|
228
|
+
if (members.length > 0) try {
|
|
229
|
+
process.kill(-pgid, "SIGKILL");
|
|
230
|
+
} catch {}
|
|
231
|
+
return members;
|
|
232
|
+
}
|
|
144
233
|
// src/checks/baseline.ts
|
|
145
234
|
/** A flag no real program defines. */
|
|
146
235
|
const UNKNOWN_FLAG = "--cliprobe-unknown-flag";
|
|
@@ -1153,7 +1242,7 @@ const CTRL_C_DELAY_MS = 1e3;
|
|
|
1153
1242
|
/** How long it gets to exit after Ctrl-C. */
|
|
1154
1243
|
const CTRL_C_GRACE_MS = 3e3;
|
|
1155
1244
|
/** Lines worth quoting from a trace printed on Ctrl-C, best first. */
|
|
1156
|
-
const TRACE_MESSAGES = [/^(KeyboardInterrupt|\w*Error\b|\w*Exception\b|panic:)/, TRACE_RE];
|
|
1245
|
+
const TRACE_MESSAGES$1 = [/^(KeyboardInterrupt|\w*Error\b|\w*Exception\b|panic:)/, TRACE_RE];
|
|
1157
1246
|
function judgeCtrlC(r) {
|
|
1158
1247
|
if (r.spawnError) return {
|
|
1159
1248
|
verdict: "error",
|
|
@@ -1172,7 +1261,7 @@ function judgeCtrlC(r) {
|
|
|
1172
1261
|
if (TRACE_RE.test(after)) return {
|
|
1173
1262
|
verdict: "fail",
|
|
1174
1263
|
reason: "printed a stack trace on Ctrl-C",
|
|
1175
|
-
evidence: crashEvidence(after, TRACE_MESSAGES)
|
|
1264
|
+
evidence: crashEvidence(after, TRACE_MESSAGES$1)
|
|
1176
1265
|
};
|
|
1177
1266
|
if (r.signal) return {
|
|
1178
1267
|
verdict: "pass",
|
|
@@ -1424,6 +1513,94 @@ const restoreCheck = {
|
|
|
1424
1513
|
return results;
|
|
1425
1514
|
}
|
|
1426
1515
|
};
|
|
1516
|
+
// src/checks/sigterm.ts
|
|
1517
|
+
/** How long the program runs before SIGTERM. */
|
|
1518
|
+
const SIGTERM_DELAY_MS = 1e3;
|
|
1519
|
+
/** How long it gets to exit after SIGTERM. */
|
|
1520
|
+
const SIGTERM_GRACE_MS = 3e3;
|
|
1521
|
+
/** How long its children get to follow it once it has exited. */
|
|
1522
|
+
const SIGTERM_LEFTOVERS_MS = 1e3;
|
|
1523
|
+
/** Lines worth quoting from a trace printed on SIGTERM, best first. */
|
|
1524
|
+
const TRACE_MESSAGES = [/^(\w*Error\b|\w*Exception\b|panic:)/, TRACE_RE];
|
|
1525
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "es"}`;
|
|
1526
|
+
function judgeSigterm(r) {
|
|
1527
|
+
if (r.spawnError) return {
|
|
1528
|
+
verdict: "error",
|
|
1529
|
+
reason: `could not start: ${r.spawnError}`
|
|
1530
|
+
};
|
|
1531
|
+
if (r.signalSentMs === void 0) return {
|
|
1532
|
+
verdict: "skip",
|
|
1533
|
+
reason: `finished in ${r.durationMs} ms, before SIGTERM at ${SIGTERM_DELAY_MS} ms; probe a command that keeps running`
|
|
1534
|
+
};
|
|
1535
|
+
if (r.timedOut) return {
|
|
1536
|
+
verdict: "warn",
|
|
1537
|
+
reason: `ignored SIGTERM: still running ${SIGTERM_GRACE_MS / 1e3} s later, so docker stop or a process manager has to kill it`
|
|
1538
|
+
};
|
|
1539
|
+
const left = r.leftRunning ?? [];
|
|
1540
|
+
const [firstLeft] = left;
|
|
1541
|
+
if (firstLeft) return {
|
|
1542
|
+
verdict: "warn",
|
|
1543
|
+
reason: `exited on SIGTERM but left ${plural(left.length, "process")} running, which keep ports and files busy`,
|
|
1544
|
+
evidence: `still running: ${firstLeft.command}${left.length > 1 ? ` (and ${left.length - 1} more)` : ""}`
|
|
1545
|
+
};
|
|
1546
|
+
const after = r.stderr.slice(r.stderrAtSignal ?? 0);
|
|
1547
|
+
if (TRACE_RE.test(after)) return {
|
|
1548
|
+
verdict: "warn",
|
|
1549
|
+
reason: "printed a stack trace on SIGTERM",
|
|
1550
|
+
evidence: crashEvidence(after, TRACE_MESSAGES)
|
|
1551
|
+
};
|
|
1552
|
+
const ms = `${r.durationMs - r.signalSentMs} ms`;
|
|
1553
|
+
return {
|
|
1554
|
+
verdict: "pass",
|
|
1555
|
+
reason: `${r.signal ? `stopped by ${r.signal}` : `exited with code ${r.exitCode}`} in ${ms} and left nothing running`
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
async function sigterm(command, args) {
|
|
1559
|
+
const r = await run$1(command, args, {
|
|
1560
|
+
timeout: 4e3,
|
|
1561
|
+
signal: {
|
|
1562
|
+
name: "SIGTERM",
|
|
1563
|
+
afterMs: SIGTERM_DELAY_MS,
|
|
1564
|
+
to: "process"
|
|
1565
|
+
},
|
|
1566
|
+
stdin: "open",
|
|
1567
|
+
leftoversMs: SIGTERM_LEFTOVERS_MS
|
|
1568
|
+
});
|
|
1569
|
+
const sent = r.signalSentMs;
|
|
1570
|
+
return {
|
|
1571
|
+
check: "sigterm",
|
|
1572
|
+
invocation: [command, ...args],
|
|
1573
|
+
...judgeSigterm(r),
|
|
1574
|
+
sentAfterMs: sent ?? null,
|
|
1575
|
+
exitedAfterMs: sent === void 0 || r.timedOut ? null : r.durationMs - sent,
|
|
1576
|
+
exitCode: r.exitCode,
|
|
1577
|
+
signal: r.signal,
|
|
1578
|
+
leftRunning: (r.leftRunning ?? []).map((m) => m.command),
|
|
1579
|
+
stderrAfter: sent === void 0 ? "" : r.stderr.slice(r.stderrAtSignal ?? 0).slice(-2e3)
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
const sigtermCheck = {
|
|
1583
|
+
name: "sigterm",
|
|
1584
|
+
kind: "check",
|
|
1585
|
+
summary: "ignores SIGTERM, or exits on it and leaves its child processes running",
|
|
1586
|
+
async run(target) {
|
|
1587
|
+
if (!target.explicit) return [{
|
|
1588
|
+
check: "sigterm",
|
|
1589
|
+
invocation: [target.command],
|
|
1590
|
+
verdict: "skip",
|
|
1591
|
+
reason: "needs probe args that keep it running, such as a watch or serve command, or --bare",
|
|
1592
|
+
sentAfterMs: null,
|
|
1593
|
+
exitedAfterMs: null,
|
|
1594
|
+
exitCode: null,
|
|
1595
|
+
signal: null,
|
|
1596
|
+
leftRunning: [],
|
|
1597
|
+
stderrAfter: ""
|
|
1598
|
+
}];
|
|
1599
|
+
const results = [];
|
|
1600
|
+
for (const args of target.invocations) results.push(await sigterm(target.command, args));
|
|
1601
|
+
return results;
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1427
1604
|
function median(values) {
|
|
1428
1605
|
const sorted = [...values].sort((a, b) => a - b);
|
|
1429
1606
|
const mid = Math.floor(sorted.length / 2);
|
|
@@ -1603,6 +1780,7 @@ const CHECKS = [
|
|
|
1603
1780
|
}
|
|
1604
1781
|
},
|
|
1605
1782
|
ctrlCCheck,
|
|
1783
|
+
sigtermCheck,
|
|
1606
1784
|
restoreCheck,
|
|
1607
1785
|
controlCharsCheck,
|
|
1608
1786
|
startupCheck,
|
|
@@ -1704,14 +1882,26 @@ function formatHuman({ version, command, checks, results }, { color }) {
|
|
|
1704
1882
|
lines.push("", summaryLine(countVerdicts(results)));
|
|
1705
1883
|
return lines.join("\n") + "\n";
|
|
1706
1884
|
}
|
|
1707
|
-
|
|
1885
|
+
/**
|
|
1886
|
+
* The report as JSON. Each result keeps the fields every check shares at the top
|
|
1887
|
+
* and moves the check's own measurements into `details`.
|
|
1888
|
+
*/
|
|
1708
1889
|
function formatJson({ version, command, checks, results }) {
|
|
1709
1890
|
return safeJson({
|
|
1710
1891
|
tool: "cliprobe",
|
|
1892
|
+
schemaVersion: 1,
|
|
1711
1893
|
version,
|
|
1712
1894
|
command,
|
|
1713
1895
|
checks,
|
|
1714
|
-
results
|
|
1896
|
+
summary: countVerdicts(results),
|
|
1897
|
+
results: results.map(({ check, invocation, verdict, reason, evidence, ...details }) => ({
|
|
1898
|
+
check,
|
|
1899
|
+
invocation,
|
|
1900
|
+
verdict,
|
|
1901
|
+
reason,
|
|
1902
|
+
...evidence === void 0 ? {} : { evidence },
|
|
1903
|
+
details
|
|
1904
|
+
}))
|
|
1715
1905
|
}) + "\n";
|
|
1716
1906
|
}
|
|
1717
1907
|
// src/report/junit.ts
|
|
@@ -1938,6 +2128,11 @@ Checks:
|
|
|
1938
2128
|
prints a stack trace; warns if it exits 0. Skipped when the
|
|
1939
2129
|
command finishes first, so probe a command that keeps running
|
|
1940
2130
|
(a watcher, a server, a long task).
|
|
2131
|
+
sigterm Sends SIGTERM to the command alone after 1 s, as kill, docker
|
|
2132
|
+
stop and process managers do. Warns if it is still running 3 s
|
|
2133
|
+
later, prints a stack trace, or exits and leaves child
|
|
2134
|
+
processes running (a dev server holding its port). Skipped
|
|
2135
|
+
when the command finishes first, as for ctrl-c.
|
|
1941
2136
|
restore Runs the command under a terminal and, for your own probes,
|
|
1942
2137
|
types Ctrl-C after 1 s, as a person would. Warns if it leaves
|
|
1943
2138
|
the cursor hidden, the alternate screen, mouse or focus
|
|
@@ -1975,8 +2170,8 @@ Options:
|
|
|
1975
2170
|
|
|
1976
2171
|
Exit codes: 0 no failures, 1 a check failed, 2 usage error or could not run.
|
|
1977
2172
|
Runs the target in the current directory without a shell, with stdin closed
|
|
1978
|
-
(the stdin
|
|
1979
|
-
and a minimal environment. Only run programs you trust.`;
|
|
2173
|
+
(the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
|
|
2174
|
+
temporary HOME and a minimal environment. Only run programs you trust.`;
|
|
1980
2175
|
// src/cli/program.ts
|
|
1981
2176
|
/** 0 no failures, 1 a check failed, 2 nothing could be judged because something could not run. */
|
|
1982
2177
|
function exitCodeFor(results) {
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "0.
|
|
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, a terminal left broken after Ctrl-C, and control characters from file names reaching your terminal.",
|
|
3
|
+
"version": "1.0.0",
|
|
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": {
|
|
7
7
|
"cliprobe": "dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"dist",
|
|
11
|
+
"schema.json"
|
|
11
12
|
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./schema.json": "./schema.json",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
12
17
|
"scripts": {
|
|
13
18
|
"build": "tsdown",
|
|
14
19
|
"dev": "node src/cli/main.ts",
|
|
@@ -38,6 +43,8 @@
|
|
|
38
43
|
"no-color",
|
|
39
44
|
"sigint",
|
|
40
45
|
"ctrl-c",
|
|
46
|
+
"sigterm",
|
|
47
|
+
"graceful-shutdown",
|
|
41
48
|
"terminal-injection",
|
|
42
49
|
"pty",
|
|
43
50
|
"stdin",
|
|
@@ -81,6 +88,7 @@
|
|
|
81
88
|
"@types/markdown-it": "^14.2.0",
|
|
82
89
|
"@types/node": "^22.20.5",
|
|
83
90
|
"@vitest/coverage-v8": "^5.1.0",
|
|
91
|
+
"ajv": "^8.20.0",
|
|
84
92
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
85
93
|
"fast-xml-parser": "^5.12.0",
|
|
86
94
|
"husky": "^9.1.7",
|
package/schema.json
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://unpkg.com/cliprobe@1/schema.json",
|
|
4
|
+
"title": "cliprobe JSON report",
|
|
5
|
+
"description": "Output of cliprobe --format json, schemaVersion 1. Within 1.x, fields are only added, never removed, renamed or retyped.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["tool", "schemaVersion", "version", "command", "checks", "summary", "results"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"tool": {
|
|
10
|
+
"const": "cliprobe"
|
|
11
|
+
},
|
|
12
|
+
"schemaVersion": {
|
|
13
|
+
"const": 1
|
|
14
|
+
},
|
|
15
|
+
"version": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "The cliprobe version that wrote the report."
|
|
18
|
+
},
|
|
19
|
+
"command": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "The command under test, as given."
|
|
22
|
+
},
|
|
23
|
+
"checks": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"items": {
|
|
26
|
+
"$ref": "#/$defs/checkName"
|
|
27
|
+
},
|
|
28
|
+
"description": "The checks that ran, in order."
|
|
29
|
+
},
|
|
30
|
+
"summary": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"description": "How many results have each verdict.",
|
|
33
|
+
"required": ["pass", "fail", "warn", "skip", "error", "info"],
|
|
34
|
+
"properties": {
|
|
35
|
+
"pass": {
|
|
36
|
+
"type": "integer",
|
|
37
|
+
"minimum": 0
|
|
38
|
+
},
|
|
39
|
+
"fail": {
|
|
40
|
+
"type": "integer",
|
|
41
|
+
"minimum": 0
|
|
42
|
+
},
|
|
43
|
+
"warn": {
|
|
44
|
+
"type": "integer",
|
|
45
|
+
"minimum": 0
|
|
46
|
+
},
|
|
47
|
+
"skip": {
|
|
48
|
+
"type": "integer",
|
|
49
|
+
"minimum": 0
|
|
50
|
+
},
|
|
51
|
+
"error": {
|
|
52
|
+
"type": "integer",
|
|
53
|
+
"minimum": 0
|
|
54
|
+
},
|
|
55
|
+
"info": {
|
|
56
|
+
"type": "integer",
|
|
57
|
+
"minimum": 0
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"results": {
|
|
62
|
+
"type": "array",
|
|
63
|
+
"items": {
|
|
64
|
+
"$ref": "#/$defs/result"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"$defs": {
|
|
69
|
+
"checkName": {
|
|
70
|
+
"enum": [
|
|
71
|
+
"closed-pipe",
|
|
72
|
+
"color",
|
|
73
|
+
"pipe-escapes",
|
|
74
|
+
"stdin",
|
|
75
|
+
"ctrl-c",
|
|
76
|
+
"sigterm",
|
|
77
|
+
"restore",
|
|
78
|
+
"control-chars",
|
|
79
|
+
"startup",
|
|
80
|
+
"baseline"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
"verdict": {
|
|
84
|
+
"enum": ["pass", "fail", "warn", "skip", "error", "info"],
|
|
85
|
+
"description": "fail sets exit code 1; error means the probe could not run; info comes only from info checks."
|
|
86
|
+
},
|
|
87
|
+
"controlKind": {
|
|
88
|
+
"enum": ["cursor", "erase", "mode", "hyperlink", "title", "osc", "redraw"]
|
|
89
|
+
},
|
|
90
|
+
"result": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"description": "One check on one invocation.",
|
|
93
|
+
"required": ["check", "invocation", "verdict", "reason", "details"],
|
|
94
|
+
"properties": {
|
|
95
|
+
"check": {
|
|
96
|
+
"$ref": "#/$defs/checkName"
|
|
97
|
+
},
|
|
98
|
+
"invocation": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"minItems": 1,
|
|
101
|
+
"items": {
|
|
102
|
+
"type": "string"
|
|
103
|
+
},
|
|
104
|
+
"description": "The command and arguments that were run."
|
|
105
|
+
},
|
|
106
|
+
"verdict": {
|
|
107
|
+
"$ref": "#/$defs/verdict"
|
|
108
|
+
},
|
|
109
|
+
"reason": {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"description": "One sentence for a person; its wording may change."
|
|
112
|
+
},
|
|
113
|
+
"evidence": {
|
|
114
|
+
"type": "string",
|
|
115
|
+
"description": "The line that led to the verdict, escaped; absent when there is none."
|
|
116
|
+
},
|
|
117
|
+
"details": {
|
|
118
|
+
"type": "object",
|
|
119
|
+
"description": "The check's own measurements, described by $defs/details.<check>."
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"allOf": [
|
|
123
|
+
{
|
|
124
|
+
"if": {
|
|
125
|
+
"properties": {
|
|
126
|
+
"check": {
|
|
127
|
+
"const": "closed-pipe"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"then": {
|
|
132
|
+
"properties": {
|
|
133
|
+
"details": {
|
|
134
|
+
"$ref": "#/$defs/details.closed-pipe"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"if": {
|
|
141
|
+
"properties": {
|
|
142
|
+
"check": {
|
|
143
|
+
"const": "color"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"then": {
|
|
148
|
+
"properties": {
|
|
149
|
+
"details": {
|
|
150
|
+
"$ref": "#/$defs/details.color"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"if": {
|
|
157
|
+
"properties": {
|
|
158
|
+
"check": {
|
|
159
|
+
"const": "pipe-escapes"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"then": {
|
|
164
|
+
"properties": {
|
|
165
|
+
"details": {
|
|
166
|
+
"$ref": "#/$defs/details.pipe-escapes"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"if": {
|
|
173
|
+
"properties": {
|
|
174
|
+
"check": {
|
|
175
|
+
"const": "stdin"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"then": {
|
|
180
|
+
"properties": {
|
|
181
|
+
"details": {
|
|
182
|
+
"$ref": "#/$defs/details.stdin"
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"if": {
|
|
189
|
+
"properties": {
|
|
190
|
+
"check": {
|
|
191
|
+
"const": "ctrl-c"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"then": {
|
|
196
|
+
"properties": {
|
|
197
|
+
"details": {
|
|
198
|
+
"$ref": "#/$defs/details.ctrl-c"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"if": {
|
|
205
|
+
"properties": {
|
|
206
|
+
"check": {
|
|
207
|
+
"const": "sigterm"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"then": {
|
|
212
|
+
"properties": {
|
|
213
|
+
"details": {
|
|
214
|
+
"$ref": "#/$defs/details.sigterm"
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"if": {
|
|
221
|
+
"properties": {
|
|
222
|
+
"check": {
|
|
223
|
+
"const": "restore"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
"then": {
|
|
228
|
+
"properties": {
|
|
229
|
+
"details": {
|
|
230
|
+
"$ref": "#/$defs/details.restore"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"if": {
|
|
237
|
+
"properties": {
|
|
238
|
+
"check": {
|
|
239
|
+
"const": "control-chars"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"then": {
|
|
244
|
+
"properties": {
|
|
245
|
+
"details": {
|
|
246
|
+
"$ref": "#/$defs/details.control-chars"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"if": {
|
|
253
|
+
"properties": {
|
|
254
|
+
"check": {
|
|
255
|
+
"const": "startup"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
"then": {
|
|
260
|
+
"properties": {
|
|
261
|
+
"details": {
|
|
262
|
+
"$ref": "#/$defs/details.startup"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"if": {
|
|
269
|
+
"properties": {
|
|
270
|
+
"check": {
|
|
271
|
+
"const": "baseline"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
"then": {
|
|
276
|
+
"properties": {
|
|
277
|
+
"details": {
|
|
278
|
+
"$ref": "#/$defs/details.baseline"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
"details.closed-pipe": {
|
|
286
|
+
"type": "object",
|
|
287
|
+
"description": "A normal run into a pipe, then a run with stdout already closed.",
|
|
288
|
+
"required": ["baseline", "closed"],
|
|
289
|
+
"properties": {
|
|
290
|
+
"baseline": {
|
|
291
|
+
"type": "object",
|
|
292
|
+
"description": "The normal run.",
|
|
293
|
+
"required": ["exitCode", "signal", "stdoutBytes"],
|
|
294
|
+
"properties": {
|
|
295
|
+
"exitCode": {
|
|
296
|
+
"type": ["integer", "null"],
|
|
297
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
298
|
+
},
|
|
299
|
+
"signal": {
|
|
300
|
+
"type": ["string", "null"],
|
|
301
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
302
|
+
},
|
|
303
|
+
"stdoutBytes": {
|
|
304
|
+
"type": "integer",
|
|
305
|
+
"minimum": 0
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
"closed": {
|
|
310
|
+
"type": "object",
|
|
311
|
+
"description": "The run with stdout closed.",
|
|
312
|
+
"required": ["exitCode", "signal", "timedOut", "stderr"],
|
|
313
|
+
"properties": {
|
|
314
|
+
"exitCode": {
|
|
315
|
+
"type": ["integer", "null"],
|
|
316
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
317
|
+
},
|
|
318
|
+
"signal": {
|
|
319
|
+
"type": ["string", "null"],
|
|
320
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
321
|
+
},
|
|
322
|
+
"timedOut": {
|
|
323
|
+
"type": "boolean"
|
|
324
|
+
},
|
|
325
|
+
"stderr": {
|
|
326
|
+
"type": "string",
|
|
327
|
+
"description": "What it printed to stderr, up to 64 KiB."
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
"details.color": {
|
|
334
|
+
"type": "object",
|
|
335
|
+
"description": "Runs into a pipe, under a terminal and under a terminal with NO_COLOR=1; null for a run that was not needed.",
|
|
336
|
+
"required": ["pipe", "tty", "noColor"],
|
|
337
|
+
"properties": {
|
|
338
|
+
"pipe": {
|
|
339
|
+
"type": "object",
|
|
340
|
+
"description": "The run into a pipe.",
|
|
341
|
+
"required": ["exitCode", "stdoutStyled", "stderrStyled"],
|
|
342
|
+
"properties": {
|
|
343
|
+
"exitCode": {
|
|
344
|
+
"type": ["integer", "null"],
|
|
345
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
346
|
+
},
|
|
347
|
+
"stdoutStyled": {
|
|
348
|
+
"type": "boolean"
|
|
349
|
+
},
|
|
350
|
+
"stderrStyled": {
|
|
351
|
+
"type": "boolean"
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
"tty": {
|
|
356
|
+
"type": ["object", "null"],
|
|
357
|
+
"description": "The run under a terminal.",
|
|
358
|
+
"required": ["exitCode", "timedOut", "styled"],
|
|
359
|
+
"properties": {
|
|
360
|
+
"exitCode": {
|
|
361
|
+
"type": ["integer", "null"],
|
|
362
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
363
|
+
},
|
|
364
|
+
"timedOut": {
|
|
365
|
+
"type": "boolean"
|
|
366
|
+
},
|
|
367
|
+
"styled": {
|
|
368
|
+
"type": "boolean"
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
"noColor": {
|
|
373
|
+
"type": ["object", "null"],
|
|
374
|
+
"description": "The run under a terminal with NO_COLOR=1.",
|
|
375
|
+
"required": ["exitCode", "timedOut", "styled"],
|
|
376
|
+
"properties": {
|
|
377
|
+
"exitCode": {
|
|
378
|
+
"type": ["integer", "null"],
|
|
379
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
380
|
+
},
|
|
381
|
+
"timedOut": {
|
|
382
|
+
"type": "boolean"
|
|
383
|
+
},
|
|
384
|
+
"styled": {
|
|
385
|
+
"type": "boolean"
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
"details.pipe-escapes": {
|
|
392
|
+
"type": "object",
|
|
393
|
+
"description": "Kinds of control code found on each stream, without repeats.",
|
|
394
|
+
"required": ["stdoutKinds", "stderrKinds"],
|
|
395
|
+
"properties": {
|
|
396
|
+
"stdoutKinds": {
|
|
397
|
+
"type": "array",
|
|
398
|
+
"items": {
|
|
399
|
+
"$ref": "#/$defs/controlKind"
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
"stderrKinds": {
|
|
403
|
+
"type": "array",
|
|
404
|
+
"items": {
|
|
405
|
+
"$ref": "#/$defs/controlKind"
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
"details.stdin": {
|
|
411
|
+
"type": "object",
|
|
412
|
+
"description": "The run with stdin as an open pipe that is closed after a while.",
|
|
413
|
+
"required": ["closedMs", "waitedForStdin", "finishedAfterCloseMs"],
|
|
414
|
+
"properties": {
|
|
415
|
+
"closedMs": {
|
|
416
|
+
"type": ["integer", "null"],
|
|
417
|
+
"minimum": 0,
|
|
418
|
+
"description": "When stdin was closed, in ms after start; null if it finished first."
|
|
419
|
+
},
|
|
420
|
+
"waitedForStdin": {
|
|
421
|
+
"type": "boolean"
|
|
422
|
+
},
|
|
423
|
+
"finishedAfterCloseMs": {
|
|
424
|
+
"type": ["integer", "null"],
|
|
425
|
+
"minimum": 0,
|
|
426
|
+
"description": "From closing stdin to the program finishing; null if not measured."
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
"details.ctrl-c": {
|
|
431
|
+
"type": "object",
|
|
432
|
+
"description": "SIGINT to the process group after 1 s.",
|
|
433
|
+
"required": ["sentAfterMs", "exitedAfterMs", "exitCode", "signal", "stderrAfter"],
|
|
434
|
+
"properties": {
|
|
435
|
+
"sentAfterMs": {
|
|
436
|
+
"type": ["integer", "null"],
|
|
437
|
+
"minimum": 0,
|
|
438
|
+
"description": "When SIGINT was sent, in ms after start; null if the program had already exited."
|
|
439
|
+
},
|
|
440
|
+
"exitedAfterMs": {
|
|
441
|
+
"type": ["integer", "null"],
|
|
442
|
+
"minimum": 0,
|
|
443
|
+
"description": "From SIGINT to exit; null if it was not sent or the program ignored it."
|
|
444
|
+
},
|
|
445
|
+
"exitCode": {
|
|
446
|
+
"type": ["integer", "null"],
|
|
447
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
448
|
+
},
|
|
449
|
+
"signal": {
|
|
450
|
+
"type": ["string", "null"],
|
|
451
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
452
|
+
},
|
|
453
|
+
"stderrAfter": {
|
|
454
|
+
"type": "string",
|
|
455
|
+
"description": "The last 2000 characters it printed to stderr after SIGINT."
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
"details.sigterm": {
|
|
460
|
+
"type": "object",
|
|
461
|
+
"description": "SIGTERM to the program alone after 1 s.",
|
|
462
|
+
"required": [
|
|
463
|
+
"sentAfterMs",
|
|
464
|
+
"exitedAfterMs",
|
|
465
|
+
"exitCode",
|
|
466
|
+
"signal",
|
|
467
|
+
"leftRunning",
|
|
468
|
+
"stderrAfter"
|
|
469
|
+
],
|
|
470
|
+
"properties": {
|
|
471
|
+
"sentAfterMs": {
|
|
472
|
+
"type": ["integer", "null"],
|
|
473
|
+
"minimum": 0,
|
|
474
|
+
"description": "When SIGTERM was sent, in ms after start; null if the program had already exited."
|
|
475
|
+
},
|
|
476
|
+
"exitedAfterMs": {
|
|
477
|
+
"type": ["integer", "null"],
|
|
478
|
+
"minimum": 0,
|
|
479
|
+
"description": "From SIGTERM to exit; null if it was not sent or the program ignored it."
|
|
480
|
+
},
|
|
481
|
+
"exitCode": {
|
|
482
|
+
"type": ["integer", "null"],
|
|
483
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
484
|
+
},
|
|
485
|
+
"signal": {
|
|
486
|
+
"type": ["string", "null"],
|
|
487
|
+
"description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
|
|
488
|
+
},
|
|
489
|
+
"leftRunning": {
|
|
490
|
+
"type": "array",
|
|
491
|
+
"items": {
|
|
492
|
+
"type": "string"
|
|
493
|
+
},
|
|
494
|
+
"description": "Command lines of the processes still running in its group after it exited."
|
|
495
|
+
},
|
|
496
|
+
"stderrAfter": {
|
|
497
|
+
"type": "string",
|
|
498
|
+
"description": "The last 2000 characters it printed to stderr after SIGTERM."
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
"details.restore": {
|
|
503
|
+
"type": "object",
|
|
504
|
+
"description": "The run under a terminal.",
|
|
505
|
+
"required": ["interrupted", "openModes"],
|
|
506
|
+
"properties": {
|
|
507
|
+
"interrupted": {
|
|
508
|
+
"type": "boolean",
|
|
509
|
+
"description": "Whether Ctrl-C was typed; false when the program exited first."
|
|
510
|
+
},
|
|
511
|
+
"openModes": {
|
|
512
|
+
"type": "array",
|
|
513
|
+
"description": "The terminal modes it left switched on.",
|
|
514
|
+
"items": {
|
|
515
|
+
"type": "object",
|
|
516
|
+
"description": "One mode left on.",
|
|
517
|
+
"required": ["label", "sequence", "line"],
|
|
518
|
+
"properties": {
|
|
519
|
+
"label": {
|
|
520
|
+
"type": "string"
|
|
521
|
+
},
|
|
522
|
+
"sequence": {
|
|
523
|
+
"type": "string",
|
|
524
|
+
"description": "The sequence that switched it on, escaped."
|
|
525
|
+
},
|
|
526
|
+
"line": {
|
|
527
|
+
"type": "integer",
|
|
528
|
+
"minimum": 1
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
"details.control-chars": {
|
|
536
|
+
"type": "object",
|
|
537
|
+
"description": "Kinds of hostile file name that reached the output unescaped.",
|
|
538
|
+
"required": ["terminalRaw", "pipeRaw"],
|
|
539
|
+
"properties": {
|
|
540
|
+
"terminalRaw": {
|
|
541
|
+
"type": "array",
|
|
542
|
+
"items": {
|
|
543
|
+
"type": "string"
|
|
544
|
+
},
|
|
545
|
+
"description": "In the terminal run; these decide the verdict."
|
|
546
|
+
},
|
|
547
|
+
"pipeRaw": {
|
|
548
|
+
"type": "array",
|
|
549
|
+
"items": {
|
|
550
|
+
"type": "string"
|
|
551
|
+
},
|
|
552
|
+
"description": "In the pipe run; normal for ls and find, so not judged."
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
"details.startup": {
|
|
557
|
+
"type": "object",
|
|
558
|
+
"description": "Timed runs.",
|
|
559
|
+
"required": ["runsMs", "medianMs"],
|
|
560
|
+
"properties": {
|
|
561
|
+
"runsMs": {
|
|
562
|
+
"type": "array",
|
|
563
|
+
"items": {
|
|
564
|
+
"type": "integer",
|
|
565
|
+
"minimum": 0
|
|
566
|
+
},
|
|
567
|
+
"description": "Wall time of each timed run."
|
|
568
|
+
},
|
|
569
|
+
"medianMs": {
|
|
570
|
+
"type": ["integer", "null"],
|
|
571
|
+
"minimum": 0
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
"details.baseline": {
|
|
576
|
+
"type": "object",
|
|
577
|
+
"description": "One run with the extra flag.",
|
|
578
|
+
"required": ["exitCode", "stdoutLines", "stderrLines"],
|
|
579
|
+
"properties": {
|
|
580
|
+
"exitCode": {
|
|
581
|
+
"type": ["integer", "null"],
|
|
582
|
+
"description": "Exit code; null if it was killed by a signal or never ran."
|
|
583
|
+
},
|
|
584
|
+
"stdoutLines": {
|
|
585
|
+
"type": "integer",
|
|
586
|
+
"minimum": 0
|
|
587
|
+
},
|
|
588
|
+
"stderrLines": {
|
|
589
|
+
"type": "integer",
|
|
590
|
+
"minimum": 0
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|