cliprobe 1.8.1 → 1.9.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.
Files changed (3) hide show
  1. package/README.md +12 -2
  2. package/dist/cli.js +56 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -130,6 +130,7 @@ npx cliprobe --probe "watch app.ts" -- tsx # adds a probe: --version, --help a
130
130
  npx cliprobe -- node ./dist/cli.js list # test your own CLI before publishing
131
131
  npx cliprobe --json -- <command> # machine-readable results
132
132
  npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; human report on stdout
133
+ npx cliprobe --format github -- <command> # in GitHub Actions: the report, plus an annotation per finding
133
134
  npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
134
135
  npx cliprobe --bare -- htop # the command alone: a REPL, a full-screen program, a server
135
136
  npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
@@ -145,7 +146,7 @@ npx cliprobe # no command: the run in cliprobe.conf
145
146
  | `--check <name>` | Run only this check; repeat it or use commas for several |
146
147
  | `--skip <name>` | Leave this check out; repeat it or use commas for several |
147
148
  | `--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) or `junit` (XML for CI test reports) |
149
+ | `--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
150
  | `--json` | Same as `--format json` |
150
151
  | `-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
152
  | `--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 |
@@ -229,6 +230,15 @@ A failed check exits 1, so the step fails. Warnings don't fail it unless you add
229
230
  run: npx --yes cliprobe@1 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
230
231
  ```
231
232
 
233
+ 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).
234
+
235
+ ```yaml
236
+ - name: Check the CLI for terminal-edge bugs
237
+ run: npx --yes "cliprobe@^1.9" --format github -- node ./dist/cli.js
238
+ ```
239
+
240
+ 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.
241
+
232
242
  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
243
 
234
244
  ```yaml
@@ -290,7 +300,7 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
290
300
  - **Names and exit codes.** Check names, verdicts, options, config file keys and exit codes stay as they are.
291
301
  - **`--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
302
  - **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
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.
303
+ - **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
304
 
295
305
  ## Checks
296
306
 
package/dist/cli.js CHANGED
@@ -4,6 +4,7 @@ import { execFile, execFileSync, spawn } from "node:child_process";
4
4
  import { accessSync, closeSync, constants, existsSync, lstatSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
5
5
  import { delimiter, dirname, join, resolve, sep } from "node:path";
6
6
  import { tmpdir } from "node:os";
7
+ import { randomUUID } from "node:crypto";
7
8
  import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
8
9
  // src/core/interrupt.ts
9
10
  const cleanups = /* @__PURE__ */ new Set();
@@ -2560,6 +2561,54 @@ function formatHuman({ version, command, checks, strict, results }, { color }) {
2560
2561
  lines.push("", summaryLine(countVerdicts(results), strict, countAccepted(results)));
2561
2562
  return lines.join("\n") + "\n";
2562
2563
  }
2564
+ // src/report/github.ts
2565
+ /** The text of a workflow command: GitHub reads `%0A` back as a line break. */
2566
+ const commandData = (text) => text.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
2567
+ /** A workflow command's property value, where `:` and `,` also end something. */
2568
+ const commandProperty = (text) => commandData(text).replaceAll(":", "%3A").replaceAll(",", "%2C");
2569
+ /**
2570
+ * The annotation level for a result, if it gets one: an error for what fails
2571
+ * the step (a failure, could-not-run, a warning under --strict), a warning for
2572
+ * other warnings, and a notice for a finding the config file accepts.
2573
+ */
2574
+ function annotationLevel(r, strict) {
2575
+ if (r.verdict === "error") return "error";
2576
+ if (r.verdict !== "fail" && r.verdict !== "warn") return null;
2577
+ if (r.accepted) return "notice";
2578
+ return r.verdict === "fail" || strict ? "error" : "warning";
2579
+ }
2580
+ function annotation(r, strict) {
2581
+ const level = annotationLevel(r, strict);
2582
+ if (level === null) return null;
2583
+ const title = `cliprobe ${r.check}: ${safe(shellJoin(r.invocation))}`;
2584
+ const lines = [
2585
+ safe(r.reason),
2586
+ ...r.evidence ? [showEvidence(r.evidence)] : [],
2587
+ ...r.accepted ? [`accepted: ${safe(r.accepted.reason)}`] : []
2588
+ ];
2589
+ return `::${level} title=${commandProperty(title)}::${commandData(lines.join("\n"))}`;
2590
+ }
2591
+ /**
2592
+ * For a GitHub Actions step: the human report for the log, then one workflow
2593
+ * command per finding, which GitHub shows as an annotation on the run and on the
2594
+ * pull request's checks.
2595
+ *
2596
+ * The report quotes the program under test, and GitHub reads a workflow command
2597
+ * from any log line that starts with `::`, even an indented one. So the report
2598
+ * is printed with command processing stopped, behind a token made after the
2599
+ * program ran, which it therefore can't know and can't use to switch it back on.
2600
+ */
2601
+ function formatGithub(report) {
2602
+ const token = randomUUID();
2603
+ const annotations = report.results.map((r) => annotation(r, report.strict)).filter((line) => line !== null);
2604
+ return [
2605
+ `::stop-commands::${token}`,
2606
+ formatHuman(report, { color: false }).trimEnd(),
2607
+ `::${token}::`,
2608
+ ...annotations,
2609
+ ""
2610
+ ].join("\n");
2611
+ }
2563
2612
  /**
2564
2613
  * The report as JSON. Each result keeps the fields every check shares at the top
2565
2614
  * and moves the check's own measurements into `details`.
@@ -2687,7 +2736,8 @@ const FORMAT_NAMES = [
2687
2736
  "human",
2688
2737
  "json",
2689
2738
  "markdown",
2690
- "junit"
2739
+ "junit",
2740
+ "github"
2691
2741
  ];
2692
2742
  function isFormat(name) {
2693
2743
  return FORMAT_NAMES.includes(name);
@@ -2697,7 +2747,8 @@ const FORMATS = {
2697
2747
  human: formatHuman,
2698
2748
  json: formatJson,
2699
2749
  markdown: formatMarkdown,
2700
- junit: formatJunit
2750
+ junit: formatJunit,
2751
+ github: formatGithub
2701
2752
  };
2702
2753
  // src/report/write.ts
2703
2754
  /** Why a report can't be written to a path, in words for the person who gave it. */
@@ -3159,7 +3210,9 @@ Options:
3159
3210
  --skip <name> Leave this check out; repeat it or use commas for several
3160
3211
  --strict Exit 1 on a warning too, not only on a failure
3161
3212
  --format <name> Output format: human (default), json, markdown (a CI job
3162
- summary or PR comment) or junit (XML for CI test reports)
3213
+ summary or PR comment), junit (XML for CI test reports)
3214
+ or github (the human report, then an annotation for each
3215
+ failure and warning, for a GitHub Actions step)
3163
3216
  --json Same as --format json
3164
3217
  -o, --output-file <path>
3165
3218
  Write the --format report to a file (replaced atomically,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
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": {