cliprobe 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -11
- package/dist/cli.js +306 -45
- package/package.json +1 -1
- package/schema.json +11 -0
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ control-chars
|
|
|
78
78
|
|
|
79
79
|
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.
|
|
80
80
|
|
|
81
|
-
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`. Since then esbuild and
|
|
81
|
+
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`. Since then esbuild, browserslist and autoprefixer have fixed it; the other six still crash at their December 2026 versions. 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/`.) The census is repeatable: [`census/`](https://github.com/KhaledSaeed18/cliprobe/tree/main/census) pins the packages, runs them offline with one command, and keeps [the latest results](https://github.com/KhaledSaeed18/cliprobe/blob/main/census/results/top-100.md).
|
|
82
82
|
|
|
83
83
|
The other checks cover the rest of what goes wrong between a program and the thing reading it: output lost on a full disk while the program exits 0, 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.
|
|
84
84
|
|
|
@@ -92,6 +92,7 @@ The other checks cover the rest of what goes wrong between a program and the thi
|
|
|
92
92
|
|
|
93
93
|
- [Installation](#installation)
|
|
94
94
|
- [Usage](#usage)
|
|
95
|
+
- [Config file](#config-file)
|
|
95
96
|
- [Exit codes](#exit-codes)
|
|
96
97
|
- [In CI](#in-ci)
|
|
97
98
|
- [JSON output](#json-output)
|
|
@@ -133,12 +134,14 @@ npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile fi
|
|
|
133
134
|
npx cliprobe --bare -- htop # the command alone: a REPL, a full-screen program, a server
|
|
134
135
|
npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
|
|
135
136
|
npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings fail too, except restore's
|
|
137
|
+
npx cliprobe # no command: the run in cliprobe.config.json
|
|
136
138
|
```
|
|
137
139
|
|
|
138
140
|
| Option | Meaning |
|
|
139
141
|
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
142
|
| `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
|
|
141
143
|
| `--probe <args>` | Also probe `<command> <args>`; repeat it for several. Split like a shell command line (quotes and backslashes, no variables or wildcards). The args after `<command>` aren't kept: with `-- node ./cli.js`, write `--probe "./cli.js watch"` |
|
|
144
|
+
| `--config <path>` | Read this [config file](#config-file) instead of `cliprobe.config.json`; give no command with it |
|
|
142
145
|
| `--check <name>` | Run only this check; repeat it or use commas for several |
|
|
143
146
|
| `--skip <name>` | Leave this check out; repeat it or use commas for several |
|
|
144
147
|
| `--strict` | Exit 1 on a warning too, not only on a failure |
|
|
@@ -153,13 +156,65 @@ An option's value follows it or comes after `=` (`--format=json`). A value that
|
|
|
153
156
|
|
|
154
157
|
A probe runs `<command>` with its own args, in place of the args after the command, not after them. So when the command is an interpreter, name the script in every probe: `npx cliprobe --probe "./dist/cli.js watch" -- node ./dist/cli.js` probes `node ./dist/cli.js` and `node ./dist/cli.js watch`, while `--probe watch` would run `node watch`. A probe that exits with a failure code and is skipped says so in its reason, with the error line from stderr as evidence, so a probe that never ran as intended doesn't pass for a quiet skip.
|
|
155
158
|
|
|
159
|
+
## Config file
|
|
160
|
+
|
|
161
|
+
A project can keep its run in `cliprobe.config.json`, so the command is the same on every machine and in CI:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"command": "node ./dist/cli.js",
|
|
166
|
+
"probes": ["serve --port 0", "scan {fixture}"],
|
|
167
|
+
"strict": true,
|
|
168
|
+
"accept": [
|
|
169
|
+
{
|
|
170
|
+
"check": "ctrl-c",
|
|
171
|
+
"probe": "serve --port 0",
|
|
172
|
+
"reason": "exits 0 on Ctrl-C on purpose, as tsc --watch does"
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
npx cliprobe # with no command, reads cliprobe.config.json from the current directory
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
| Key | Meaning |
|
|
183
|
+
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
184
|
+
| `command` | The program, required. Unlike on the command line, everything in it belongs to the program, so with `node ./dist/cli.js` the probes are `--version`, `--help` and each of `probes`, all after the script |
|
|
185
|
+
| `probes` | More invocations, each the arguments after the program, as `--probe` |
|
|
186
|
+
| `bare` | `true` probes the program alone instead of `--version` and `--help`, as `--bare` |
|
|
187
|
+
| `checks`, `skip` | Arrays of check names, as `--check` and `--skip` |
|
|
188
|
+
| `strict`, `timeout` | As `--strict` and `--timeout` |
|
|
189
|
+
| `accept` | Failures and warnings the project knows about; see below |
|
|
190
|
+
|
|
191
|
+
`command` and each probe are a string, split like a shell command line (quotes and backslashes, no variables or wildcards), or an array of arguments, taken as they are. The file is plain JSON, never code. A key cliprobe doesn't know is a usage error (exit `2`), so a typo can't silently drop a probe; `$schema` is allowed.
|
|
192
|
+
|
|
193
|
+
Options on the command line add to the file: `--probe` and `--skip` join its lists, `--bare` and `--strict` switch on what it left off, and `--check` and `--timeout` replace its values. So `npx cliprobe --check closed-pipe` runs one check on the project's probes, and `--format` and `--output-file` work as usual. A command on the command line is a different run: `npx cliprobe -- ls` ignores the file. `--config <path>` reads another file; the program still runs in the current directory.
|
|
194
|
+
|
|
195
|
+
### Accepted findings
|
|
196
|
+
|
|
197
|
+
`accept` is for a failure or warning you have looked at and decided to live with, so that `--strict` (or a failing check) can gate everything else. Each entry names a `check`, a `reason`, and usually a `probe`, written as in `probes` (`"--help"` and `"--version"` name the default ones); without `probe` it covers every probe of that check.
|
|
198
|
+
|
|
199
|
+
An accepted result is never hidden. It keeps its verdict in every report, with the reason under it, and only stops counting toward the exit code:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
ctrl-c
|
|
203
|
+
WARN node ./dist/cli.js serve --port 0 exited 0 after Ctrl-C, so a script cannot tell it was interrupted (130 is the convention)
|
|
204
|
+
accepted: exits 0 on Ctrl-C on purpose, as tsc --watch does
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The summary line counts it too, as `(1 accepted in the config)`.
|
|
208
|
+
|
|
209
|
+
In JSON the result gains `"accepted": { "reason": "..." }`; in JUnit it passes, with the verdict and the reason in its output. Only `FAIL` and `WARN` can be accepted. An entry that names an unknown check, or a probe that isn't part of the run, is a usage error. When an accepted finding stops occurring, because the bug was fixed, cliprobe says so on stderr, so the entry can be removed.
|
|
210
|
+
|
|
156
211
|
## Exit codes
|
|
157
212
|
|
|
158
|
-
| Code | Meaning
|
|
159
|
-
| ---- |
|
|
160
|
-
| `0` | No check failed
|
|
161
|
-
| `1` | A check failed, or warned with `--strict
|
|
162
|
-
| `2` | Usage error, the command could not run, or the report could not be written (to stdout or the `--output-file`) |
|
|
213
|
+
| Code | Meaning |
|
|
214
|
+
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
215
|
+
| `0` | No check failed |
|
|
216
|
+
| `1` | A check failed, or warned with `--strict`, and the [config file](#accepted-findings) doesn't accept it |
|
|
217
|
+
| `2` | Usage error (a mistake in the config file is one), the command could not run, or the report could not be written (to stdout or the `--output-file`) |
|
|
163
218
|
|
|
164
219
|
Any non-zero exit fails a CI step, so cliprobe works as a gate.
|
|
165
220
|
|
|
@@ -174,6 +229,12 @@ A failed check exits 1, so the step fails. Warnings don't fail it unless you add
|
|
|
174
229
|
run: npx --yes cliprobe@1 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
|
|
175
230
|
```
|
|
176
231
|
|
|
232
|
+
With a [config file](#config-file) in the repository, the step needs no probes of its own; ask for 1.8 or later, the first version that reads it:
|
|
233
|
+
|
|
234
|
+
```yaml
|
|
235
|
+
- run: npx --yes "cliprobe@^1.8" --format markdown --output-file "$GITHUB_STEP_SUMMARY"
|
|
236
|
+
```
|
|
237
|
+
|
|
177
238
|
For CI systems that read test results, write JUnit XML instead and keep it even when the step fails:
|
|
178
239
|
|
|
179
240
|
```yaml
|
|
@@ -185,7 +246,7 @@ For CI systems that read test results, write JUnit XML instead and keep it even
|
|
|
185
246
|
path: reports/cliprobe.xml
|
|
186
247
|
```
|
|
187
248
|
|
|
188
|
-
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 `
|
|
249
|
+
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`, `PASS` and an [accepted](#accepted-findings) `FAIL` or `WARN` pass, with the verdict and reason in the case's output.
|
|
189
250
|
|
|
190
251
|
## JSON output
|
|
191
252
|
|
|
@@ -219,14 +280,14 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
219
280
|
}
|
|
220
281
|
```
|
|
221
282
|
|
|
222
|
-
`strict` says whether `--strict` was given (added in 1.1). 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. The human report shows them as `\x1b`-style escapes and doubles a backslash the program printed, so `\\x1b` is text and `\x1b` a real escape character; it cuts evidence longer than 200 characters, which the JSON has in full.
|
|
283
|
+
`strict` says whether `--strict` was given (added in 1.1). 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 and, since 1.8, `accepted` (an object with the `reason`) when the [config file accepts](#accepted-findings) the result; `summary` counts verdicts as before. `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. The human report shows them as `\x1b`-style escapes and doubles a backslash the program printed, so `\\x1b` is text and `\x1b` a real escape character; it cuts evidence longer than 200 characters, which the JSON has in full.
|
|
223
284
|
|
|
224
285
|
## Stability
|
|
225
286
|
|
|
226
287
|
From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
|
|
227
288
|
|
|
228
289
|
- **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.
|
|
229
|
-
- **Names and exit codes.** Check names, verdicts, options and exit codes stay as they are.
|
|
290
|
+
- **Names and exit codes.** Check names, verdicts, options, config file keys and exit codes stay as they are.
|
|
230
291
|
- **`--strict` opts out of the first promise.** It fails on warnings, so a new warning in a minor release can fail your build. Pin an exact version (`cliprobe@1.7.0`) if that matters, or `--skip` the check.
|
|
231
292
|
- **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
|
|
232
293
|
- **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.
|
|
@@ -266,7 +327,7 @@ cliprobe runs the command twice: once normally, then with stdout set to `/dev/fu
|
|
|
266
327
|
| `WARN` | Exited 0 though its output was lost, crashed with a stack trace, or hung |
|
|
267
328
|
| `SKIP` | Wrote nothing to stdout for this invocation (or before the timeout), or the system has no `/dev/full` (macOS) |
|
|
268
329
|
|
|
269
|
-
The check is new in 1.7 and only warns
|
|
330
|
+
The check is new in 1.7 and only warns. The December 2026 census shows why it should stay that way for now: of the 157 `--help` and `--version` runs of the top 100 npm commands that print something, 138 warned. 119 exited 0 with their output lost, among them esbuild, eslint, prettier and `tsc`, and 19 crashed with a stack trace; only 19, such as pnpm and uuid, reported the error and exited non-zero. Every one checked by hand was real (`esbuild --version > /dev/full; echo $?` prints 0), so the warning is true, but a check that most tools would fail is not one to gate a build on yet. It runs on Linux only, since macOS has no `/dev/full`; run it in CI on a Linux runner, or in a container.
|
|
270
331
|
|
|
271
332
|
### color
|
|
272
333
|
|
|
@@ -472,7 +533,7 @@ cliprobe executes the program you name, so only probe programs you trust. It lim
|
|
|
472
533
|
|
|
473
534
|
- **No shell.** The target runs in your current directory, started directly.
|
|
474
535
|
- **A minimal environment.** A temporary `HOME` and no tokens from your shell; see [the probe's environment](#the-probes-environment).
|
|
475
|
-
- **Only your arguments.** cliprobe passes the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`. Only the baseline check, when you name it, adds an unknown flag.
|
|
536
|
+
- **Only your arguments.** cliprobe passes the arguments you give, after the command or with `--probe`, or `--version` and `--help`, or none with `--bare`. With no command, they come from `cliprobe.config.json` in the current directory, which is data, never code. Only the baseline check, when you name it, adds an unknown flag.
|
|
476
537
|
- **No input.** stdin is closed (`/dev/null`); the stdin, ctrl-c and sigterm checks use a pipe that they never write to. The only input cliprobe ever sends is Ctrl-C, from the ctrl-c and restore checks, and SIGTERM, from the sigterm check, to probes you write.
|
|
477
538
|
- **Nothing left running.** It kills each run's whole process group on timeout, including under a pseudo-terminal. When a program exits, it kills whatever the program left running, in its group or started in another one, in every check.
|
|
478
539
|
- **Clean when interrupted.** If cliprobe itself is stopped by Ctrl-C, SIGTERM or SIGHUP, it first kills the probe it is running and removes its temporary directories and any half-written report file, then exits by the same signal (130, 143 or 129).
|
|
@@ -507,6 +568,8 @@ The runs under a terminal are color's second and third, restore's, and control-c
|
|
|
507
568
|
|
|
508
569
|
**Why does my program behave differently under cliprobe?** It runs without your shell's variables or your home directory, with `TERM=dumb` and `CI=1` in most checks: [the probe's environment](#the-probes-environment) lists every variable. A program that needs a token or a config file from your home directory sees neither, as on a fresh CI runner.
|
|
509
570
|
|
|
571
|
+
**How do I stop repeating the probes in every command?** Put them in a [config file](#config-file): `cliprobe.config.json` holds the command, the probes and any findings you accept, and `npx cliprobe` runs it.
|
|
572
|
+
|
|
510
573
|
**Does a pass mean my CLI has no terminal bugs?** No. Each check tests one behavior, on the probes that ran; a subcommand that wasn't probed wasn't checked. cliprobe reports evidence, not a score, so add a `--probe` for each command your users pipe or interrupt.
|
|
511
574
|
|
|
512
575
|
**Does it only work for Node.js programs?** No. It tests any command as a black box, whatever it is written in. Only the [fixes](#fixing-a-failure-in-a-nodejs-cli) are specific to Node.js.
|
package/dist/cli.js
CHANGED
|
@@ -642,7 +642,7 @@ const baselineCheck = {
|
|
|
642
642
|
summary: "--version prints one line, --help goes to stdout, an unknown flag exits non-zero",
|
|
643
643
|
async run(target, ctx) {
|
|
644
644
|
const [first] = target.probes;
|
|
645
|
-
const prefix = first?.own ? first.args : [];
|
|
645
|
+
const prefix = first?.own ? first.args : target.programArgs ?? [];
|
|
646
646
|
return [
|
|
647
647
|
await probe(target.command, [...prefix, "--version"], ctx.timeout, describeVersion),
|
|
648
648
|
await probe(target.command, [...prefix, "--help"], ctx.timeout, describeHelp),
|
|
@@ -1632,7 +1632,7 @@ const controlCharsCheck = {
|
|
|
1632
1632
|
async run(target, ctx) {
|
|
1633
1633
|
if (target.fixtureDir === void 0) {
|
|
1634
1634
|
const own = target.probes.filter((p) => p.own);
|
|
1635
|
-
return (own.length ? own.map((p) => [target.command, ...p.args]) : [[target.command]]).map((invocation) => ({
|
|
1635
|
+
return (own.length ? own.map((p) => [target.command, ...p.args]) : [[target.command, ...target.programArgs ?? []]]).map((invocation) => ({
|
|
1636
1636
|
check: "control-chars",
|
|
1637
1637
|
invocation,
|
|
1638
1638
|
...judgeControlChars({ usesFixture: false }),
|
|
@@ -1731,7 +1731,7 @@ const sigtermCheck = {
|
|
|
1731
1731
|
const own = target.probes.filter((p) => p.own);
|
|
1732
1732
|
if (own.length === 0) return [{
|
|
1733
1733
|
check: "sigterm",
|
|
1734
|
-
invocation: [target.command],
|
|
1734
|
+
invocation: [target.command, ...target.programArgs ?? []],
|
|
1735
1735
|
verdict: "skip",
|
|
1736
1736
|
reason: "needs a probe that keeps running, such as a watch or serve command (--probe), or --bare",
|
|
1737
1737
|
sentAfterMs: null,
|
|
@@ -1812,7 +1812,7 @@ function judgeCtrlC(r, bare = false) {
|
|
|
1812
1812
|
reason: `exited with code ${r.exitCode} in ${ms} (130 is the convention)`
|
|
1813
1813
|
};
|
|
1814
1814
|
}
|
|
1815
|
-
async function ctrlC(command, args) {
|
|
1815
|
+
async function ctrlC(command, args, bare = args.length === 0) {
|
|
1816
1816
|
const r = await run$1(command, args, {
|
|
1817
1817
|
timeout: 4e3,
|
|
1818
1818
|
signal: {
|
|
@@ -1826,7 +1826,7 @@ async function ctrlC(command, args) {
|
|
|
1826
1826
|
return {
|
|
1827
1827
|
check: "ctrl-c",
|
|
1828
1828
|
invocation: [command, ...args],
|
|
1829
|
-
...judgeCtrlC(r,
|
|
1829
|
+
...judgeCtrlC(r, bare),
|
|
1830
1830
|
sentAfterMs: sent ?? null,
|
|
1831
1831
|
exitedAfterMs: sent === void 0 || r.timedOut ? null : r.durationMs - sent,
|
|
1832
1832
|
exitCode: r.exitCode,
|
|
@@ -1843,7 +1843,7 @@ const ctrlCCheck = {
|
|
|
1843
1843
|
const own = target.probes.filter((p) => p.own);
|
|
1844
1844
|
if (own.length === 0) return [{
|
|
1845
1845
|
check: "ctrl-c",
|
|
1846
|
-
invocation: [target.command],
|
|
1846
|
+
invocation: [target.command, ...target.programArgs ?? []],
|
|
1847
1847
|
verdict: "skip",
|
|
1848
1848
|
reason: "needs a probe that keeps running, such as a watch or serve command (--probe), or --bare",
|
|
1849
1849
|
sentAfterMs: null,
|
|
@@ -1854,7 +1854,7 @@ const ctrlCCheck = {
|
|
|
1854
1854
|
stderrAfter: ""
|
|
1855
1855
|
}];
|
|
1856
1856
|
const results = [];
|
|
1857
|
-
for (const { args } of own) results.push(await ctrlC(target.command, args));
|
|
1857
|
+
for (const { args, bare } of own) results.push(await ctrlC(target.command, args, bare));
|
|
1858
1858
|
return results;
|
|
1859
1859
|
}
|
|
1860
1860
|
};
|
|
@@ -2127,7 +2127,7 @@ const startupCheck = {
|
|
|
2127
2127
|
summary: "median wall time of --version, or of the given probe, over 5 runs",
|
|
2128
2128
|
async run(target, ctx) {
|
|
2129
2129
|
const [first] = target.probes;
|
|
2130
|
-
const args = first?.own ? first.args : ["--version"];
|
|
2130
|
+
const args = first?.own ? first.args : [...target.programArgs ?? [], "--version"];
|
|
2131
2131
|
return [await startup(target.command, args, ctx.timeout)];
|
|
2132
2132
|
}
|
|
2133
2133
|
};
|
|
@@ -2496,15 +2496,19 @@ function countVerdicts(results) {
|
|
|
2496
2496
|
for (const r of results) counts[r.verdict]++;
|
|
2497
2497
|
return counts;
|
|
2498
2498
|
}
|
|
2499
|
+
/** How many failures and warnings the config file accepts, so they don't fail the run. */
|
|
2500
|
+
const countAccepted = (results) => results.filter((r) => r.accepted).length;
|
|
2499
2501
|
/**
|
|
2500
2502
|
* "2 failed, 0 warned, 2 passed, 2 skipped", plus info and could-not-run when
|
|
2501
|
-
* present,
|
|
2503
|
+
* present, a note when --strict makes warnings fail, and how many of the failures
|
|
2504
|
+
* and warnings the config file accepts.
|
|
2502
2505
|
*/
|
|
2503
|
-
function summaryLine(c, strict = false) {
|
|
2506
|
+
function summaryLine(c, strict = false, accepted = 0) {
|
|
2504
2507
|
const info = c.info ? `, ${c.info} info` : "";
|
|
2505
2508
|
const errors = c.error ? `, ${c.error} could not run` : "";
|
|
2506
2509
|
const mode = strict ? " (--strict: warnings fail)" : "";
|
|
2507
|
-
|
|
2510
|
+
const known = accepted ? ` (${accepted} accepted in the config)` : "";
|
|
2511
|
+
return `${c.fail} failed, ${c.warn} warned, ${c.pass} passed, ${c.skip} skipped${info}${errors}${mode}${known}`;
|
|
2508
2512
|
}
|
|
2509
2513
|
// src/report/human.ts
|
|
2510
2514
|
const COLORS = {
|
|
@@ -2550,9 +2554,10 @@ function formatHuman({ version, command, checks, strict, results }, { color }) {
|
|
|
2550
2554
|
if (invocation.length > width) lines.push(` ${paint(r.verdict)} ${invocation}`, `${indent}${safe(r.reason)}`);
|
|
2551
2555
|
else lines.push(` ${paint(r.verdict)} ${invocation.padEnd(width)} ${safe(r.reason)}`);
|
|
2552
2556
|
if (r.evidence) lines.push(`${indent}${showEvidence(r.evidence)}`);
|
|
2557
|
+
if (r.accepted) lines.push(`${indent}accepted: ${safe(r.accepted.reason)}`);
|
|
2553
2558
|
}
|
|
2554
2559
|
}
|
|
2555
|
-
lines.push("", summaryLine(countVerdicts(results), strict));
|
|
2560
|
+
lines.push("", summaryLine(countVerdicts(results), strict, countAccepted(results)));
|
|
2556
2561
|
return lines.join("\n") + "\n";
|
|
2557
2562
|
}
|
|
2558
2563
|
/**
|
|
@@ -2568,12 +2573,13 @@ function formatJson({ version, command, checks, strict, results }) {
|
|
|
2568
2573
|
checks,
|
|
2569
2574
|
strict,
|
|
2570
2575
|
summary: countVerdicts(results),
|
|
2571
|
-
results: results.map(({ check, invocation, verdict, reason, evidence, ...details }) => ({
|
|
2576
|
+
results: results.map(({ check, invocation, verdict, reason, evidence, accepted, ...details }) => ({
|
|
2572
2577
|
check,
|
|
2573
2578
|
invocation,
|
|
2574
2579
|
verdict,
|
|
2575
2580
|
reason,
|
|
2576
2581
|
...evidence === void 0 ? {} : { evidence },
|
|
2582
|
+
...accepted === void 0 ? {} : { accepted },
|
|
2577
2583
|
details
|
|
2578
2584
|
}))
|
|
2579
2585
|
}) + "\n";
|
|
@@ -2594,10 +2600,12 @@ const XML_ESCAPES = {
|
|
|
2594
2600
|
function xml(text) {
|
|
2595
2601
|
return safe(text).replace(/[&<>"']/g, (c) => XML_ESCAPES[c] ?? c);
|
|
2596
2602
|
}
|
|
2603
|
+
/** A failure, or with --strict a warning, that the config file doesn't accept. */
|
|
2604
|
+
const fails = (r, strict) => !r.accepted && (r.verdict === "fail" || strict && r.verdict === "warn");
|
|
2597
2605
|
/** JUnit's count attributes for a suite or the whole run; with --strict, warnings are failures. */
|
|
2598
2606
|
function totals(results, strict) {
|
|
2599
2607
|
const c = countVerdicts(results);
|
|
2600
|
-
const failures =
|
|
2608
|
+
const failures = results.filter((r) => fails(r, strict)).length;
|
|
2601
2609
|
return `tests="${results.length}" failures="${failures}" errors="${c.error}" skipped="${c.skip}"`;
|
|
2602
2610
|
}
|
|
2603
2611
|
function testcase(r, strict) {
|
|
@@ -2605,10 +2613,11 @@ function testcase(r, strict) {
|
|
|
2605
2613
|
const message = `message="${xml(r.reason)}"`;
|
|
2606
2614
|
const body = r.evidence ? xml(r.evidence) : "";
|
|
2607
2615
|
const failure = (type) => `${open}>\n <failure ${message} type="${type}">${body}</failure>\n </testcase>`;
|
|
2608
|
-
if (r
|
|
2616
|
+
if (fails(r, strict)) return failure(r.verdict);
|
|
2609
2617
|
if (r.verdict === "error") return `${open}>\n <error ${message} type="error">${body}</error>\n </testcase>`;
|
|
2610
2618
|
if (r.verdict === "skip") return `${open}>\n <skipped ${message}/>\n </testcase>`;
|
|
2611
|
-
|
|
2619
|
+
const accepted = r.accepted ? `\nAccepted: ${xml(r.accepted.reason)}` : "";
|
|
2620
|
+
return `${open}>\n <system-out>${`${r.verdict.toUpperCase()}: ${xml(r.reason)}${r.evidence ? `\n${body}` : ""}${accepted}`}</system-out>\n </testcase>`;
|
|
2612
2621
|
}
|
|
2613
2622
|
/** JUnit XML: one testsuite per check, one testcase per result. */
|
|
2614
2623
|
function formatJunit({ version, command, checks, strict, results }) {
|
|
@@ -2650,8 +2659,8 @@ function prose(text) {
|
|
|
2650
2659
|
return safe(text).replace(/[\\`*_[\]<>|~&]/g, (c) => `\\${c}`);
|
|
2651
2660
|
}
|
|
2652
2661
|
function row(r, strict) {
|
|
2653
|
-
const verdict = r.verdict === "
|
|
2654
|
-
const evidence = r.evidence ? `<br>${code(r.evidence.slice(0, 300), { inTable: true })}` : "";
|
|
2662
|
+
const verdict = r.verdict === "error" || !r.accepted && (r.verdict === "fail" || strict && r.verdict === "warn") ? `**${r.verdict.toUpperCase()}**` : r.verdict.toUpperCase();
|
|
2663
|
+
const evidence = (r.evidence ? `<br>${code(r.evidence.slice(0, 300), { inTable: true })}` : "") + (r.accepted ? `<br>Accepted: ${prose(r.accepted.reason)}` : "");
|
|
2655
2664
|
return `| ${[
|
|
2656
2665
|
prose(r.check),
|
|
2657
2666
|
verdict,
|
|
@@ -2664,7 +2673,7 @@ function formatMarkdown({ version, command, strict, results }) {
|
|
|
2664
2673
|
return [
|
|
2665
2674
|
`## cliprobe ${version}: ${code(command, { inTable: false })}`,
|
|
2666
2675
|
"",
|
|
2667
|
-
summaryLine(countVerdicts(results), strict),
|
|
2676
|
+
summaryLine(countVerdicts(results), strict, countAccepted(results)),
|
|
2668
2677
|
"",
|
|
2669
2678
|
"| Check | Verdict | Invocation | Result |",
|
|
2670
2679
|
"| --- | --- | --- | --- |",
|
|
@@ -2842,8 +2851,10 @@ function readVersion() {
|
|
|
2842
2851
|
return "0.0.0";
|
|
2843
2852
|
}
|
|
2844
2853
|
const VERSION = readVersion();
|
|
2845
|
-
// src/cli/
|
|
2854
|
+
// src/cli/usage.ts
|
|
2855
|
+
/** A mistake in how cliprobe was called, or in its config file: reported with exit 2. */
|
|
2846
2856
|
var UsageError = class extends Error {};
|
|
2857
|
+
// src/cli/args.ts
|
|
2847
2858
|
/** Every option cliprobe takes, to tell a forgotten value from a value that starts with -. */
|
|
2848
2859
|
const OPTIONS = /* @__PURE__ */ new Set([
|
|
2849
2860
|
"--json",
|
|
@@ -2857,19 +2868,28 @@ const OPTIONS = /* @__PURE__ */ new Set([
|
|
|
2857
2868
|
"-v",
|
|
2858
2869
|
"--version",
|
|
2859
2870
|
"--timeout",
|
|
2871
|
+
"--config",
|
|
2860
2872
|
"--probe",
|
|
2861
2873
|
"--check",
|
|
2862
2874
|
"--skip"
|
|
2863
2875
|
]);
|
|
2864
2876
|
/** Options whose value is a path, which ./ can make start with something other than -. */
|
|
2865
|
-
const PATH_OPTIONS = /* @__PURE__ */ new Set([
|
|
2877
|
+
const PATH_OPTIONS = /* @__PURE__ */ new Set([
|
|
2878
|
+
"-o",
|
|
2879
|
+
"--output-file",
|
|
2880
|
+
"--config"
|
|
2881
|
+
]);
|
|
2866
2882
|
/** The option name in an argument such as --format=json. */
|
|
2867
2883
|
const flagOf = (arg) => arg.split("=")[0] ?? arg;
|
|
2884
|
+
/** How long a probe may run when neither --timeout nor a config file says. */
|
|
2885
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
2868
2886
|
function parseArgs(argv) {
|
|
2869
2887
|
const opts = {
|
|
2870
2888
|
format: "human",
|
|
2871
2889
|
outputFile: void 0,
|
|
2872
|
-
timeout:
|
|
2890
|
+
timeout: DEFAULT_TIMEOUT_MS,
|
|
2891
|
+
timeoutGiven: false,
|
|
2892
|
+
config: void 0,
|
|
2873
2893
|
bare: false,
|
|
2874
2894
|
help: false,
|
|
2875
2895
|
version: false,
|
|
@@ -2899,6 +2919,7 @@ function parseArgs(argv) {
|
|
|
2899
2919
|
else if (a === "--bare") opts.bare = true;
|
|
2900
2920
|
else if (a === "--strict") opts.strict = true;
|
|
2901
2921
|
else if (/^(-o|--output-file)(=|$)/.test(a)) opts.outputFile = value("a file path");
|
|
2922
|
+
else if (/^--config(=|$)/.test(a)) opts.config = value("a file path");
|
|
2902
2923
|
else if (/^--format(=|$)/.test(a)) {
|
|
2903
2924
|
const format = value(`a value (one of ${FORMAT_NAMES.join(", ")})`);
|
|
2904
2925
|
if (!isFormat(format)) throw new UsageError(`--format needs one of ${FORMAT_NAMES.join(", ")}, got "${format}"`);
|
|
@@ -2908,6 +2929,7 @@ function parseArgs(argv) {
|
|
|
2908
2929
|
else if (/^--timeout(=|$)/.test(a)) {
|
|
2909
2930
|
const ms = value("a value");
|
|
2910
2931
|
opts.timeout = Number(ms);
|
|
2932
|
+
opts.timeoutGiven = true;
|
|
2911
2933
|
if (!Number.isInteger(opts.timeout) || opts.timeout <= 0 || opts.timeout > MAX_TIMEOUT_MS) throw new UsageError(`--timeout needs a whole number of milliseconds from 1 to ${MAX_TIMEOUT_MS} (about 24 days), got "${ms}"`);
|
|
2912
2934
|
} else if (a === "--probe" || a.startsWith("--probe=")) {
|
|
2913
2935
|
const probe = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
@@ -2931,6 +2953,7 @@ function parseArgs(argv) {
|
|
|
2931
2953
|
break;
|
|
2932
2954
|
}
|
|
2933
2955
|
}
|
|
2956
|
+
if (opts.config !== void 0 && opts.command !== void 0) throw new UsageError("--config names the command to probe, so give none on the command line");
|
|
2934
2957
|
if (opts.bare && opts.args.length) throw new UsageError("--bare probes the command with no arguments, so give none after it");
|
|
2935
2958
|
const seen = new Set(mainProbe(opts).map((args) => JSON.stringify(args)));
|
|
2936
2959
|
for (const args of opts.probes) {
|
|
@@ -2945,11 +2968,118 @@ function mainProbe(opts) {
|
|
|
2945
2968
|
if (opts.bare) return [[]];
|
|
2946
2969
|
return opts.args.length ? [opts.args] : [["--version"], ["--help"]];
|
|
2947
2970
|
}
|
|
2971
|
+
// src/cli/config.ts
|
|
2972
|
+
/** The file `cliprobe` reads from the current directory when no command is given. */
|
|
2973
|
+
const CONFIG_FILE = "cliprobe.config.json";
|
|
2974
|
+
const KEYS = /* @__PURE__ */ new Set([
|
|
2975
|
+
"$schema",
|
|
2976
|
+
"command",
|
|
2977
|
+
"probes",
|
|
2978
|
+
"bare",
|
|
2979
|
+
"checks",
|
|
2980
|
+
"skip",
|
|
2981
|
+
"strict",
|
|
2982
|
+
"timeout",
|
|
2983
|
+
"accept"
|
|
2984
|
+
]);
|
|
2985
|
+
const ACCEPT_KEYS = /* @__PURE__ */ new Set([
|
|
2986
|
+
"check",
|
|
2987
|
+
"probe",
|
|
2988
|
+
"reason"
|
|
2989
|
+
]);
|
|
2990
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2991
|
+
const isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
2992
|
+
/** Reads a config file's text. Every problem is a usage error that names the key. */
|
|
2993
|
+
function parseConfig(text, path) {
|
|
2994
|
+
const bad = (message) => new UsageError(`${path}: ${message}`);
|
|
2995
|
+
let json;
|
|
2996
|
+
try {
|
|
2997
|
+
json = JSON.parse(text);
|
|
2998
|
+
} catch (error) {
|
|
2999
|
+
throw bad(`not valid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
3000
|
+
}
|
|
3001
|
+
if (!isObject(json)) throw bad("must hold a JSON object");
|
|
3002
|
+
const unknownKey = Object.keys(json).find((key) => !KEYS.has(key));
|
|
3003
|
+
if (unknownKey !== void 0) throw bad(`unknown key "${unknownKey}" (known: ${[...KEYS].slice(1).join(", ")})`);
|
|
3004
|
+
/** Arguments as a string, split like --probe, or as an array of strings, taken as they are. */
|
|
3005
|
+
const words = (value, key) => {
|
|
3006
|
+
if (isStrings(value)) return value;
|
|
3007
|
+
if (typeof value !== "string") throw bad(`"${key}" must be a string or an array of strings`);
|
|
3008
|
+
try {
|
|
3009
|
+
return shellSplit(value);
|
|
3010
|
+
} catch (error) {
|
|
3011
|
+
throw bad(`"${key}" ${error instanceof Error ? error.message : String(error)}`);
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
const flag = (key) => {
|
|
3015
|
+
const value = json[key];
|
|
3016
|
+
if (value === void 0) return false;
|
|
3017
|
+
if (typeof value !== "boolean") throw bad(`"${key}" must be true or false`);
|
|
3018
|
+
return value;
|
|
3019
|
+
};
|
|
3020
|
+
const names = (key) => {
|
|
3021
|
+
const value = json[key];
|
|
3022
|
+
if (value === void 0) return [];
|
|
3023
|
+
if (!isStrings(value)) throw bad(`"${key}" must be an array of check names`);
|
|
3024
|
+
return value;
|
|
3025
|
+
};
|
|
3026
|
+
const list = (key) => {
|
|
3027
|
+
const value = json[key];
|
|
3028
|
+
if (value === void 0) return [];
|
|
3029
|
+
if (!Array.isArray(value)) throw bad(`"${key}" must be an array`);
|
|
3030
|
+
return value;
|
|
3031
|
+
};
|
|
3032
|
+
if (json["command"] === void 0) throw bad("needs a \"command\", the program to probe");
|
|
3033
|
+
const command = words(json["command"], "command");
|
|
3034
|
+
if (command.length === 0 || command[0] === "") throw bad("\"command\" is empty");
|
|
3035
|
+
const probes = list("probes").map((probe, i) => {
|
|
3036
|
+
const args = words(probe, `probes[${i}]`);
|
|
3037
|
+
if (args.length === 0) throw bad(`"probes[${i}]" is empty; use "bare": true for no arguments`);
|
|
3038
|
+
return args;
|
|
3039
|
+
});
|
|
3040
|
+
const timeout = json["timeout"];
|
|
3041
|
+
if (timeout !== void 0 && (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout <= 0 || timeout > MAX_TIMEOUT_MS)) throw bad(`"timeout" must be a whole number of milliseconds from 1 to ${MAX_TIMEOUT_MS}`);
|
|
3042
|
+
const accept = list("accept").map((entry, i) => {
|
|
3043
|
+
const key = `accept[${i}]`;
|
|
3044
|
+
if (!isObject(entry)) throw bad(`"${key}" must be an object with "check" and "reason"`);
|
|
3045
|
+
const extra = Object.keys(entry).find((k) => !ACCEPT_KEYS.has(k));
|
|
3046
|
+
if (extra !== void 0) throw bad(`"${key}" has an unknown key "${extra}"`);
|
|
3047
|
+
const { check, reason, probe } = entry;
|
|
3048
|
+
if (typeof check !== "string" || check === "") throw bad(`"${key}" needs a "check" name`);
|
|
3049
|
+
if (typeof reason !== "string" || reason.trim() === "") throw bad(`"${key}" needs a "reason": say why the finding is accepted`);
|
|
3050
|
+
return {
|
|
3051
|
+
check,
|
|
3052
|
+
reason,
|
|
3053
|
+
...probe === void 0 ? {} : { probe: words(probe, `${key}.probe`) }
|
|
3054
|
+
};
|
|
3055
|
+
});
|
|
3056
|
+
return {
|
|
3057
|
+
command,
|
|
3058
|
+
probes,
|
|
3059
|
+
bare: flag("bare"),
|
|
3060
|
+
checks: names("checks"),
|
|
3061
|
+
skip: names("skip"),
|
|
3062
|
+
strict: flag("strict"),
|
|
3063
|
+
timeout,
|
|
3064
|
+
accept
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
/** Reads and parses a config file; a file that can't be read is a usage error too. */
|
|
3068
|
+
function loadConfig(path) {
|
|
3069
|
+
let text;
|
|
3070
|
+
try {
|
|
3071
|
+
text = readFileSync(path, "utf8");
|
|
3072
|
+
} catch (error) {
|
|
3073
|
+
throw new UsageError(`cannot read the config file ${path}: ${error instanceof Error && "code" in error && error.code === "ENOENT" ? "no such file" : error instanceof Error ? error.message : ""}`);
|
|
3074
|
+
}
|
|
3075
|
+
return parseConfig(text, path);
|
|
3076
|
+
}
|
|
2948
3077
|
// src/cli/help.ts
|
|
2949
3078
|
const HELP = `cliprobe ${VERSION}: test a command-line program for terminal-edge bugs
|
|
2950
3079
|
|
|
2951
3080
|
Usage:
|
|
2952
3081
|
cliprobe [options] -- <command> [args...]
|
|
3082
|
+
cliprobe [options] (reads cliprobe.config.json)
|
|
2953
3083
|
|
|
2954
3084
|
With no args after <command>, cliprobe probes "<command> --version" and
|
|
2955
3085
|
"<command> --help". With args, it probes exactly that invocation; with --bare,
|
|
@@ -3023,6 +3153,8 @@ Options:
|
|
|
3023
3153
|
variables and wildcards are not expanded. The args after
|
|
3024
3154
|
<command> are not kept, so name the script in each probe:
|
|
3025
3155
|
cliprobe --probe "./cli.js watch" -- node ./cli.js
|
|
3156
|
+
--config <path> Read this config file instead of cliprobe.config.json;
|
|
3157
|
+
give no command with it
|
|
3026
3158
|
--check <name> Run only this check; repeat it or use commas for several
|
|
3027
3159
|
--skip <name> Leave this check out; repeat it or use commas for several
|
|
3028
3160
|
--strict Exit 1 on a warning too, not only on a failure
|
|
@@ -3041,20 +3173,140 @@ Options:
|
|
|
3041
3173
|
-h, --help Show this help
|
|
3042
3174
|
-v, --version Show the version
|
|
3043
3175
|
|
|
3176
|
+
Config file: with no command, cliprobe reads cliprobe.config.json from the
|
|
3177
|
+
current directory, so a project's run is just "npx cliprobe":
|
|
3178
|
+
{
|
|
3179
|
+
"command": "node ./dist/cli.js",
|
|
3180
|
+
"probes": ["serve --port 0", "scan {fixture}"],
|
|
3181
|
+
"strict": true,
|
|
3182
|
+
"accept": [
|
|
3183
|
+
{ "check": "sigterm", "probe": "serve --port 0", "reason": "why" }
|
|
3184
|
+
]
|
|
3185
|
+
}
|
|
3186
|
+
"command" is the program, script included, so probes don't repeat it. Also
|
|
3187
|
+
"bare", "checks", "skip" and "timeout", as the options. "accept" lists known
|
|
3188
|
+
failures and warnings: each stays in the report with its reason but no longer
|
|
3189
|
+
changes the exit code; leave "probe" out to accept a check for every probe.
|
|
3190
|
+
Options add to the file: --probe and --skip join its lists, --check and
|
|
3191
|
+
--timeout replace its values.
|
|
3192
|
+
|
|
3044
3193
|
Exit codes: 0 no failures, 1 a check failed (or warned, with --strict), 2 usage
|
|
3045
|
-
error, could not run, or could not write the report
|
|
3194
|
+
error (or a bad config file), could not run, or could not write the report.
|
|
3046
3195
|
Runs the target in the current directory without a shell, with stdin closed
|
|
3047
3196
|
(the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
|
|
3048
3197
|
temporary HOME and a minimal environment. Only run programs you trust. When a
|
|
3049
3198
|
probe exits, or when cliprobe is stopped, it kills whatever the probe left
|
|
3050
3199
|
running and removes its temporary files.`;
|
|
3200
|
+
// src/cli/plan.ts
|
|
3201
|
+
const same = (a, b) => a.length === b.length && a.every((word, i) => word === b[i]);
|
|
3202
|
+
const shown = (args) => args.length ? `"${shellJoin(args)}"` : "the bare command";
|
|
3203
|
+
/** The plan for a command given on the command line; null when there is none. */
|
|
3204
|
+
function planFromArgs(opts) {
|
|
3205
|
+
if (opts.command === void 0) return null;
|
|
3206
|
+
const own = opts.bare || opts.args.length > 0;
|
|
3207
|
+
return {
|
|
3208
|
+
command: opts.command,
|
|
3209
|
+
programArgs: [],
|
|
3210
|
+
probes: [...mainProbe(opts).map((args) => ({
|
|
3211
|
+
args,
|
|
3212
|
+
own,
|
|
3213
|
+
...opts.bare ? { bare: true } : {}
|
|
3214
|
+
})), ...opts.probes.map((args) => ({
|
|
3215
|
+
args,
|
|
3216
|
+
own: true
|
|
3217
|
+
}))],
|
|
3218
|
+
checks: opts.checks,
|
|
3219
|
+
skip: opts.skip,
|
|
3220
|
+
strict: opts.strict,
|
|
3221
|
+
timeout: opts.timeout,
|
|
3222
|
+
accept: []
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
/**
|
|
3226
|
+
* The plan for a config file. The command line adds to it: its probes and skips
|
|
3227
|
+
* join the file's, --bare and --strict switch on what the file left off, and
|
|
3228
|
+
* --check and --timeout replace the file's.
|
|
3229
|
+
*/
|
|
3230
|
+
function planFromConfig(config, path, opts) {
|
|
3231
|
+
const bad = (message) => new UsageError(`${path}: ${message}`);
|
|
3232
|
+
const [command = "", ...programArgs] = config.command;
|
|
3233
|
+
const bare = opts.bare || config.bare;
|
|
3234
|
+
const probes = mainProbe({
|
|
3235
|
+
bare,
|
|
3236
|
+
args: []
|
|
3237
|
+
}).map((args) => ({
|
|
3238
|
+
args,
|
|
3239
|
+
own: bare,
|
|
3240
|
+
...bare ? { bare } : {}
|
|
3241
|
+
}));
|
|
3242
|
+
for (const args of [...config.probes, ...opts.probes]) {
|
|
3243
|
+
if (probes.some((p) => same(p.args, args))) throw bad(`the probe ${shown(args)} is given twice, or already runs`);
|
|
3244
|
+
probes.push({
|
|
3245
|
+
args,
|
|
3246
|
+
own: true
|
|
3247
|
+
});
|
|
3248
|
+
}
|
|
3249
|
+
const known = new Set(CHECKS.map((c) => c.name));
|
|
3250
|
+
for (const { check, probe } of config.accept) {
|
|
3251
|
+
if (!known.has(check)) throw bad(`"accept" names an unknown check "${check}" (available: ${[...known].join(", ")})`);
|
|
3252
|
+
if (probe !== void 0 && !probes.some((p) => same(p.args, probe))) {
|
|
3253
|
+
const running = probes.map((p) => shown(p.args)).join(", ");
|
|
3254
|
+
throw bad(`"accept" names ${shown(probe)}, which isn't a probe of this run (${running})`);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
return {
|
|
3258
|
+
command,
|
|
3259
|
+
programArgs,
|
|
3260
|
+
probes,
|
|
3261
|
+
checks: opts.checks.length ? opts.checks : config.checks,
|
|
3262
|
+
skip: [.../* @__PURE__ */ new Set([...config.skip, ...opts.skip])],
|
|
3263
|
+
strict: opts.strict || config.strict,
|
|
3264
|
+
timeout: opts.timeoutGiven ? opts.timeout : config.timeout ?? 15e3,
|
|
3265
|
+
accept: config.accept,
|
|
3266
|
+
configPath: path
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
/** Whether an accepted finding is this result: the same check and, when it names one, the same probe. */
|
|
3270
|
+
const matches = (accept, r, plan) => accept.check === r.check && (accept.probe === void 0 || same(r.invocation, [
|
|
3271
|
+
plan.command,
|
|
3272
|
+
...plan.programArgs,
|
|
3273
|
+
...accept.probe
|
|
3274
|
+
]));
|
|
3275
|
+
/**
|
|
3276
|
+
* Marks the failures and warnings the config accepts. A verdict never changes;
|
|
3277
|
+
* an accepted result only stops counting toward the exit code.
|
|
3278
|
+
*/
|
|
3279
|
+
function applyAccepts(results, plan) {
|
|
3280
|
+
const used = /* @__PURE__ */ new Set();
|
|
3281
|
+
return {
|
|
3282
|
+
results: results.map((r) => {
|
|
3283
|
+
if (r.verdict !== "fail" && r.verdict !== "warn") return r;
|
|
3284
|
+
const accept = plan.accept.find((a) => matches(a, r, plan));
|
|
3285
|
+
if (!accept) return r;
|
|
3286
|
+
used.add(accept);
|
|
3287
|
+
return {
|
|
3288
|
+
...r,
|
|
3289
|
+
accepted: { reason: accept.reason }
|
|
3290
|
+
};
|
|
3291
|
+
}),
|
|
3292
|
+
stale: plan.accept.filter((a) => {
|
|
3293
|
+
if (used.has(a)) return false;
|
|
3294
|
+
const own = results.filter((r) => matches(a, r, plan));
|
|
3295
|
+
return own.length > 0 && own.every((r) => r.verdict === "pass");
|
|
3296
|
+
})
|
|
3297
|
+
};
|
|
3298
|
+
}
|
|
3299
|
+
/** How a stale accepted finding is named in the note about it. */
|
|
3300
|
+
const describeAccept = ({ check, probe }) => probe === void 0 ? check : `${check} for ${shown(probe)}`;
|
|
3051
3301
|
// src/cli/program.ts
|
|
3052
3302
|
/**
|
|
3053
3303
|
* 0 no failures, 1 a check failed (or, with `strict`, warned), 2 nothing could be
|
|
3054
|
-
* judged because something could not run.
|
|
3304
|
+
* judged because something could not run. A failure or warning the config file
|
|
3305
|
+
* accepts doesn't count.
|
|
3055
3306
|
*/
|
|
3056
3307
|
function exitCodeFor(results, strict = false) {
|
|
3057
|
-
|
|
3308
|
+
const counts = (r) => !r.accepted && (r.verdict === "fail" || strict && r.verdict === "warn");
|
|
3309
|
+
if (results.some(counts)) return 1;
|
|
3058
3310
|
if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
|
|
3059
3311
|
return 0;
|
|
3060
3312
|
}
|
|
@@ -3078,7 +3330,21 @@ async function run(argv, io) {
|
|
|
3078
3330
|
out(VERSION + "\n");
|
|
3079
3331
|
return 0;
|
|
3080
3332
|
}
|
|
3081
|
-
|
|
3333
|
+
let plan;
|
|
3334
|
+
try {
|
|
3335
|
+
plan = planFromArgs(opts);
|
|
3336
|
+
const path = opts.config ?? (plan === null && existsSync("cliprobe.config.json") ? "cliprobe.config.json" : null);
|
|
3337
|
+
if (path !== null) plan = planFromConfig(loadConfig(path), path, opts);
|
|
3338
|
+
} catch (error) {
|
|
3339
|
+
if (!(error instanceof UsageError)) throw error;
|
|
3340
|
+
err(`cliprobe: ${safe(error.message)}\n`);
|
|
3341
|
+
return 2;
|
|
3342
|
+
}
|
|
3343
|
+
if (plan === null) {
|
|
3344
|
+
err(`cliprobe: no command given, and no ${CONFIG_FILE} in this directory\nUsage: cliprobe [options] -- <command> [args...]\n`);
|
|
3345
|
+
return 2;
|
|
3346
|
+
}
|
|
3347
|
+
const { checks, unknown } = selectChecks(plan.checks, plan.skip);
|
|
3082
3348
|
if (unknown.length) {
|
|
3083
3349
|
const available = CHECKS.map((c) => c.name).join(", ");
|
|
3084
3350
|
err(`cliprobe: unknown check ${unknown.map((n) => `"${n}"`).join(", ")} (available: ${available})\n`);
|
|
@@ -3088,15 +3354,11 @@ async function run(argv, io) {
|
|
|
3088
3354
|
err("cliprobe: --skip leaves no check to run\n");
|
|
3089
3355
|
return 2;
|
|
3090
3356
|
}
|
|
3091
|
-
if (!opts.command) {
|
|
3092
|
-
err("cliprobe: no command given\nUsage: cliprobe [options] -- <command> [args...]\n");
|
|
3093
|
-
return 2;
|
|
3094
|
-
}
|
|
3095
3357
|
if (io.platform === "win32") {
|
|
3096
3358
|
err("cliprobe: Windows is not supported yet (the closed-pipe check needs mkfifo).\n");
|
|
3097
3359
|
return 2;
|
|
3098
3360
|
}
|
|
3099
|
-
const problem = commandProblem(
|
|
3361
|
+
const problem = commandProblem(plan.command);
|
|
3100
3362
|
if (problem !== void 0) {
|
|
3101
3363
|
err(`cliprobe: ${safe(problem)}\n`);
|
|
3102
3364
|
return 2;
|
|
@@ -3106,20 +3368,17 @@ async function run(argv, io) {
|
|
|
3106
3368
|
err(`cliprobe: cannot write the report to ${safe(opts.outputFile ?? "")}: ${safe(pathProblem)}\n`);
|
|
3107
3369
|
return 2;
|
|
3108
3370
|
}
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
args,
|
|
3112
|
-
|
|
3113
|
-
})), ...opts.probes.map((args) => ({
|
|
3114
|
-
args,
|
|
3115
|
-
own: true
|
|
3116
|
-
}))];
|
|
3371
|
+
const probes = plan.probes.map((p) => ({
|
|
3372
|
+
...p,
|
|
3373
|
+
args: [...plan.programArgs, ...p.args]
|
|
3374
|
+
}));
|
|
3117
3375
|
const fixture = probes.some((p) => usesFixture(p.args)) ? createFixture() : void 0;
|
|
3118
3376
|
const unregister = fixture && onInterrupt(() => fixture.cleanup());
|
|
3119
3377
|
const results = [];
|
|
3120
3378
|
try {
|
|
3121
3379
|
const target = {
|
|
3122
|
-
command:
|
|
3380
|
+
command: plan.command,
|
|
3381
|
+
...plan.programArgs.length ? { programArgs: plan.programArgs } : {},
|
|
3123
3382
|
probes: fixture ? probes.map((p) => ({
|
|
3124
3383
|
...p,
|
|
3125
3384
|
args: expandFixture(p.args, fixture.dir)
|
|
@@ -3127,7 +3386,7 @@ async function run(argv, io) {
|
|
|
3127
3386
|
...fixture ? { fixtureDir: fixture.dir } : {}
|
|
3128
3387
|
};
|
|
3129
3388
|
const ctx = {
|
|
3130
|
-
timeout:
|
|
3389
|
+
timeout: plan.timeout,
|
|
3131
3390
|
longRunning: /* @__PURE__ */ new Set()
|
|
3132
3391
|
};
|
|
3133
3392
|
for (const check of checks) results.push(...await check.run(target, ctx));
|
|
@@ -3135,12 +3394,13 @@ async function run(argv, io) {
|
|
|
3135
3394
|
unregister?.();
|
|
3136
3395
|
fixture?.cleanup();
|
|
3137
3396
|
}
|
|
3397
|
+
const accepted = applyAccepts(fixture ? collapseResults(results, fixture) : results, plan);
|
|
3138
3398
|
const report = {
|
|
3139
3399
|
version: VERSION,
|
|
3140
|
-
command:
|
|
3400
|
+
command: plan.command,
|
|
3141
3401
|
checks: checks.map((c) => c.name),
|
|
3142
|
-
strict:
|
|
3143
|
-
results:
|
|
3402
|
+
strict: plan.strict,
|
|
3403
|
+
results: accepted.results
|
|
3144
3404
|
};
|
|
3145
3405
|
const { color } = io;
|
|
3146
3406
|
if (opts.outputFile) {
|
|
@@ -3156,7 +3416,8 @@ async function run(argv, io) {
|
|
|
3156
3416
|
return 2;
|
|
3157
3417
|
}
|
|
3158
3418
|
} else out(FORMATS[opts.format](report, { color }));
|
|
3159
|
-
|
|
3419
|
+
for (const stale of accepted.stale) err(`cliprobe: ${safe(plan.configPath ?? "cliprobe.config.json")} accepts ${safe(describeAccept(stale))}, which passed: remove it from "accept"\n`);
|
|
3420
|
+
return exitCodeFor(report.results, plan.strict);
|
|
3160
3421
|
}
|
|
3161
3422
|
// src/cli/main.ts
|
|
3162
3423
|
process.stdout.on("error", (error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), output lost on a full disk while exiting 0, 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
|
@@ -132,6 +132,17 @@
|
|
|
132
132
|
"type": "string",
|
|
133
133
|
"description": "The line that led to the verdict, escaped; absent when there is none."
|
|
134
134
|
},
|
|
135
|
+
"accepted": {
|
|
136
|
+
"type": "object",
|
|
137
|
+
"description": "Present when the config file accepts this fail or warn: the verdict stays, but the result doesn't count toward the exit code. Added in 1.8.",
|
|
138
|
+
"required": ["reason"],
|
|
139
|
+
"properties": {
|
|
140
|
+
"reason": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"description": "Why the project accepts it, from the config file."
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
135
146
|
"details": {
|
|
136
147
|
"type": "object",
|
|
137
148
|
"description": "The check's own measurements, described by $defs/details.<check>."
|