cliprobe 1.0.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
@@ -120,12 +120,15 @@ npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; hu
120
120
  npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
121
121
  npx cliprobe --bare -- htop # the command alone: a REPL, a full-screen program, a server
122
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
123
124
  ```
124
125
 
125
126
  | Option | Meaning |
126
127
  | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
127
128
  | `--bare` | Probe the command with no arguments instead of `--version` and `--help`, as a probe you wrote |
128
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 |
129
132
  | `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports) |
130
133
  | `--json` | Same as `--format json` |
131
134
  | `-o`, `--output-file <path>` | Write the `--format` report to a file (atomically, creating parent folders); the human report still prints |
@@ -138,14 +141,14 @@ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, onl
138
141
  | Code | Meaning |
139
142
  | ---- | ----------------------------------------- |
140
143
  | `0` | No check failed |
141
- | `1` | A check failed |
144
+ | `1` | A check failed, or warned with `--strict` |
142
145
  | `2` | Usage error, or the command could not run |
143
146
 
144
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.
145
148
 
146
149
  ## In CI
147
150
 
148
- 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:
149
152
 
150
153
  ```yaml
151
154
  - name: Check the CLI for terminal-edge bugs
@@ -176,6 +179,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
176
179
  "version": "1.0.0",
177
180
  "command": "node",
178
181
  "checks": ["ctrl-c"],
182
+ "strict": false,
179
183
  "summary": { "pass": 0, "fail": 1, "warn": 0, "skip": 0, "error": 0, "info": 0 },
180
184
  "results": [
181
185
  {
@@ -195,7 +199,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
195
199
  }
196
200
  ```
197
201
 
198
- Every result has the same five fields: `check`, `invocation` (the command and arguments that ran), `verdict` (`pass`, `fail`, `warn`, `skip`, `error` for could-not-run, or `info`), `reason` (a sentence for a person) and `details`, plus `evidence` when there is a line to quote. `details` holds the check's own measurements, such as exit codes, timings, the terminal modes left on or the processes left running; the schema describes each check's. Text from the program under test is escaped: control characters, line separators and bidi overrides appear as `\u` escapes, so the report can't drive a terminal when printed.
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.
199
203
 
200
204
  ## Stability
201
205
 
@@ -203,6 +207,7 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
203
207
 
204
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.
205
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.
206
211
  - **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
207
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.
208
213
 
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,20 +1879,21 @@ 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
1885
  /**
1886
1886
  * The report as JSON. Each result keeps the fields every check shares at the top
1887
1887
  * and moves the check's own measurements into `details`.
1888
1888
  */
