cliprobe 0.1.0 → 0.2.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 +32 -7
- package/dist/cli.js +192 -19
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -43,20 +43,45 @@ npx cliprobe -- <command> # probes "<command> --version" and "<c
|
|
|
43
43
|
npx cliprobe -- <command> [args...] # probes exactly this invocation
|
|
44
44
|
npx cliprobe -- node ./dist/cli.js list # test your own CLI before publishing
|
|
45
45
|
npx cliprobe --json -- <command> # machine-readable results
|
|
46
|
+
npx cliprobe --format junit -o report.xml -- <command> # JUnit file for CI; human report on stdout
|
|
46
47
|
npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
|
|
47
48
|
npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
| Option
|
|
51
|
-
|
|
|
52
|
-
| `--check <name>`
|
|
53
|
-
| `--
|
|
54
|
-
| `--
|
|
55
|
-
| `-
|
|
56
|
-
|
|
|
51
|
+
| Option | Meaning |
|
|
52
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
53
|
+
| `--check <name>` | Run only this check; repeat it or use commas for several |
|
|
54
|
+
| `--format <name>` | Output format: `human` (default), `json`, `markdown` (a GitHub job summary or PR comment) or `junit` (XML for CI test reports) |
|
|
55
|
+
| `--json` | Same as `--format json` |
|
|
56
|
+
| `-o`, `--output-file <path>` | Write the `--format` report to a file (atomically, creating parent folders); the human report still prints |
|
|
57
|
+
| `--timeout <ms>` | Kill a probe after this long (default 15000) |
|
|
58
|
+
| `-h`, `--help` | Show help |
|
|
59
|
+
| `-v`, `--version` | Show the version |
|
|
57
60
|
|
|
58
61
|
Exit codes: `0` no failures, `1` a check failed, `2` usage error or the command could not run. That makes it usable as a CI gate.
|
|
59
62
|
|
|
63
|
+
### In CI
|
|
64
|
+
|
|
65
|
+
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:
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
- name: Check the CLI for terminal-edge bugs
|
|
69
|
+
run: npx --yes cliprobe@0 --format markdown --output-file "$GITHUB_STEP_SUMMARY" -- node ./dist/cli.js
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For CI systems that read test results, write JUnit XML instead and keep it even when the step fails:
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
- run: npx --yes cliprobe@0 --format junit --output-file reports/cliprobe.xml -- node ./dist/cli.js
|
|
76
|
+
- uses: actions/upload-artifact@v7
|
|
77
|
+
if: always()
|
|
78
|
+
with:
|
|
79
|
+
name: cliprobe-report
|
|
80
|
+
path: reports/cliprobe.xml
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
60
85
|
## Checks
|
|
61
86
|
|
|
62
87
|
A default run does the four checks below: closed-pipe, color, ctrl-c and control-chars. Each one reports evidence, never a score. Two info checks, startup and baseline, run only when you name them with `--check`.
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { execFileSync, spawn } from "node:child_process";
|
|
4
|
-
import { closeSync, constants, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
4
|
+
import { closeSync, constants, mkdirSync, mkdtempSync, openSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
// src/core/sandbox.ts
|
|
8
8
|
/** A minimal environment: no tokens or config from the caller's shell. */
|
|
@@ -1041,6 +1041,25 @@ function safe(text) {
|
|
|
1041
1041
|
function safeJson(value) {
|
|
1042
1042
|
return JSON.stringify(value, null, 2).replace(JSON_UNSAFE, (c) => `\\u${hex(c, 4)}`);
|
|
1043
1043
|
}
|
|
1044
|
+
// src/report/summary.ts
|
|
1045
|
+
function countVerdicts(results) {
|
|
1046
|
+
const counts = {
|
|
1047
|
+
pass: 0,
|
|
1048
|
+
fail: 0,
|
|
1049
|
+
warn: 0,
|
|
1050
|
+
skip: 0,
|
|
1051
|
+
error: 0,
|
|
1052
|
+
info: 0
|
|
1053
|
+
};
|
|
1054
|
+
for (const r of results) counts[r.verdict]++;
|
|
1055
|
+
return counts;
|
|
1056
|
+
}
|
|
1057
|
+
/** "2 failed, 0 warned, 2 passed, 2 skipped", plus info and could-not-run when present. */
|
|
1058
|
+
function summaryLine(c) {
|
|
1059
|
+
const info = c.info ? `, ${c.info} info` : "";
|
|
1060
|
+
const errors = c.error ? `, ${c.error} could not run` : "";
|
|
1061
|
+
return `${c.fail} failed, ${c.warn} warned, ${c.pass} passed, ${c.skip} skipped${info}${errors}`;
|
|
1062
|
+
}
|
|
1044
1063
|
// src/report/human.ts
|
|
1045
1064
|
const COLORS = {
|
|
1046
1065
|
pass: 32,
|
|
@@ -1050,10 +1069,10 @@ const COLORS = {
|
|
|
1050
1069
|
error: 35,
|
|
1051
1070
|
info: 36
|
|
1052
1071
|
};
|
|
1053
|
-
function formatHuman(version, command, checks, results,
|
|
1072
|
+
function formatHuman({ version, command, checks, results }, { color }) {
|
|
1054
1073
|
const paint = (verdict) => {
|
|
1055
1074
|
const label = verdict.toUpperCase().padEnd(5);
|
|
1056
|
-
return
|
|
1075
|
+
return color ? `\x1b[${COLORS[verdict]}m${label}\x1b[0m` : label;
|
|
1057
1076
|
};
|
|
1058
1077
|
const width = Math.max(0, ...results.map((r) => safe(r.invocation.join(" ")).length));
|
|
1059
1078
|
const noun = checks.length === 1 ? "check" : "checks";
|
|
@@ -1066,14 +1085,11 @@ function formatHuman(version, command, checks, results, useColor) {
|
|
|
1066
1085
|
if (r.evidence) lines.push(` ${" ".repeat(5)} ${" ".repeat(width)} ${safe(r.evidence).slice(0, 200)}`);
|
|
1067
1086
|
}
|
|
1068
1087
|
}
|
|
1069
|
-
|
|
1070
|
-
const info = count("info") ? `, ${count("info")} info` : "";
|
|
1071
|
-
const errors = count("error") ? `, ${count("error")} could not run` : "";
|
|
1072
|
-
lines.push("", `${count("fail")} failed, ${count("warn")} warned, ${count("pass")} passed, ${count("skip")} skipped${info}${errors}`);
|
|
1088
|
+
lines.push("", summaryLine(countVerdicts(results)));
|
|
1073
1089
|
return lines.join("\n") + "\n";
|
|
1074
1090
|
}
|
|
1075
1091
|
// src/report/json.ts
|
|
1076
|
-
function formatJson(version, command, checks, results) {
|
|
1092
|
+
function formatJson({ version, command, checks, results }) {
|
|
1077
1093
|
return safeJson({
|
|
1078
1094
|
tool: "cliprobe",
|
|
1079
1095
|
version,
|
|
@@ -1082,6 +1098,137 @@ function formatJson(version, command, checks, results) {
|
|
|
1082
1098
|
results
|
|
1083
1099
|
}) + "\n";
|
|
1084
1100
|
}
|
|
1101
|
+
// src/report/junit.ts
|
|
1102
|
+
const XML_ESCAPES = {
|
|
1103
|
+
"&": "&",
|
|
1104
|
+
"<": "<",
|
|
1105
|
+
">": ">",
|
|
1106
|
+
"\"": """,
|
|
1107
|
+
"'": "'"
|
|
1108
|
+
};
|
|
1109
|
+
/**
|
|
1110
|
+
* Text that is always well-formed XML 1.0: safe() first turns every control
|
|
1111
|
+
* character (most of which XML forbids even when escaped) into a visible escape,
|
|
1112
|
+
* then the five markup characters become entities.
|
|
1113
|
+
*/
|
|
1114
|
+
function xml(text) {
|
|
1115
|
+
return safe(text).replace(/[&<>"']/g, (c) => XML_ESCAPES[c] ?? c);
|
|
1116
|
+
}
|
|
1117
|
+
/** JUnit's count attributes for a suite or the whole run. */
|
|
1118
|
+
function totals(results) {
|
|
1119
|
+
const c = countVerdicts(results);
|
|
1120
|
+
return `tests="${results.length}" failures="${c.fail}" errors="${c.error}" skipped="${c.skip}"`;
|
|
1121
|
+
}
|
|
1122
|
+
function testcase(r) {
|
|
1123
|
+
const open = ` <testcase classname="cliprobe.${xml(r.check)}" name="${xml(r.invocation.join(" "))}"`;
|
|
1124
|
+
const message = `message="${xml(r.reason)}"`;
|
|
1125
|
+
const body = r.evidence ? xml(r.evidence) : "";
|
|
1126
|
+
switch (r.verdict) {
|
|
1127
|
+
case "fail": return `${open}>\n <failure ${message} type="fail">${body}</failure>\n </testcase>`;
|
|
1128
|
+
case "error": return `${open}>\n <error ${message} type="error">${body}</error>\n </testcase>`;
|
|
1129
|
+
case "skip": return `${open}>\n <skipped ${message}/>\n </testcase>`;
|
|
1130
|
+
case "pass":
|
|
1131
|
+
case "warn":
|
|
1132
|
+
case "info": return `${open}>\n <system-out>${`${r.verdict.toUpperCase()}: ${xml(r.reason)}${r.evidence ? `\n${body}` : ""}`}</system-out>\n </testcase>`;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
/** JUnit XML: one testsuite per check, one testcase per result. */
|
|
1136
|
+
function formatJunit({ version, command, checks, results }) {
|
|
1137
|
+
const suites = checks.map((check) => {
|
|
1138
|
+
const own = results.filter((r) => r.check === check);
|
|
1139
|
+
return [
|
|
1140
|
+
` <testsuite name="${xml(check)}" ${totals(own)}>`,
|
|
1141
|
+
...own.map(testcase),
|
|
1142
|
+
" </testsuite>"
|
|
1143
|
+
].join("\n");
|
|
1144
|
+
});
|
|
1145
|
+
return [
|
|
1146
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
1147
|
+
`<testsuites name="cliprobe ${xml(version)}: ${xml(command)}" ${totals(results)}>`,
|
|
1148
|
+
...suites,
|
|
1149
|
+
"</testsuites>",
|
|
1150
|
+
""
|
|
1151
|
+
].join("\n");
|
|
1152
|
+
}
|
|
1153
|
+
// src/report/markdown.ts
|
|
1154
|
+
/**
|
|
1155
|
+
* A code span that shows any text literally: control characters escaped onto one
|
|
1156
|
+
* line, `|` escaped so a table cell can't be split, and a fence longer than any
|
|
1157
|
+
* run of backticks inside.
|
|
1158
|
+
*/
|
|
1159
|
+
function code(text, { inTable }) {
|
|
1160
|
+
const body = inTable ? safe(text).replaceAll("|", "\\|") : safe(text);
|
|
1161
|
+
const longest = Math.max(0, ...(body.match(/`+/g) ?? []).map((run) => run.length));
|
|
1162
|
+
const fence = "`".repeat(longest + 1);
|
|
1163
|
+
const pad = body.startsWith("`") || body.endsWith("`") ? " " : "";
|
|
1164
|
+
return `${fence}${pad}${body}${pad}${fence}`;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Prose for inside a table cell. Only characters that act mid-line are escaped:
|
|
1168
|
+
* emphasis, code, links, HTML, entities and the cell separator. Line-start syntax
|
|
1169
|
+
* (`#`, `-`, `1.`) can't trigger there, so it stays readable.
|
|
1170
|
+
*/
|
|
1171
|
+
function prose(text) {
|
|
1172
|
+
return safe(text).replace(/[\\`*_[\]<>|~&]/g, (c) => `\\${c}`);
|
|
1173
|
+
}
|
|
1174
|
+
function row(r) {
|
|
1175
|
+
const verdict = r.verdict === "fail" || r.verdict === "error" ? `**${r.verdict.toUpperCase()}**` : r.verdict.toUpperCase();
|
|
1176
|
+
const evidence = r.evidence ? `<br>${code(r.evidence.slice(0, 300), { inTable: true })}` : "";
|
|
1177
|
+
return `| ${[
|
|
1178
|
+
prose(r.check),
|
|
1179
|
+
verdict,
|
|
1180
|
+
code(r.invocation.join(" "), { inTable: true }),
|
|
1181
|
+
prose(r.reason) + evidence
|
|
1182
|
+
].join(" | ")} |`;
|
|
1183
|
+
}
|
|
1184
|
+
/** GitHub-flavored Markdown, for a job summary ($GITHUB_STEP_SUMMARY) or a PR comment. */
|
|
1185
|
+
function formatMarkdown({ version, command, results }) {
|
|
1186
|
+
return [
|
|
1187
|
+
`## cliprobe ${version}: ${code(command, { inTable: false })}`,
|
|
1188
|
+
"",
|
|
1189
|
+
summaryLine(countVerdicts(results)),
|
|
1190
|
+
"",
|
|
1191
|
+
"| Check | Verdict | Invocation | Result |",
|
|
1192
|
+
"| --- | --- | --- | --- |",
|
|
1193
|
+
...results.map(row),
|
|
1194
|
+
""
|
|
1195
|
+
].join("\n");
|
|
1196
|
+
}
|
|
1197
|
+
// src/report/index.ts
|
|
1198
|
+
/** The format names, in the order --help lists them. */
|
|
1199
|
+
const FORMAT_NAMES = [
|
|
1200
|
+
"human",
|
|
1201
|
+
"json",
|
|
1202
|
+
"markdown",
|
|
1203
|
+
"junit"
|
|
1204
|
+
];
|
|
1205
|
+
function isFormat(name) {
|
|
1206
|
+
return FORMAT_NAMES.includes(name);
|
|
1207
|
+
}
|
|
1208
|
+
/** Every output format; the Record type makes a missing formatter a type error. */
|
|
1209
|
+
const FORMATS = {
|
|
1210
|
+
human: formatHuman,
|
|
1211
|
+
json: formatJson,
|
|
1212
|
+
markdown: formatMarkdown,
|
|
1213
|
+
junit: formatJunit
|
|
1214
|
+
};
|
|
1215
|
+
// src/report/write.ts
|
|
1216
|
+
/**
|
|
1217
|
+
* Writes a report so that nothing ever sees half of it: a temporary file in the
|
|
1218
|
+
* same directory, then a rename, which is atomic on one file system. Missing
|
|
1219
|
+
* parent directories are created. Throws on failure, leaving no temporary file.
|
|
1220
|
+
*/
|
|
1221
|
+
function writeReportFile(path, text) {
|
|
1222
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1223
|
+
const temp = `${path}.cliprobe-${process.pid}.tmp`;
|
|
1224
|
+
try {
|
|
1225
|
+
writeFileSync(temp, text);
|
|
1226
|
+
renameSync(temp, path);
|
|
1227
|
+
} catch (error) {
|
|
1228
|
+
rmSync(temp, { force: true });
|
|
1229
|
+
throw error;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1085
1232
|
// src/version.ts
|
|
1086
1233
|
/**
|
|
1087
1234
|
* Read from the package manifest at runtime. Works from both `src/` (development)
|
|
@@ -1097,7 +1244,8 @@ const VERSION = readVersion();
|
|
|
1097
1244
|
var UsageError = class extends Error {};
|
|
1098
1245
|
function parseArgs(argv) {
|
|
1099
1246
|
const opts = {
|
|
1100
|
-
|
|
1247
|
+
format: "human",
|
|
1248
|
+
outputFile: void 0,
|
|
1101
1249
|
timeout: 15e3,
|
|
1102
1250
|
help: false,
|
|
1103
1251
|
version: false,
|
|
@@ -1111,8 +1259,16 @@ function parseArgs(argv) {
|
|
|
1111
1259
|
[opts.command, ...opts.args] = argv.slice(i + 1);
|
|
1112
1260
|
break;
|
|
1113
1261
|
}
|
|
1114
|
-
if (a === "--json") opts.
|
|
1115
|
-
else if (a === "-
|
|
1262
|
+
if (a === "--json") opts.format = "json";
|
|
1263
|
+
else if (a === "-o" || a === "--output-file" || a.startsWith("--output-file=")) {
|
|
1264
|
+
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
1265
|
+
if (!value) throw new UsageError(`${a.split("=")[0] ?? a} needs a file path`);
|
|
1266
|
+
opts.outputFile = value;
|
|
1267
|
+
} else if (a === "--format" || a.startsWith("--format=")) {
|
|
1268
|
+
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
1269
|
+
if (value === void 0 || !isFormat(value)) throw new UsageError(`--format needs one of ${FORMAT_NAMES.join(", ")}, got "${String(value)}"`);
|
|
1270
|
+
opts.format = value;
|
|
1271
|
+
} else if (a === "-h" || a === "--help") opts.help = true;
|
|
1116
1272
|
else if (a === "-v" || a === "--version") opts.version = true;
|
|
1117
1273
|
else if (a === "--timeout" || a.startsWith("--timeout=")) {
|
|
1118
1274
|
const value = a.includes("=") ? a.slice(a.indexOf("=") + 1) : argv[++i];
|
|
@@ -1169,7 +1325,12 @@ Info checks (never fail; run only when named with --check):
|
|
|
1169
1325
|
|
|
1170
1326
|
Options:
|
|
1171
1327
|
--check <name> Run only this check; repeat it or use commas for several
|
|
1172
|
-
--json
|
|
1328
|
+
--format <name> Output format: human (default), json, markdown (a CI job
|
|
1329
|
+
summary or PR comment) or junit (XML for CI test reports)
|
|
1330
|
+
--json Same as --format json
|
|
1331
|
+
-o, --output-file <path>
|
|
1332
|
+
Write the --format report to a file (created atomically,
|
|
1333
|
+
with parent folders); the human report still prints
|
|
1173
1334
|
--timeout <ms> Kill a probe after this long (default 15000)
|
|
1174
1335
|
-h, --help Show this help
|
|
1175
1336
|
-v, --version Show the version
|
|
@@ -1229,12 +1390,24 @@ async function main() {
|
|
|
1229
1390
|
} finally {
|
|
1230
1391
|
fixture?.cleanup();
|
|
1231
1392
|
}
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1393
|
+
const collapse = (text) => fixture ? collapseFixture(text, fixture) : text;
|
|
1394
|
+
const report = {
|
|
1395
|
+
version: VERSION,
|
|
1396
|
+
command: opts.command,
|
|
1397
|
+
checks: checks.map((c) => c.name),
|
|
1398
|
+
results
|
|
1399
|
+
};
|
|
1400
|
+
const color = process.stdout.isTTY && !process.env["NO_COLOR"];
|
|
1401
|
+
if (opts.outputFile) {
|
|
1402
|
+
try {
|
|
1403
|
+
writeReportFile(opts.outputFile, collapse(FORMATS[opts.format](report, { color: false })));
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1406
|
+
err(`cliprobe: could not write ${safe(opts.outputFile)}: ${safe(reason)}\n`);
|
|
1407
|
+
return 2;
|
|
1408
|
+
}
|
|
1409
|
+
out(collapse(FORMATS.human(report, { color })));
|
|
1410
|
+
} else out(collapse(FORMATS[opts.format](report, { color })));
|
|
1238
1411
|
if (results.some((r) => r.verdict === "fail")) return 1;
|
|
1239
1412
|
if (!results.some((r) => r.verdict !== "error" && r.verdict !== "skip") && results.some((r) => r.verdict === "error")) return 2;
|
|
1240
1413
|
return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cliprobe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), color codes leaking into pipes, broken Ctrl-C handling, and control characters from file names reaching your terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -73,9 +73,12 @@
|
|
|
73
73
|
"@semantic-release/github": "^12.0.10",
|
|
74
74
|
"@semantic-release/npm": "^13.2.0",
|
|
75
75
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
76
|
+
"@types/markdown-it": "^14.2.0",
|
|
76
77
|
"@types/node": "^22.20.5",
|
|
77
78
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
79
|
+
"fast-xml-parser": "^5.12.0",
|
|
78
80
|
"husky": "^9.1.7",
|
|
81
|
+
"markdown-it": "^15.0.3",
|
|
79
82
|
"oxlint": "^1.88.0",
|
|
80
83
|
"oxlint-tsgolint": "^7.0.2004",
|
|
81
84
|
"prettier": "^3.9.10",
|