cliprobe 1.8.1 → 1.10.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 +62 -4
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +24 -3000
- package/dist/index.d.ts +323 -0
- package/dist/index.js +108 -0
- package/dist/report-DuFcZAqG.js +3137 -0
- package/package.json +10 -2
- package/schema.json +1 -1
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ The other checks cover the rest of what goes wrong between a program and the thi
|
|
|
96
96
|
- [Exit codes](#exit-codes)
|
|
97
97
|
- [In CI](#in-ci)
|
|
98
98
|
- [JSON output](#json-output)
|
|
99
|
+
- [In your test suite](#in-your-test-suite)
|
|
99
100
|
- [Stability](#stability)
|
|
100
101
|
- [Checks](#checks): [closed-pipe](#closed-pipe), [write-error](#write-error), [color](#color), [pipe-escapes](#pipe-escapes), [stdin](#stdin), [ctrl-c](#ctrl-c), [sigterm](#sigterm), [restore](#restore), [control-chars](#control-chars), [info checks](#info-checks)
|
|
101
102
|
- [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
|
|
@@ -115,7 +116,7 @@ Run it without installing:
|
|
|
115
116
|
npx cliprobe -- <command>
|
|
116
117
|
```
|
|
117
118
|
|
|
118
|
-
Or add it to a project, to run in CI against your own CLI:
|
|
119
|
+
Or add it to a project, to run in CI against your own CLI or [from its test suite](#in-your-test-suite):
|
|
119
120
|
|
|
120
121
|
```sh
|
|
121
122
|
npm install --save-dev cliprobe # or: pnpm add -D cliprobe
|
|
@@ -130,6 +131,7 @@ npx cliprobe --probe "watch app.ts" -- tsx # adds a probe: --version, --help a
|
|
|
130
131
|
npx cliprobe -- node ./dist/cli.js list # test your own CLI before publishing
|
|
131
132
|
npx cliprobe --json -- <command> # machine-readable results
|
|
132
133
|
npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; human report on stdout
|
|
134
|
+
npx cliprobe --format github -- <command> # in GitHub Actions: the report, plus an annotation per finding
|
|
133
135
|
npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
|
|
134
136
|
npx cliprobe --bare -- htop # the command alone: a REPL, a full-screen program, a server
|
|
135
137
|
npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
|
|
@@ -145,7 +147,7 @@ npx cliprobe # no command: the run in cliprobe.conf
|
|
|
145
147
|
| `--check <name>` | Run only this check; repeat it or use commas for several |
|
|
146
148
|
| `--skip <name>` | Leave this check out; repeat it or use commas for several |
|
|
147
149
|
| `--strict` | Exit 1 on a warning too, not only on a failure |
|
|
148
|
-
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment)
|
|
150
|
+
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment), `junit` (XML for CI test reports) or `github` (the human report, then an annotation for each failure and warning, for a GitHub Actions step) |
|
|
149
151
|
| `--json` | Same as `--format json` |
|
|
150
152
|
| `-o`, `--output-file <path>` | Write the `--format` report to a file (replaced atomically, keeping its mode and following symlinks, with parent folders created; a FIFO, `/dev/stdout` or `/dev/fd/N` is written in place); the human report still prints. For a path that starts with `-`, write `-o=<path>` or `./<path>` |
|
|
151
153
|
| `--timeout <ms>` | Kill a probe after this long (default 15000, at most 2147483647, about 24 days); a command still running then is judged on what it did so far |
|
|
@@ -184,6 +186,7 @@ npx cliprobe # with no command, reads cliprobe.config.json from the current d
|
|
|
184
186
|
| `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
187
|
| `probes` | More invocations, each the arguments after the program, as `--probe` |
|
|
186
188
|
| `bare` | `true` probes the program alone instead of `--version` and `--help`, as `--bare` |
|
|
189
|
+
| `defaultProbes` | `false` leaves out `--version` and `--help`, so only `probes` run |
|
|
187
190
|
| `checks`, `skip` | Arrays of check names, as `--check` and `--skip` |
|
|
188
191
|
| `strict`, `timeout` | As `--strict` and `--timeout` |
|
|
189
192
|
| `accept` | Failures and warnings the project knows about; see below |
|
|
@@ -229,6 +232,15 @@ A failed check exits 1, so the step fails. Warnings don't fail it unless you add
|
|
|
229
232
|
run: npx --yes cliprobe@1 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
|
|
230
233
|
```
|
|
231
234
|
|
|
235
|
+
To see each finding on the workflow run and on the pull request's checks, without opening the log, use `--format github`. It prints the human report, then a GitHub annotation for every result that needs attention: an error for a `FAIL` or could-not-run (and for a `WARN` under `--strict`), a warning for a `WARN`, and a notice for a finding the [config file accepts](#accepted-findings).
|
|
236
|
+
|
|
237
|
+
```yaml
|
|
238
|
+
- name: Check the CLI for terminal-edge bugs
|
|
239
|
+
run: npx --yes "cliprobe@^1.9" --format github -- node ./dist/cli.js
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
The report quotes the program under test, and GitHub reads a workflow command from any log line that starts with `::`. So cliprobe prints the report with command processing stopped (`::stop-commands::`) behind a random token, and escapes every annotation onto one line: a program can't use cliprobe's output to forge an annotation or run another workflow command.
|
|
243
|
+
|
|
232
244
|
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
245
|
|
|
234
246
|
```yaml
|
|
@@ -250,7 +262,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
250
262
|
|
|
251
263
|
## JSON output
|
|
252
264
|
|
|
253
|
-
`--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json
|
|
265
|
+
`--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`. [`probe()`](#in-your-test-suite) returns the same report as an object:
|
|
254
266
|
|
|
255
267
|
```json
|
|
256
268
|
{
|
|
@@ -282,6 +294,49 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
282
294
|
|
|
283
295
|
`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.
|
|
284
296
|
|
|
297
|
+
## In your test suite
|
|
298
|
+
|
|
299
|
+
cliprobe is also a library: `probe()` runs the checks and returns the report as an object, so your own tests can hold your CLI to them. It works with any test runner; with Vitest:
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
import { expect, test } from 'vitest';
|
|
303
|
+
import { failing, formatReport, probe } from 'cliprobe';
|
|
304
|
+
|
|
305
|
+
test('the CLI behaves in pipes, on Ctrl-C and on a full disk', async () => {
|
|
306
|
+
const report = await probe('node ./dist/cli.js', {
|
|
307
|
+
probes: ['serve --port 0', 'scan {fixture}'],
|
|
308
|
+
});
|
|
309
|
+
// On a failure, the message is the report a person would read.
|
|
310
|
+
expect(failing(report), formatReport(report)).toEqual([]);
|
|
311
|
+
}, 120_000);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
`probe(command, options)` takes the program as the [config file](#config-file) does: `command` is all of it, script included, as a string or an array, and the options are the file's other keys (`probes`, `bare`, `defaultProbes`, `checks`, `skip`, `strict`, `timeout`, `accept`). It resolves to the same report as [`--format json`](#json-output), with TypeScript types: `result.check` narrows `result.details` to that check's fields.
|
|
315
|
+
|
|
316
|
+
| Export | What it does |
|
|
317
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
318
|
+
| `probe(command, options?)` | Runs the checks and resolves to the report. A check that fails is a result, never an exception |
|
|
319
|
+
| `failing(report)` | The results that fail the run: every `fail`, plus every `warn` with `strict`, except those `accept` covers |
|
|
320
|
+
| `exitCode(report)` | `0`, `1` or `2`, as the CLI would exit |
|
|
321
|
+
| `formatReport(report, format?)` | The report as text: `human` (default), `json`, `markdown`, `junit` or `github`, escaped as in the CLI. `{ color: true }` paints the verdicts |
|
|
322
|
+
| `readConfig(path?)` | Reads `cliprobe.config.json`, so a test probes exactly what `npx cliprobe` does: `const { command, ...options } = readConfig()` |
|
|
323
|
+
| `ProbeError` | What `probe()` rejects with when the run can't start; its `code` is `USAGE`, `COMMAND` or `PLATFORM` |
|
|
324
|
+
| `CHECK_NAMES`, `FORMAT_NAMES`, `version` | The check names in run order, the format names, and the cliprobe version |
|
|
325
|
+
|
|
326
|
+
To assert on one check, read the results; the verdict and the check name are stable, the wording of `reason` is not:
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
const report = await probe('node ./dist/cli.js', { checks: ['closed-pipe'] });
|
|
330
|
+
expect(report.results.map((r) => r.verdict)).toEqual(['pass', 'pass']);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
A few things to know:
|
|
334
|
+
|
|
335
|
+
- **Give the test time.** A probe that keeps running costs a few seconds in each check, so a full run takes from a few seconds to a minute or more. `checks` and `defaultProbes: false` keep a test to exactly what it asserts.
|
|
336
|
+
- **Run probes one after another.** The checks measure time, so several `probe()` calls at once on a busy machine can turn a slow answer into a wrong verdict.
|
|
337
|
+
- **It is the same run as the CLI.** The program starts in the current directory, without a shell, with a temporary `HOME` and [a minimal environment](#the-probes-environment), and anything it leaves running is killed. If the test process exits early, cliprobe kills the probe in progress and removes its temporary files on the way out.
|
|
338
|
+
- **Importing it does nothing.** No output, no signal handlers, no work until `probe()` is called. The package is ESM with types included and no dependencies; `require('cliprobe')` works too.
|
|
339
|
+
|
|
285
340
|
## Stability
|
|
286
341
|
|
|
287
342
|
From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
|
|
@@ -290,7 +345,8 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
|
|
|
290
345
|
- **Names and exit codes.** Check names, verdicts, options, config file keys and exit codes stay as they are.
|
|
291
346
|
- **`--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.
|
|
292
347
|
- **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
|
|
293
|
-
- **
|
|
348
|
+
- **The API.** The functions `cliprobe` exports, their options and the report they return follow the same rules: they are only added to.
|
|
349
|
+
- **Not covered.** The wording of `reason` and `evidence`, and the human, Markdown and `github` output, are for people and may change. Match on `check` and `verdict`, not on text.
|
|
294
350
|
|
|
295
351
|
## Checks
|
|
296
352
|
|
|
@@ -570,6 +626,8 @@ The runs under a terminal are color's second and third, restore's, and control-c
|
|
|
570
626
|
|
|
571
627
|
**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
628
|
|
|
629
|
+
**Can I run it from my own tests?** Yes: [`probe()`](#in-your-test-suite) returns the report as an object, with helpers to list what fails and to print it.
|
|
630
|
+
|
|
573
631
|
**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.
|
|
574
632
|
|
|
575
633
|
**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.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|