1889
- function formatJson({ version, command, checks, results }) {
1889
+ function formatJson({ version, command, checks, strict, results }) {
1890
1890
  return safeJson({
1891
1891
  tool: "cliprobe",
1892
1892
  schemaVersion: 1,
1893
1893
  version,
1894
1894
  command,
1895
1895
  checks,
1896
+ strict,
1896
1897
  summary: countVerdicts(results),
1897
1898
  results: results.map(({ check, invocation, verdict, reason, evidence, ...details }) => ({
1898
1899
  check,
@@ -1920,37 +1921,35 @@ const XML_ESCAPES = {
1920
1921
  function xml(text) {
1921
1922
  return safe(text).replace(/[&<>"']/g, (c) => XML_ESCAPES[c] ?? c);
1922
1923
  }
1923
- /** JUnit's count attributes for a suite or the whole run. */
1924
- 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) {
1925
1926
  const c = countVerdicts(results);
1926
- 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}"`;
1927
1929
  }
1928
- function testcase(r) {
1930
+ function testcase(r, strict) {
1929
1931
  const open = ` <testcase classname="cliprobe.${xml(r.check)}" name="${xml(shellJoin(r.invocation))}"`;
1930
1932
  const message = `message="${xml(r.reason)}"`;
1931
1933
  const body = r.evidence ? xml(r.evidence) : "";
1932
- switch (r.verdict) {
1933
- case "fail": return `${open}>\n <failure ${message} type="fail">${body}</failure>\n </testcase>`;
1934
- case "error": return `${open}>\n <error ${message} type="error">${body}</error>\n </testcase>`;
1935
- case "skip": return `${open}>\n <skipped ${message}/>\n </testcase>`;
1936
- case "pass":
1937
- case "warn":
1938
- case "info": return `${open}>\n <system-out>${`${r.verdict.toUpperCase()}: ${xml(r.reason)}${r.evidence ? `\n${body}` : ""}`}</system-out>\n </testcase>`;
1939
- }
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>`;
1940
1939
  }
1941
1940
  /** JUnit XML: one testsuite per check, one testcase per result. */
1942
- function formatJunit({ version, command, checks, results }) {
1941
+ function formatJunit({ version, command, checks, strict, results }) {
1943
1942
  const suites = checks.map((check) => {
1944
1943
  const own = results.filter((r) => r.check === check);
1945
1944
  return [
1946
- ` <testsuite name="${xml(check)}" ${totals(own)}>`,
1947
- ...own.map(testcase),
1945
+ ` <testsuite name="${xml(check)}" ${totals(own, strict)}>`,
1946
+ ...own.map((r) => testcase(r, strict)),
1948
1947
  " </testsuite>"
1949
1948
  ].join("\n");
1950
1949
  });
1951
1950
  return [
1952
1951
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
1953
- `<testsuites name="cliprobe ${xml(version)}: ${xml(command)}" ${totals(results)}>`,
1952
+ `<testsuites name="cliprobe ${xml(version)}: ${xml(command)}" ${totals(results, strict)}>`,
1954
1953
  ...suites,
1955
1954
  "</testsuites>",
1956
1955
  ""
@@ -1977,8 +1976,8 @@ function code(text, { inTable }) {
1977
1976
  function prose(text) {
1978
1977
  return safe(text).replace(/[\\`*_[\]<>|~&]/g, (c) => `\\${c}`);
1979
1978
  }
1980
- function row(r) {
1981
- 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();
1982
1981
  const evidence = r.evidence ? `<br>${code(r.evidence.slice(0, 300), { inTable: true })}` : "";
1983
1982
  return `| ${[
1984
1983
  prose(r.check),
@@ -1988,15 +1987,15 @@ function row(r) {
1988
1987
  ].join(" | ")} |`;
1989
1988
  }
1990
1989
  /** GitHub-flavored Markdown, for a job summary ($GITHUB_STEP_SUMMARY) or a PR comment. */
1991
- function formatMarkdown({ version, command, results }) {
1990
+ function formatMarkdown({ version, command, strict, results }) {
1992
1991
  return [
1993
1992
  `## cliprobe ${version}: ${code(command, { inTable: false })}`,
1994
1993
  "",
1995
- summaryLine(countVerdicts(results)),
1994
+ summaryLine(countVerdicts(results), strict),
1996
1995
  "",
1997
1996
  "| Check | Verdict | Invocation | Result |",
1998
1997
  "| --- | --- | --- | --- |",
1999
- ...results.map(row),
1998
+ ...results.map((r) => row(r, strict)),
2000
1999
  ""
2001
2000
  ].join("\n");
2002
2001
  }
@@ -2057,6 +2056,8 @@ function parseArgs(argv) {
2057
2056
  help: false,
2058
2057
  version: false,
2059
2058
  checks: [],
2059
+ skip: [],
2060
+ strict: false,
2060
2061
  command: void 0,
2061
2062
  args: []
2062
2063
  };
@@ -2068,6 +2069,7 @@ function parseArgs(argv) {
2068
2069
  }
2069
2070
  if (a === "--json") opts.format = "json";
2070
2071
  else if (a === "--bare") opts.bare = true;
2072
+ else if (a === "--strict") opts.strict = true;
2071
2073
  else if (a === "-o" || a === "--output-file" || a.startsWith("--output-file=")) {
2072
2074
  const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
2073
2075
  if (!value) throw new UsageError(`${a.split("=")[0] ?? a} needs a file path`);
@@ -2082,10 +2084,11 @@ function parseArgs(argv) {
2082
2084
  const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
2083
2085
  opts.timeout = Number(value);
2084
2086
  if (!Number.isInteger(opts.timeout) || opts.timeout <= 0) throw new UsageError(`--timeout needs a positive whole number of milliseconds, got "${String(value)}"`);
2085
- } else if (a === "--check" || a.startsWith("--check=")) {
2087
+ } else if (/^--(check|skip)(=|$)/.test(a)) {
2088
+ const flag = a.split("=")[0] ?? a;
2086
2089
  const names = ((a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i]) ?? "").split(",").map((n) => n.trim()).filter(Boolean);
2087
- if (names.length === 0) throw new UsageError("--check needs a check name");
2088
- 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);
2089
2092
  } else if (a.startsWith("-")) throw new UsageError(`unknown option "${a}"`);
2090
2093
  else {
2091
2094
  [opts.command, ...opts.args] = argv.slice(i);
@@ -2156,6 +2159,8 @@ Options:
2156
2159
  --bare Probe the command with no arguments (a REPL, a full-screen
2157
2160
  program, a server) instead of --version and --help
2158
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
2159
2164
  --format <name> Output format: human (default), json, markdown (a CI job
2160
2165
  summary or PR comment) or junit (XML for CI test reports)
2161
2166
  --json Same as --format json
@@ -2168,14 +2173,18 @@ Options:
2168
2173
  -h, --help Show this help
2169
2174
  -v, --version Show the version
2170
2175
 
2171
- 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.
2172
2178
  Runs the target in the current directory without a shell, with stdin closed
2173
2179
  (the stdin, ctrl-c and sigterm checks use a pipe they never write to), a
2174
2180
  temporary HOME and a minimal environment. Only run programs you trust.`;
2175
2181
  // src/cli/program.ts
2176
- /** 0 no failures, 1 a check failed, 2 nothing could be judged because something could not run. */
2177
- function exitCodeFor(results) {
2178
- 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;
2179
2188
  if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
2180
2189
  return 0;
2181
2190
  }
@@ -2199,12 +2208,16 @@ async function run(argv, io) {
2199
2208
  out(VERSION + "\n");
2200
2209
  return 0;
2201
2210
  }
2202
- const { checks, unknown } = selectChecks(opts.checks);
2211
+ const { checks, unknown } = selectChecks(opts.checks, opts.skip);
2203
2212
  if (unknown.length) {
2204
2213
  const available = CHECKS.map((c) => c.name).join(", ");
2205
2214
  err(`cliprobe: unknown check ${unknown.map((n) => `"${n}"`).join(", ")} (available: ${available})\n`);
2206
2215
  return 2;
2207
2216
  }
2217
+ if (checks.length === 0) {
2218
+ err("cliprobe: --skip leaves no check to run\n");
2219
+ return 2;
2220
+ }
2208
2221
  if (!opts.command) {
2209
2222
  err("cliprobe: no command given\nUsage: cliprobe [options] -- <command> [args...]\n");
2210
2223
  return 2;
@@ -2239,6 +2252,7 @@ async function run(argv, io) {
2239
2252
  version: VERSION,
2240
2253
  command: opts.command,
2241
2254
  checks: checks.map((c) => c.name),
2255
+ strict: opts.strict,
2242
2256
  results: fixture ? collapseResults(results, fixture) : results
2243
2257
  };
2244
2258
  const { color } = io;
@@ -2252,7 +2266,7 @@ async function run(argv, io) {
2252
2266
  }
2253
2267
  out(FORMATS.human(report, { color }));
2254
2268
  } else out(FORMATS[opts.format](report, { color }));
2255
- return exitCodeFor(results);
2269
+ return exitCodeFor(results, opts.strict);
2256
2270
  }
2257
2271
  // src/cli/main.ts
2258
2272
  process.stdout.on("error", (error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.0.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": {
package/schema.json CHANGED
@@ -27,6 +27,10 @@
27
27
  },
28
28
  "description": "The checks that ran, in order."
29
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
+ },
30
34
  "summary": {
31
35
  "type": "object",
32
36
  "description": "How many results have each verdict.",