cliprobe 1.4.3 → 1.4.4

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 +1 -1
  2. package/dist/cli.js +39 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -211,7 +211,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
211
211
  }
212
212
  ```
213
213
 
214
- `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.
214
+ `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.
215
215
 
216
216
  ## Stability
217
217
 
package/dist/cli.js CHANGED
@@ -583,7 +583,10 @@ function describeVersion(r) {
583
583
  function describeHelp(r) {
584
584
  const out = lines(r.stdout.toString("utf8"));
585
585
  const err = lines(r.stderr);
586
- if (out.length && r.exitCode === 0) return { reason: `printed ${out.length} lines to stdout and exited 0` };
586
+ if (out.length && r.exitCode === 0) {
587
+ const noun = out.length === 1 ? "line" : "lines";
588
+ return { reason: `printed ${out.length} ${noun} to stdout and exited 0` };
589
+ }
587
590
  if (out.length) return { reason: `printed help to stdout but ${exitText(r)}` };
588
591
  if (err.length) return { reason: `printed help to stderr and ${exitText(r)}, so "--help | less" and agents reading stdout get nothing` };
589
592
  return { reason: `printed nothing and ${exitText(r)}` };
@@ -1556,13 +1559,16 @@ const controlCharsCheck = {
1556
1559
  kind: "check",
1557
1560
  summary: "prints control characters from file names raw to the terminal",
1558
1561
  async run(target, ctx) {
1559
- if (target.fixtureDir === void 0) return [{
1560
- check: "control-chars",
1561
- invocation: [target.command],
1562
- ...judgeControlChars({ usesFixture: false }),
1563
- terminalRaw: [],
1564
- pipeRaw: []
1565
- }];
1562
+ if (target.fixtureDir === void 0) {
1563
+ const own = target.probes.filter((p) => p.own);
1564
+ return (own.length ? own.map((p) => [target.command, ...p.args]) : [[target.command]]).map((invocation) => ({
1565
+ check: "control-chars",
1566
+ invocation,
1567
+ ...judgeControlChars({ usesFixture: false }),
1568
+ terminalRaw: [],
1569
+ pipeRaw: []
1570
+ }));
1571
+ }
1566
1572
  const dir = target.fixtureDir;
1567
1573
  const results = [];
1568
1574
  for (const { args } of target.probes.filter((p) => p.args.some((a) => a.includes(dir)))) results.push(await controlChars(target.command, args, dir, ctx));
@@ -1863,7 +1869,6 @@ function listLabels(modes) {
1863
1869
  const WRAPPER_EXEC_FAILED = /^sh: [^\n]*(cannot execute|exec format error)/i;
1864
1870
  /** What the Ctrl-C key sends to a terminal. */
1865
1871
  const CTRL_C_KEY = "";
1866
- const showSequence = (sequence) => sequence.replaceAll("\x1B", "ESC");
1867
1872
  function judgeRestore(r) {
1868
1873
  if (r.spawnError) return {
1869
1874
  verdict: "error",
@@ -1883,7 +1888,7 @@ function judgeRestore(r) {
1883
1888
  if (open.length > 0) return {
1884
1889
  verdict: "warn",
1885
1890
  reason: `left the terminal with ${listLabels(open)} ${when}`,
1886
- evidence: open.map((m) => `${showSequence(m.sequence)} on line ${m.line}, never undone`).join("; ")
1891
+ evidence: open.map((m) => `${m.sequence} on line ${m.line}, never undone`).join("; ")
1887
1892
  };
1888
1893
  return {
1889
1894
  verdict: "pass",
@@ -2291,20 +2296,41 @@ const COLORS = {
2291
2296
  error: 35,
2292
2297
  info: 36
2293
2298
  };
2299
+ const CUT = " ... (--json has the rest)";
2300
+ /**
2301
+ * Evidence for one line of the report: escaped as safe() does, with a backslash from
2302
+ * the program doubled, so the text `\x1b` can't pass for a real escape. Past the limit
2303
+ * it ends at a word, or between two escapes, never inside one, and says it was cut.
2304
+ */
2305
+ function showEvidence(evidence, limit = 200) {
2306
+ const pieces = Array.from(evidence, (c) => c === "\\" ? "\\\\" : safe(c));
2307
+ let shown = "";
2308
+ let wordEnd = 0;
2309
+ for (const piece of pieces) {
2310
+ if (shown.length + piece.length > limit) return (wordEnd > limit * .6 ? shown.slice(0, wordEnd) : shown) + CUT;
2311
+ if (piece === " ") wordEnd = shown.length;
2312
+ shown += piece;
2313
+ }
2314
+ return shown;
2315
+ }
2294
2316
  function formatHuman({ version, command, checks, strict, results }, { color }) {
2295
2317
  const paint = (verdict) => {
2296
2318
  const label = verdict.toUpperCase().padEnd(5);
2297
2319
  return color ? `\x1b[${COLORS[verdict]}m${label}\x1b[0m` : label;
2298
2320
  };
2299
- const width = Math.max(0, ...results.map((r) => safe(shellJoin(r.invocation)).length));
2321
+ const shownInvocation = (invocation) => safe(shellJoin(invocation));
2322
+ const width = Math.max(0, ...results.map((r) => shownInvocation(r.invocation).length).filter((length) => length <= 40));
2323
+ const indent = ` ${" ".repeat(5)} ${" ".repeat(width)} `;
2300
2324
  const noun = checks.length === 1 ? "check" : "checks";
2301
2325
  const lines = [`cliprobe ${version}: ${checks.join(", ")} ${noun} for ${safe(command)}`];
2302
2326
  for (const check of checks) {
2303
2327
  lines.push("");
2304
2328
  if (checks.length > 1) lines.push(check);
2305
2329
  for (const r of results.filter((result) => result.check === check)) {
2306
- lines.push(` ${paint(r.verdict)} ${safe(shellJoin(r.invocation)).padEnd(width)} ${safe(r.reason)}`);
2307
- if (r.evidence) lines.push(` ${" ".repeat(5)} ${" ".repeat(width)} ${safe(r.evidence).slice(0, 200)}`);
2330
+ const invocation = shownInvocation(r.invocation);
2331
+ if (invocation.length > width) lines.push(` ${paint(r.verdict)} ${invocation}`, `${indent}${safe(r.reason)}`);
2332
+ else lines.push(` ${paint(r.verdict)} ${invocation.padEnd(width)} ${safe(r.reason)}`);
2333
+ if (r.evidence) lines.push(`${indent}${showEvidence(r.evidence)}`);
2308
2334
  }
2309
2335
  }
2310
2336
  lines.push("", summaryLine(countVerdicts(results), strict));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
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": {