cliprobe 0.10.0 → 1.1.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 CHANGED
@@ -31,7 +31,7 @@ npx cliprobe -- esbuild
31
31
  ```
32
32
 
33
33
  ```
34
- cliprobe 0.10.0: closed-pipe, color, pipe-escapes, stdin, ctrl-c, sigterm, restore, control-chars checks for esbuild
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)
@@ -87,6 +87,8 @@ The other checks cover the rest of what goes wrong between a program and the thi
87
87
  - [Usage](#usage)
88
88
  - [Exit codes](#exit-codes)
89
89
  - [In CI](#in-ci)
90
+ - [JSON output](#json-output)
91
+ - [Stability](#stability)
90
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)
91
93
  - [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
92
94
  - [Safety](#safety)
@@ -118,12 +120,15 @@ npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; hu
118
120
  npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
119
121
  npx cliprobe --bare -- htop # the command alone: a REPL, a full-screen program, a server
120
122
  npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
123
+ npx cliprobe --strict --skip restore -- node ./dist/cli.js server # warnings fail too, except restore's
121
124
  ```
122
125
 
123
126
  | Option | Meaning |
124
127
  | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
125
128
  | `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
126
129
  | `--check <name>` | Run only this check; repeat it or use commas for several |
130
+ | `--skip <name>` | Leave this check out; repeat it or use commas for several |
131
+ | `--strict` | Exit 1 on a warning too, not only on a failure |
127
132
  | `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports) |
128
133
  | `--json` | Same as `--format json` |
129
134
  | `-o`, `--output-file <path>` | Write the `--format` report to a file (atomically, creating parent folders); the human report still prints |
@@ -136,24 +141,24 @@ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, onl
136
141
  | Code | Meaning |
137
142
  | ---- | ----------------------------------------- |
138
143
  | `0` | No check failed |
139
- | `1` | A check failed |
144
+ | `1` | A check failed, or warned with `--strict` |
140
145
  | `2` | Usage error, or the command could not run |
141
146
 
142
147
  A command that isn't on `PATH` is reported once, before any check runs, with exit `2` and no report. That makes cliprobe usable as a CI gate.
143
148
 
144
149
  ## In CI
145
150
 
146
- A failed check exits 1, so the step fails. In GitHub Actions, write a Markdown report to the job summary while the log keeps the human report:
151
+ A failed check exits 1, so the step fails. Warnings don't fail it unless you add `--strict`; with `--strict`, `--skip` leaves out a check whose warning you accept. In GitHub Actions, write a Markdown report to the job summary while the log keeps the human report:
147
152
 
148
153
  ```yaml
149
154
  - name: Check the CLI for terminal-edge bugs
150
- run: npx --yes cliprobe@0 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
155
+ run: npx --yes cliprobe@1 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
151
156
  ```
152
157
 
153
158
  For CI systems that read test results, write JUnit XML instead and keep it even when the step fails:
154
159
 
155
160
  ```yaml
156
- - run: npx --yes cliprobe@0 --format junit --output-file reports/cliprobe.xml -- node ./dist/cli.js
161
+ - run: npx --yes cliprobe@1 --format junit --output-file reports/cliprobe.xml -- node ./dist/cli.js
157
162
  - uses: actions/upload-artifact@v7
158
163
  if: always()
159
164
  with:
@@ -163,6 +168,49 @@ For CI systems that read test results, write JUnit XML instead and keep it even
163
168
 
164
169
  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.
165
170
 
171
+ ## JSON output
172
+
173
+ `--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`:
174
+
175
+ ```json
176
+ {
177
+ "tool": "cliprobe",
178
+ "schemaVersion": 1,
179
+ "version": "1.0.0",
180
+ "command": "node",
181
+ "checks": ["ctrl-c"],
182
+ "strict": false,
183
+ "summary": { "pass": 0, "fail": 1, "warn": 0, "skip": 0, "error": 0, "info": 0 },
184
+ "results": [
185
+ {
186
+ "check": "ctrl-c",
187
+ "invocation": ["node", "server.js"],
188
+ "verdict": "fail",
189
+ "reason": "ignored Ctrl-C: still running 3 s later",
190
+ "details": {
191
+ "sentAfterMs": 1003,
192
+ "exitedAfterMs": null,
193
+ "exitCode": null,
194
+ "signal": "SIGKILL",
195
+ "stderrAfter": ""
196
+ }
197
+ }
198
+ ]
199
+ }
200
+ ```
201
+
202
+ `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.
203
+
204
+ ## Stability
205
+
206
+ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
207
+
208
+ - **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.
209
+ - **Names and exit codes.** Check names, verdicts, options and exit codes stay as they are.
210
+ - **`--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.1.0`) if that matters, or `--skip` the check.
211
+ - **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
212
+ - **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.
213
+
166
214
  ## Checks
167
215
 
168
216
  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`.
@@ -269,7 +317,7 @@ Put `{fixture}` in the arguments where your command takes a path, for example `n
269
317
  | `WARN` | Printed a C1 control, carriage return or newline from a file name unescaped, which can hide or forge output |
270
318
  | `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` |
271
319
 
272
- 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.
320
+ 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.
273
321
 
274
322
  ### Info checks
275
323
 
package/dist/cli.js CHANGED
@@ -1787,19 +1787,15 @@ const CHECKS = [
1787
1787
  baselineCheck
1788
1788
  ];
1789
1789
  /**
1790
- * Picks checks by name, keeping registry order. No names selects every check of
1791
- * kind "check": info checks only run when named, because they never fail and
1792
- * baseline sends a flag the user did not ask for.
1790
+ * Picks checks by name, keeping registry order, then leaves out those in `skip`.
1791
+ * No names selects every check of kind "check": info checks only run when named,
1792
+ * because they never fail and baseline sends a flag the user did not ask for.
1793
1793
  */
1794
- function selectChecks(names) {
1795
- if (names.length === 0) return {
1796
- checks: CHECKS.filter((c) => c.kind === "check"),
1797
- unknown: []
1798
- };
1794
+ function selectChecks(names, skip = []) {
1799
1795
  const known = new Set(CHECKS.map((c) => c.name));
1800
1796
  return {
1801
- checks: CHECKS.filter((c) => names.includes(c.name)),
1802
- unknown: [...new Set(names.filter((n) => !known.has(n)))]
1797
+ checks: (names.length === 0 ? CHECKS.filter((c) => c.kind === "check") : CHECKS.filter((c) => names.includes(c.name))).filter((c) => !skip.includes(c.name)),
1798
+ unknown: [...new Set([...names, ...skip].filter((n) => !known.has(n)))]
1803
1799
  };
1804
1800
  }
1805
1801
  // src/core/safe.ts
@@ -1848,11 +1844,15 @@ function countVerdicts(results) {
1848
1844
  for (const r of results) counts[r.verdict]++;
1849
1845
  return counts;
1850
1846
  }
1851
- /** "2 failed, 0 warned, 2 passed, 2 skipped", plus info and could-not-run when present. */
1852
- function summaryLine(c) {
1847
+ /**
1848
+ * "2 failed, 0 warned, 2 passed, 2 skipped", plus info and could-not-run when
1849
+ * present, and a note when --strict makes warnings fail.
1850
+ */
1851
+ function summaryLine(c, strict = false) {
1853
1852
  const info = c.info ? `, ${c.info} info` : "";
1854
1853
  const errors = c.error ? `, ${c.error} could not run` : "";
1855
- return `${c.fail} failed, ${c.warn} warned, ${c.pass} passed, ${c.skip} skipped${info}${errors}`;
1854
+ const mode = strict ? " (--strict: warnings fail)" : "";
1855
+ return `${c.fail} failed, ${c.warn} warned, ${c.pass} passed, ${c.skip} skipped${info}${errors}${mode}`;
1856
1856
  }
1857
1857
  // src/report/human.ts
1858
1858
  const COLORS = {
@@ -1863,7 +1863,7 @@ const COLORS = {
1863
1863
  error: 35,
1864
1864
  info: 36
1865
1865
  };
1866
- function formatHuman({ version, command, checks, results }, { color }) {
1866
+ function formatHuman({ version, command, checks, strict, results }, { color }) {
1867
1867
  const paint = (verdict) => {
1868
1868
  const label = verdict.toUpperCase().padEnd(5);
1869
1869
  return color ? `\x1b[${COLORS[verdict]}m${label}\x1b[0m` : label;
@@ -1879,17 +1879,30 @@ function formatHuman({ version, command, checks, results }, { color }) {
1879
1879
  if (r.evidence) lines.push(` ${" ".repeat(5)} ${" ".repeat(width)} ${safe(r.evidence).slice(0, 200)}`);
1880
1880
  }
1881
1881
  }
1882
- lines.push("", summaryLine(countVerdicts(results)));
1882
+ lines.push("", summaryLine(countVerdicts(results), strict));
1883
1883
  return lines.join("\n") + "\n";
1884
1884
  }
1885
- // src/report/json.ts
1886
- function formatJson({ version, command, checks, results }) {
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
+ */
1889
+ function formatJson({ version, command, checks, strict, results }) {
1887
1890
  return safeJson({
1888
1891
  tool: "cliprobe",
1892
+ schemaVersion: 1,
1889
1893
  version,
1890
1894
  command,
1891
1895
  checks,
1892
- results
1896
+ strict,
1897
+ summary: countVerdicts(results),
1898
+ results: results.map(({ check, invocation, verdict, reason, evidence, ...details }) => ({
1899
+ check,
1900
+ invocation,
1901
+ verdict,
1902
+ reason,
1903
+ ...evidence === void 0 ? {} : { evidence },
1904
+ details
1905
+ }))
1893
1906
  }) + "\n";
1894
1907
  }
1895
1908
  // src/report/junit.ts
@@ -1908,37 +1921,35 @@ const XML_ESCAPES = {
1908
1921
  function xml(text) {
1909
1922
  return safe(text).replace(/[&<>"']/g, (c) => XML_ESCAPES[c] ?? c);
1910
1923
  }
1911
- /** JUnit's count attributes for a suite or the whole run. */
1912
- function totals(results) {
1924
+ /** JUnit's count attributes for a suite or the whole run; with --strict, warnings are failures. */
1925
+ function totals(results, strict) {
1913
1926
  const c = countVerdicts(results);
1914
- return `tests="${results.length}" failures="${c.fail}" errors="${c.error}" skipped="${c.skip}"`;
1927
+ const failures = c.fail + (strict ? c.warn : 0);
1928
+ return `tests="${results.length}" failures="${failures}" errors="${c.error}" skipped="${c.skip}"`;
1915
1929
  }
1916
- function testcase(r) {
1930
+ function testcase(r, strict) {
1917
1931
  const open = ` <testcase classname="cliprobe.${xml(r.check)}" name="${xml(shellJoin(r.invocation))}"`;
1918
1932
  const message = `message="${xml(r.reason)}"`;
1919
1933
  const body = r.evidence ? xml(r.evidence) : "";
1920
- switch (r.verdict) {
1921
- case "fail": return `${open}>\n <failure ${message} type="fail">${body}</failure>\n </testcase>`;
1922
- case "error": return `${open}>\n <error ${message} type="error">${body}</error>\n </testcase>`;
1923
- case "skip": return `${open}>\n <skipped ${message}/>\n </testcase>`;
1924
- case "pass":
1925
- case "warn":
1926
- case "info": return `${open}>\n <system-out>${`${r.verdict.toUpperCase()}: ${xml(r.reason)}${r.evidence ? `\n${body}` : ""}`}</system-out>\n </testcase>`;
1927
- }
1934
+ const failure = (type) => `${open}>\n <failure ${message} type="${type}">${body}</failure>\n </testcase>`;
1935
+ if (r.verdict === "fail" || strict && r.verdict === "warn") return failure(r.verdict);
1936
+ if (r.verdict === "error") return `${open}>\n <error ${message} type="error">${body}</error>\n </testcase>`;
1937
+ if (r.verdict === "skip") return `${open}>\n <skipped ${message}/>\n </testcase>`;
1938
+ return `${open}>\n <system-out>${`${r.verdict.toUpperCase()}: ${xml(r.reason)}${r.evidence ? `\n${body}` : ""}`}</system-out>\n </testcase>`;
1928
1939
  }
1929
1940
  /** JUnit XML: one testsuite per check, one testcase per result. */
1930
- function formatJunit({ version, command, checks, results }) {
1941
+ function formatJunit({ version, command, checks, strict, results }) {
1931
1942
  const suites = checks.map((check) => {
1932
1943
  const own = results.filter((r) => r.check === check);
1933
1944
  return [
1934
- ` <testsuite name="${xml(check)}" ${totals(own)}>`,
1935
- ...own.map(testcase),
1945
+ ` <testsuite name="${xml(check)}" ${totals(own, strict)}>`,
1946
+ ...own.map((r) => testcase(r, strict)),
1936
1947
  " </testsuite>"
1937
1948
  ].join("\n");
1938
1949
  });
1939
1950
  return [
1940
1951
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
1941
- `<testsuites name="cliprobe ${xml(version)}: ${xml(command)}" ${totals(results)}>`,
1952
+ `<testsuites name="cliprobe ${xml(version)}: ${xml(command)}" ${totals(results, strict)}>`,
1942
1953
  ...suites,
1943
1954
  "</testsuites>",
1944
1955
  ""
@@ -1965,8 +1976,8 @@ function code(text, { inTable }) {
1965
1976
  function prose(text) {
1966
1977
  return safe(text).replace(/[\\`*_[\]<>|~&]/g, (c) => `\\${c}`);
1967
1978
  }
1968
- function row(r) {
1969
- const verdict = r.verdict === "fail" || r.verdict === "error" ? `**${r.verdict.toUpperCase()}**` : r.verdict.toUpperCase();
1979
+ function row(r, strict) {
1980
+ const verdict = r.verdict === "fail" || r.verdict === "error" || strict && r.verdict === "warn" ? `**${r.verdict.toUpperCase()}**` : r.verdict.toUpperCase();
1970
1981
  const evidence = r.evidence ? `<br>${code(r.evidence.slice(0, 300), { inTable: true })}` : "";
1971
1982
  return `| ${[
1972
1983
  prose(r.check),
@@ -1976,15 +1987,15 @@ function row(r) {
1976
1987
  ].join(" | ")} |`;
1977
1988
  }
1978
1989
  /** GitHub-flavored Markdown, for a job summary ($GITHUB_STEP_SUMMARY) or a PR comment. */
1979
- function formatMarkdown({ version, command, results }) {
1990
+ function formatMarkdown({ version, command, strict, results }) {
1980
1991
  return [
1981
1992
  `## cliprobe ${version}: ${code(command, { inTable: false })}`,
1982
1993
  "",
1983
- summaryLine(countVerdicts(results)),
1994
+ summaryLine(countVerdicts(results), strict),
1984
1995
  "",
1985
1996
  "| Check | Verdict | Invocation | Result |",
1986
1997
  "| --- | --- | --- | --- |",
1987
- ...results.map(row),
1998
+ ...results.map((r) => row(r, strict)),
1988
1999
  ""
1989
2000
  ].join("\n");
1990
2001
  }
@@ -2045,6 +2056,8 @@ function parseArgs(argv) {
2045
2056
  help: false,
2046
2057
  version: false,
2047
2058
  checks: [],
2059
+ skip: [],
2060
+ strict: false,
2048
2061
  command: void 0,
2049
2062
  args: []
2050
2063
  };
@@ -2056,6 +2069,7 @@ function parseArgs(argv) {
2056
2069
  }
2057
2070
  if (a === "--json") opts.format = "json";
2058
2071
  else if (a === "--bare") opts.bare = true;
2072
+ else if (a === "--strict") opts.strict = true;
2059
2073
  else if (a === "-o" || a === "--output-file" || a.startsWith("--output-file=")) {
2060
2074
  const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
2061
2075
  if (!value) throw new UsageError(`${a.split("=")[0] ?? a} needs a file path`);
@@ -2070,10 +2084,11 @@ function parseArgs(argv) {
2070
2084
  const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
2071
2085
  opts.timeout = Number(value);
2072
2086
  if (!Number.isInteger(opts.timeout) || opts.timeout <= 0) throw new UsageError(`--timeout needs a positive whole number of milliseconds, got "${String(value)}"`);
2073
- } else if (a === "--check" || a.startsWith("--check=")) {
2087
+ } else if (/^--(check|skip)(=|$)/.test(a)) {
2088
+ const flag = a.split("=")[0] ?? a;
2074
2089
  const names = ((a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i]) ?? "").split(",").map((n) => n.trim()).filter(Boolean);
2075
- if (names.length === 0) throw new UsageError("--check needs a check name");
2076
- opts.checks.push(...names);
2090
+ if (names.length === 0) throw new UsageError(`${flag} needs a check name`);
2091
+ (flag === "--skip" ? opts.skip : opts.checks).push(...names);
2077
2092
  } else if (a.startsWith("-")) throw new UsageError(`unknown option "${a}"`);
2078
2093
  else {
2079
2094
  [opts.command, ...opts.args] = argv.slice(i);
@@ -2144,6 +2159,8 @@ Options:
2144
2159
  --bare Probe the command with no arguments (a REPL, a full-screen
2145
2160
  program, a server) instead of --version and --help
2146
2161
  --check <name> Run only this check; repeat it or use commas for several
2162
+ --skip <name> Leave this check out; repeat it or use commas for several
2163
+ --strict Exit 1 on a warning too, not only on a failure
2147
2164
  --format <name> Output format: human (default), json, markdown (a CI job
2148
2165
  summary or PR comment) or junit (XML for CI test reports)
2149
2166
  --json Same as --format json
@@ -2156,14 +2173,18 @@ Options:
2156
2173
  -h, --help Show this help
2157
2174
  -v, --version Show the version
2158
2175
 
2159
- Exit codes: 0 no failures, 1 a check failed, 2 usage error or could not run.
2176
+ Exit codes: 0 no failures, 1 a check failed (or warned, with --strict), 2 usage
2177
+ error or could not run.
2160
2178
  Runs the target in the current directory without a shell, with stdin closed
2161
2179
  (the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
2162
2180
  temporary HOME and a minimal environment. Only run programs you trust.`;
2163
2181
  // src/cli/program.ts
2164
- /** 0 no failures, 1 a check failed, 2 nothing could be judged because something could not run. */
2165
- function exitCodeFor(results) {
2166
- if (results.some((r) => r.verdict === "fail")) return 1;
2182
+ /**
2183
+ * 0 no failures, 1 a check failed (or, with `strict`, warned), 2 nothing could be
2184
+ * judged because something could not run.
2185
+ */
2186
+ function exitCodeFor(results, strict = false) {
2187
+ if (results.some((r) => r.verdict === "fail" || strict && r.verdict === "warn")) return 1;
2167
2188
  if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
2168
2189
  return 0;
2169
2190
  }
@@ -2187,12 +2208,16 @@ async function run(argv, io) {
2187
2208
  out(VERSION + "\n");
2188
2209
  return 0;
2189
2210
  }
2190
- const { checks, unknown } = selectChecks(opts.checks);
2211
+ const { checks, unknown } = selectChecks(opts.checks, opts.skip);
2191
2212
  if (unknown.length) {
2192
2213
  const available = CHECKS.map((c) => c.name).join(", ");
2193
2214
  err(`cliprobe: unknown check ${unknown.map((n) => `"${n}"`).join(", ")} (available: ${available})\n`);
2194
2215
  return 2;
2195
2216
  }
2217
+ if (checks.length === 0) {
2218
+ err("cliprobe: --skip leaves no check to run\n");
2219
+ return 2;
2220
+ }
2196
2221
  if (!opts.command) {
2197
2222
  err("cliprobe: no command given\nUsage: cliprobe [options] -- <command> [args...]\n");
2198
2223
  return 2;
@@ -2227,6 +2252,7 @@ async function run(argv, io) {
2227
2252
  version: VERSION,
2228
2253
  command: opts.command,
2229
2254
  checks: checks.map((c) => c.name),
2255
+ strict: opts.strict,
2230
2256
  results: fixture ? collapseResults(results, fixture) : results
2231
2257
  };
2232
2258
  const { color } = io;
@@ -2240,7 +2266,7 @@ async function run(argv, io) {
2240
2266
  }
2241
2267
  out(FORMATS.human(report, { color }));
2242
2268
  } else out(FORMATS[opts.format](report, { color }));
2243
- return exitCodeFor(results);
2269
+ return exitCodeFor(results, opts.strict);
2244
2270
  }
2245
2271
  // src/cli/main.ts
2246
2272
  process.stdout.on("error", (error) => {
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "0.10.0",
3
+ "version": "1.1.0",
4
4
  "description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), color and control codes leaking into pipes, hangs waiting on stdin, broken Ctrl-C handling, child processes left running after SIGTERM, a terminal left broken after Ctrl-C, and control characters from file names reaching your terminal.",
5
5
  "type": "module",
6
6
  "bin": {
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",
@@ -83,6 +88,7 @@
83
88
  "@types/markdown-it": "^14.2.0",
84
89
  "@types/node": "^22.20.5",
85
90
  "@vitest/coverage-v8": "^5.1.0",
91
+ "ajv": "^8.20.0",
86
92
  "conventional-changelog-conventionalcommits": "^9.3.1",
87
93
  "fast-xml-parser": "^5.12.0",
88
94
  "husky": "^9.1.7",
package/schema.json ADDED
@@ -0,0 +1,599 @@
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
+ "strict": {
31
+ "type": "boolean",
32
+ "description": "Whether --strict was given, so warnings fail too (exit code 1). Added in 1.1; absent from earlier reports."
33
+ },
34
+ "summary": {
35
+ "type": "object",
36
+ "description": "How many results have each verdict.",
37
+ "required": ["pass", "fail", "warn", "skip", "error", "info"],
38
+ "properties": {
39
+ "pass": {
40
+ "type": "integer",
41
+ "minimum": 0
42
+ },
43
+ "fail": {
44
+ "type": "integer",
45
+ "minimum": 0
46
+ },
47
+ "warn": {
48
+ "type": "integer",
49
+ "minimum": 0
50
+ },
51
+ "skip": {
52
+ "type": "integer",
53
+ "minimum": 0
54
+ },
55
+ "error": {
56
+ "type": "integer",
57
+ "minimum": 0
58
+ },
59
+ "info": {
60
+ "type": "integer",
61
+ "minimum": 0
62
+ }
63
+ }
64
+ },
65
+ "results": {
66
+ "type": "array",
67
+ "items": {
68
+ "$ref": "#/$defs/result"
69
+ }
70
+ }
71
+ },
72
+ "$defs": {
73
+ "checkName": {
74
+ "enum": [
75
+ "closed-pipe",
76
+ "color",
77
+ "pipe-escapes",
78
+ "stdin",
79
+ "ctrl-c",
80
+ "sigterm",
81
+ "restore",
82
+ "control-chars",
83
+ "startup",
84
+ "baseline"
85
+ ]
86
+ },
87
+ "verdict": {
88
+ "enum": ["pass", "fail", "warn", "skip", "error", "info"],
89
+ "description": "fail sets exit code 1; error means the probe could not run; info comes only from info checks."
90
+ },
91
+ "controlKind": {
92
+ "enum": ["cursor", "erase", "mode", "hyperlink", "title", "osc", "redraw"]
93
+ },
94
+ "result": {
95
+ "type": "object",
96
+ "description": "One check on one invocation.",
97
+ "required": ["check", "invocation", "verdict", "reason", "details"],
98
+ "properties": {
99
+ "check": {
100
+ "$ref": "#/$defs/checkName"
101
+ },
102
+ "invocation": {
103
+ "type": "array",
104
+ "minItems": 1,
105
+ "items": {
106
+ "type": "string"
107
+ },
108
+ "description": "The command and arguments that were run."
109
+ },
110
+ "verdict": {
111
+ "$ref": "#/$defs/verdict"
112
+ },
113
+ "reason": {
114
+ "type": "string",
115
+ "description": "One sentence for a person; its wording may change."
116
+ },
117
+ "evidence": {
118
+ "type": "string",
119
+ "description": "The line that led to the verdict, escaped; absent when there is none."
120
+ },
121
+ "details": {
122
+ "type": "object",
123
+ "description": "The check's own measurements, described by $defs/details.<check>."
124
+ }
125
+ },
126
+ "allOf": [
127
+ {
128
+ "if": {
129
+ "properties": {
130
+ "check": {
131
+ "const": "closed-pipe"
132
+ }
133
+ }
134
+ },
135
+ "then": {
136
+ "properties": {
137
+ "details": {
138
+ "$ref": "#/$defs/details.closed-pipe"
139
+ }
140
+ }
141
+ }
142
+ },
143
+ {
144
+ "if": {
145
+ "properties": {
146
+ "check": {
147
+ "const": "color"
148
+ }
149
+ }
150
+ },
151
+ "then": {
152
+ "properties": {
153
+ "details": {
154
+ "$ref": "#/$defs/details.color"
155
+ }
156
+ }
157
+ }
158
+ },
159
+ {
160
+ "if": {
161
+ "properties": {
162
+ "check": {
163
+ "const": "pipe-escapes"
164
+ }
165
+ }
166
+ },
167
+ "then": {
168
+ "properties": {
169
+ "details": {
170
+ "$ref": "#/$defs/details.pipe-escapes"
171
+ }
172
+ }
173
+ }
174
+ },
175
+ {
176
+ "if": {
177
+ "properties": {
178
+ "check": {
179
+ "const": "stdin"
180
+ }
181
+ }
182
+ },
183
+ "then": {
184
+ "properties": {
185
+ "details": {
186
+ "$ref": "#/$defs/details.stdin"
187
+ }
188
+ }
189
+ }
190
+ },
191
+ {
192
+ "if": {
193
+ "properties": {
194
+ "check": {
195
+ "const": "ctrl-c"
196
+ }
197
+ }
198
+ },
199
+ "then": {
200
+ "properties": {
201
+ "details": {
202
+ "$ref": "#/$defs/details.ctrl-c"
203
+ }
204
+ }
205
+ }
206
+ },
207
+ {
208
+ "if": {
209
+ "properties": {
210
+ "check": {
211
+ "const": "sigterm"
212
+ }
213
+ }
214
+ },
215
+ "then": {
216
+ "properties": {
217
+ "details": {
218
+ "$ref": "#/$defs/details.sigterm"
219
+ }
220
+ }
221
+ }
222
+ },
223
+ {
224
+ "if": {
225
+ "properties": {
226
+ "check": {
227
+ "const": "restore"
228
+ }
229
+ }
230
+ },
231
+ "then": {
232
+ "properties": {
233
+ "details": {
234
+ "$ref": "#/$defs/details.restore"
235
+ }
236
+ }
237
+ }
238
+ },
239
+ {
240
+ "if": {
241
+ "properties": {
242
+ "check": {
243
+ "const": "control-chars"
244
+ }
245
+ }
246
+ },
247
+ "then": {
248
+ "properties": {
249
+ "details": {
250
+ "$ref": "#/$defs/details.control-chars"
251
+ }
252
+ }
253
+ }
254
+ },
255
+ {
256
+ "if": {
257
+ "properties": {
258
+ "check": {
259
+ "const": "startup"
260
+ }
261
+ }
262
+ },
263
+ "then": {
264
+ "properties": {
265
+ "details": {
266
+ "$ref": "#/$defs/details.startup"
267
+ }
268
+ }
269
+ }
270
+ },
271
+ {
272
+ "if": {
273
+ "properties": {
274
+ "check": {
275
+ "const": "baseline"
276
+ }
277
+ }
278
+ },
279
+ "then": {
280
+ "properties": {
281
+ "details": {
282
+ "$ref": "#/$defs/details.baseline"
283
+ }
284
+ }
285
+ }
286
+ }
287
+ ]
288
+ },
289
+ "details.closed-pipe": {
290
+ "type": "object",
291
+ "description": "A normal run into a pipe, then a run with stdout already closed.",
292
+ "required": ["baseline", "closed"],
293
+ "properties": {
294
+ "baseline": {
295
+ "type": "object",
296
+ "description": "The normal run.",
297
+ "required": ["exitCode", "signal", "stdoutBytes"],
298
+ "properties": {
299
+ "exitCode": {
300
+ "type": ["integer", "null"],
301
+ "description": "Exit code; null if it was killed by a signal or never ran."
302
+ },
303
+ "signal": {
304
+ "type": ["string", "null"],
305
+ "description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
306
+ },
307
+ "stdoutBytes": {
308
+ "type": "integer",
309
+ "minimum": 0
310
+ }
311
+ }
312
+ },
313
+ "closed": {
314
+ "type": "object",
315
+ "description": "The run with stdout closed.",
316
+ "required": ["exitCode", "signal", "timedOut", "stderr"],
317
+ "properties": {
318
+ "exitCode": {
319
+ "type": ["integer", "null"],
320
+ "description": "Exit code; null if it was killed by a signal or never ran."
321
+ },
322
+ "signal": {
323
+ "type": ["string", "null"],
324
+ "description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
325
+ },
326
+ "timedOut": {
327
+ "type": "boolean"
328
+ },
329
+ "stderr": {
330
+ "type": "string",
331
+ "description": "What it printed to stderr, up to 64 KiB."
332
+ }
333
+ }
334
+ }
335
+ }
336
+ },
337
+ "details.color": {
338
+ "type": "object",
339
+ "description": "Runs into a pipe, under a terminal and under a terminal with NO_COLOR=1; null for a run that was not needed.",
340
+ "required": ["pipe", "tty", "noColor"],
341
+ "properties": {
342
+ "pipe": {
343
+ "type": "object",
344
+ "description": "The run into a pipe.",
345
+ "required": ["exitCode", "stdoutStyled", "stderrStyled"],
346
+ "properties": {
347
+ "exitCode": {
348
+ "type": ["integer", "null"],
349
+ "description": "Exit code; null if it was killed by a signal or never ran."
350
+ },
351
+ "stdoutStyled": {
352
+ "type": "boolean"
353
+ },
354
+ "stderrStyled": {
355
+ "type": "boolean"
356
+ }
357
+ }
358
+ },
359
+ "tty": {
360
+ "type": ["object", "null"],
361
+ "description": "The run under a terminal.",
362
+ "required": ["exitCode", "timedOut", "styled"],
363
+ "properties": {
364
+ "exitCode": {
365
+ "type": ["integer", "null"],
366
+ "description": "Exit code; null if it was killed by a signal or never ran."
367
+ },
368
+ "timedOut": {
369
+ "type": "boolean"
370
+ },
371
+ "styled": {
372
+ "type": "boolean"
373
+ }
374
+ }
375
+ },
376
+ "noColor": {
377
+ "type": ["object", "null"],
378
+ "description": "The run under a terminal with NO_COLOR=1.",
379
+ "required": ["exitCode", "timedOut", "styled"],
380
+ "properties": {
381
+ "exitCode": {
382
+ "type": ["integer", "null"],
383
+ "description": "Exit code; null if it was killed by a signal or never ran."
384
+ },
385
+ "timedOut": {
386
+ "type": "boolean"
387
+ },
388
+ "styled": {
389
+ "type": "boolean"
390
+ }
391
+ }
392
+ }
393
+ }
394
+ },
395
+ "details.pipe-escapes": {
396
+ "type": "object",
397
+ "description": "Kinds of control code found on each stream, without repeats.",
398
+ "required": ["stdoutKinds", "stderrKinds"],
399
+ "properties": {
400
+ "stdoutKinds": {
401
+ "type": "array",
402
+ "items": {
403
+ "$ref": "#/$defs/controlKind"
404
+ }
405
+ },
406
+ "stderrKinds": {
407
+ "type": "array",
408
+ "items": {
409
+ "$ref": "#/$defs/controlKind"
410
+ }
411
+ }
412
+ }
413
+ },
414
+ "details.stdin": {
415
+ "type": "object",
416
+ "description": "The run with stdin as an open pipe that is closed after a while.",
417
+ "required": ["closedMs", "waitedForStdin", "finishedAfterCloseMs"],
418
+ "properties": {
419
+ "closedMs": {
420
+ "type": ["integer", "null"],
421
+ "minimum": 0,
422
+ "description": "When stdin was closed, in ms after start; null if it finished first."
423
+ },
424
+ "waitedForStdin": {
425
+ "type": "boolean"
426
+ },
427
+ "finishedAfterCloseMs": {
428
+ "type": ["integer", "null"],
429
+ "minimum": 0,
430
+ "description": "From closing stdin to the program finishing; null if not measured."
431
+ }
432
+ }
433
+ },
434
+ "details.ctrl-c": {
435
+ "type": "object",
436
+ "description": "SIGINT to the process group after 1 s.",
437
+ "required": ["sentAfterMs", "exitedAfterMs", "exitCode", "signal", "stderrAfter"],
438
+ "properties": {
439
+ "sentAfterMs": {
440
+ "type": ["integer", "null"],
441
+ "minimum": 0,
442
+ "description": "When SIGINT was sent, in ms after start; null if the program had already exited."
443
+ },
444
+ "exitedAfterMs": {
445
+ "type": ["integer", "null"],
446
+ "minimum": 0,
447
+ "description": "From SIGINT to exit; null if it was not sent or the program ignored it."
448
+ },
449
+ "exitCode": {
450
+ "type": ["integer", "null"],
451
+ "description": "Exit code; null if it was killed by a signal or never ran."
452
+ },
453
+ "signal": {
454
+ "type": ["string", "null"],
455
+ "description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
456
+ },
457
+ "stderrAfter": {
458
+ "type": "string",
459
+ "description": "The last 2000 characters it printed to stderr after SIGINT."
460
+ }
461
+ }
462
+ },
463
+ "details.sigterm": {
464
+ "type": "object",
465
+ "description": "SIGTERM to the program alone after 1 s.",
466
+ "required": [
467
+ "sentAfterMs",
468
+ "exitedAfterMs",
469
+ "exitCode",
470
+ "signal",
471
+ "leftRunning",
472
+ "stderrAfter"
473
+ ],
474
+ "properties": {
475
+ "sentAfterMs": {
476
+ "type": ["integer", "null"],
477
+ "minimum": 0,
478
+ "description": "When SIGTERM was sent, in ms after start; null if the program had already exited."
479
+ },
480
+ "exitedAfterMs": {
481
+ "type": ["integer", "null"],
482
+ "minimum": 0,
483
+ "description": "From SIGTERM to exit; null if it was not sent or the program ignored it."
484
+ },
485
+ "exitCode": {
486
+ "type": ["integer", "null"],
487
+ "description": "Exit code; null if it was killed by a signal or never ran."
488
+ },
489
+ "signal": {
490
+ "type": ["string", "null"],
491
+ "description": "Signal that ended it, such as \"SIGPIPE\"; null if it exited."
492
+ },
493
+ "leftRunning": {
494
+ "type": "array",
495
+ "items": {
496
+ "type": "string"
497
+ },
498
+ "description": "Command lines of the processes still running in its group after it exited."
499
+ },
500
+ "stderrAfter": {
501
+ "type": "string",
502
+ "description": "The last 2000 characters it printed to stderr after SIGTERM."
503
+ }
504
+ }
505
+ },
506
+ "details.restore": {
507
+ "type": "object",
508
+ "description": "The run under a terminal.",
509
+ "required": ["interrupted", "openModes"],
510
+ "properties": {
511
+ "interrupted": {
512
+ "type": "boolean",
513
+ "description": "Whether Ctrl-C was typed; false when the program exited first."
514
+ },
515
+ "openModes": {
516
+ "type": "array",
517
+ "description": "The terminal modes it left switched on.",
518
+ "items": {
519
+ "type": "object",
520
+ "description": "One mode left on.",
521
+ "required": ["label", "sequence", "line"],
522
+ "properties": {
523
+ "label": {
524
+ "type": "string"
525
+ },
526
+ "sequence": {
527
+ "type": "string",
528
+ "description": "The sequence that switched it on, escaped."
529
+ },
530
+ "line": {
531
+ "type": "integer",
532
+ "minimum": 1
533
+ }
534
+ }
535
+ }
536
+ }
537
+ }
538
+ },
539
+ "details.control-chars": {
540
+ "type": "object",
541
+ "description": "Kinds of hostile file name that reached the output unescaped.",
542
+ "required": ["terminalRaw", "pipeRaw"],
543
+ "properties": {
544
+ "terminalRaw": {
545
+ "type": "array",
546
+ "items": {
547
+ "type": "string"
548
+ },
549
+ "description": "In the terminal run; these decide the verdict."
550
+ },
551
+ "pipeRaw": {
552
+ "type": "array",
553
+ "items": {
554
+ "type": "string"
555
+ },
556
+ "description": "In the pipe run; normal for ls and find, so not judged."
557
+ }
558
+ }
559
+ },
560
+ "details.startup": {
561
+ "type": "object",
562
+ "description": "Timed runs.",
563
+ "required": ["runsMs", "medianMs"],
564
+ "properties": {
565
+ "runsMs": {
566
+ "type": "array",
567
+ "items": {
568
+ "type": "integer",
569
+ "minimum": 0
570
+ },
571
+ "description": "Wall time of each timed run."
572
+ },
573
+ "medianMs": {
574
+ "type": ["integer", "null"],
575
+ "minimum": 0
576
+ }
577
+ }
578
+ },
579
+ "details.baseline": {
580
+ "type": "object",
581
+ "description": "One run with the extra flag.",
582
+ "required": ["exitCode", "stdoutLines", "stderrLines"],
583
+ "properties": {
584
+ "exitCode": {
585
+ "type": ["integer", "null"],
586
+ "description": "Exit code; null if it was killed by a signal or never ran."
587
+ },
588
+ "stdoutLines": {
589
+ "type": "integer",
590
+ "minimum": 0
591
+ },
592
+ "stderrLines": {
593
+ "type": "integer",
594
+ "minimum": 0
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }