@acid-cat/cli 0.18.0 → 0.20.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 +35 -5
- package/conformance/fixture.acidcat.json +96 -0
- package/dist/conform-LH9KgQ9-.js +5045 -0
- package/dist/index.d.ts +164 -4
- package/dist/index.js +96 -4
- package/dist/main.d.ts +1 -2
- package/dist/main.js +1090 -7
- package/package.json +4 -3
- package/dist/catalog.d.ts +0 -12
- package/dist/catalog.js +0 -149
- package/dist/conform/check.d.ts +0 -38
- package/dist/conform/check.js +0 -144
- package/dist/conform/cli.d.ts +0 -4
- package/dist/conform/cli.js +0 -721
- package/dist/conform/http.d.ts +0 -5
- package/dist/conform/http.js +0 -297
- package/dist/conform/index.d.ts +0 -63
- package/dist/conform/index.js +0 -58
- package/dist/conform/mcp-stdio.d.ts +0 -6
- package/dist/conform/mcp-stdio.js +0 -291
- package/dist/conform/mcp.d.ts +0 -46
- package/dist/conform/mcp.js +0 -752
- package/dist/conform/poll.d.ts +0 -13
- package/dist/conform/poll.js +0 -295
- package/dist/conform/properties.d.ts +0 -12
- package/dist/conform/properties.js +0 -155
- package/dist/conform/serve.d.ts +0 -12
- package/dist/conform/serve.js +0 -93
- package/dist/conform/server-card.d.ts +0 -5
- package/dist/conform/server-card.js +0 -142
- package/dist/conform/sse.d.ts +0 -9
- package/dist/conform/sse.js +0 -53
- package/dist/conform/webhook.d.ts +0 -30
- package/dist/conform/webhook.js +0 -481
- package/dist/conform/webmcp.d.ts +0 -52
- package/dist/conform/webmcp.js +0 -232
- package/dist/json/catalog.schema.json.js +0 -170
- package/dist/json/fixture.acidcat.json.js +0 -396
- package/dist/json/package.json.js +0 -3
- package/dist/json/server-card.schema.json.js +0 -281
- package/dist/json.d.ts +0 -11
- package/dist/json.js +0 -13
package/dist/conform/cli.js
DELETED
|
@@ -1,721 +0,0 @@
|
|
|
1
|
-
import { isArrayOf, isObject, memberOf, parseJson } from "../json.js";
|
|
2
|
-
import { Checks, abortable, eventIdsOf, expect, expectEqual, expectOccurrence, idsOf, sorted, until } from "./check.js";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
5
|
-
import { existsSync } from "node:fs";
|
|
6
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { isDeepStrictEqual } from "node:util";
|
|
9
|
-
// src/conform/cli.ts
|
|
10
|
-
const RULE = "spec/surfaces/cli.md";
|
|
11
|
-
const USAGES = {
|
|
12
|
-
"fixture.crash": "fixture crash",
|
|
13
|
-
"fixture.echo": "fixture echo --text <string>",
|
|
14
|
-
"fixture.flags": "fixture flags --mode <fast|slow> [--count <integer>] [--extra <json>] [--label <string>] [--ratio <number>] [--steps <integer>...] [--tags <string>...] [--verbose]",
|
|
15
|
-
"fixture.held": "fixture held",
|
|
16
|
-
"fixture.hold": "fixture hold --key <string> [--marker <string>]",
|
|
17
|
-
"fixture.note": "fixture note --text <string> [--loud]",
|
|
18
|
-
"fixture.raw": "call fixture.raw '<json>'",
|
|
19
|
-
"fixture.refuse": "fixture refuse",
|
|
20
|
-
"fixture.release": "fixture release --key <string>",
|
|
21
|
-
"fixture.switch.set": "fixture switch set --on",
|
|
22
|
-
"fixture.toggle": "fixture toggle",
|
|
23
|
-
"fixture.signal": "fixture signal --key <string> --value <string>",
|
|
24
|
-
"fixture.watching": "fixture watching"
|
|
25
|
-
};
|
|
26
|
-
const EVENT_USAGES = {
|
|
27
|
-
"fixture.broken": "watch fixture.broken [--cursor <string>] [--max-age-ms <integer>]",
|
|
28
|
-
"fixture.echoes": "watch fixture.echoes '<json>' [--cursor <string>] [--max-age-ms <integer>]",
|
|
29
|
-
"fixture.ticks": "watch fixture.ticks --count <integer> [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]",
|
|
30
|
-
"fixture.watch": "watch fixture.watch --key <string> [--marker <string>] [--cursor <string>] [--max-age-ms <integer>]"
|
|
31
|
-
};
|
|
32
|
-
const ALIAS_USAGES = {
|
|
33
|
-
"fixture.echo": [
|
|
34
|
-
"--hello",
|
|
35
|
-
"say --text <string>",
|
|
36
|
-
"shout hello"
|
|
37
|
-
],
|
|
38
|
-
"fixture.flags": ["fixture [--count <integer>] [--extra <json>] [--label <string>] [--ratio <number>] [--steps <integer>...] [--tags <string>...] [--verbose]", "quick [--count <integer>] [--extra <json>] [--label <string>] [--ratio <number>] [--steps <integer>...] [--tags <string>...] [--verbose]"],
|
|
39
|
-
"fixture.held": ["held-keys"],
|
|
40
|
-
"fixture.note": [
|
|
41
|
-
"fixed-note [--loud]",
|
|
42
|
-
"notes add --text <string> [--loud]",
|
|
43
|
-
"notes loud --text <string>"
|
|
44
|
-
],
|
|
45
|
-
"fixture.raw": ["notes '<json>'", "raw '<json>'"]
|
|
46
|
-
};
|
|
47
|
-
const EVENT_ALIAS_USAGES = {
|
|
48
|
-
"fixture.broken": ["broken-ticks [--cursor <string>] [--max-age-ms <integer>]"],
|
|
49
|
-
"fixture.echoes": ["echoes '<json>' [--cursor <string>] [--max-age-ms <integer>]"],
|
|
50
|
-
"fixture.ticks": ["ticks [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]"]
|
|
51
|
-
};
|
|
52
|
-
const ALIASES = `${RULE}#aliases`;
|
|
53
|
-
const isEntry = (value) => isObject(value) && typeof value.id === "string";
|
|
54
|
-
function entriesOf(stdout) {
|
|
55
|
-
const list = parseJson(stdout);
|
|
56
|
-
if (!isArrayOf(list, isEntry)) throw new Error(`list must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
57
|
-
return list;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The rejection is observed here too, so that a check that stops waiting first, for example at the deadline, records a
|
|
61
|
-
* failure and does not end the process with an unhandled rejection.
|
|
62
|
-
*/
|
|
63
|
-
function start(command, args, signal) {
|
|
64
|
-
const [program, ...programArgs] = command;
|
|
65
|
-
if (program === void 0) throw new Error("the command that starts the command line is empty");
|
|
66
|
-
const child = spawn(program, [...programArgs, ...args], {
|
|
67
|
-
stdio: [
|
|
68
|
-
"ignore",
|
|
69
|
-
"pipe",
|
|
70
|
-
"pipe"
|
|
71
|
-
],
|
|
72
|
-
signal,
|
|
73
|
-
killSignal: "SIGKILL"
|
|
74
|
-
});
|
|
75
|
-
const run = new Promise((resolve, reject) => {
|
|
76
|
-
let stdout = "";
|
|
77
|
-
let stderr = "";
|
|
78
|
-
child.stdout.on("data", (chunk) => stdout += chunk.toString());
|
|
79
|
-
child.stderr.on("data", (chunk) => stderr += chunk.toString());
|
|
80
|
-
child.on("error", (error) => reject(signal.aborted ? /* @__PURE__ */ new Error(`waiting until the command line exits: ${args.join(" ")}`) : error));
|
|
81
|
-
child.on("close", (code, exitSignal) => resolve({
|
|
82
|
-
code,
|
|
83
|
-
signal: exitSignal,
|
|
84
|
-
stdout,
|
|
85
|
-
stderr
|
|
86
|
-
}));
|
|
87
|
-
});
|
|
88
|
-
run.catch(() => void 0);
|
|
89
|
-
return {
|
|
90
|
-
child,
|
|
91
|
-
run
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async function expectUsageError(result, code) {
|
|
95
|
-
const { code: actual, stdout } = await result;
|
|
96
|
-
expectEqual(actual, code, "exit code");
|
|
97
|
-
expectEqual(stdout, "", "standard output");
|
|
98
|
-
}
|
|
99
|
-
function occurrencesIn(stdout, id) {
|
|
100
|
-
return stdout.split("\n").filter((line) => line !== "").map((line) => expectOccurrence(parseJson(line), id));
|
|
101
|
-
}
|
|
102
|
-
async function checkCli(command, options) {
|
|
103
|
-
const checks = new Checks("cli", options.deadline);
|
|
104
|
-
const run = (signal, ...args) => start(command, args, signal).run;
|
|
105
|
-
const listing = start(command, ["list"], AbortSignal.timeout(options.deadline)).run.then((result) => entriesOf(result.stdout));
|
|
106
|
-
listing.catch(() => void 0);
|
|
107
|
-
const listed = (signal) => abortable(listing, signal);
|
|
108
|
-
await checks.concurrently((check) => {
|
|
109
|
-
check("a value goes to standard output with exit code 0", `${RULE}#outcomes`, async (signal) => {
|
|
110
|
-
const result = await run(signal, "fixture", "echo", "--text", "hello");
|
|
111
|
-
expectEqual(result.code, 0, "exit code");
|
|
112
|
-
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
113
|
-
});
|
|
114
|
-
check("a failure goes to standard output with exit code 1", `${RULE}#outcomes`, async (signal) => {
|
|
115
|
-
const result = await run(signal, "fixture", "refuse");
|
|
116
|
-
expectEqual(result.code, 1, "exit code");
|
|
117
|
-
expectEqual(memberOf(parseJson(result.stdout), "_tag"), "Refused", "_tag");
|
|
118
|
-
});
|
|
119
|
-
check("a defect goes to standard error with exit code 5", `${RULE}#outcomes`, async (signal) => {
|
|
120
|
-
const result = await run(signal, "fixture", "crash");
|
|
121
|
-
expectEqual(result.code, 5, "exit code");
|
|
122
|
-
expect(/"kind":"internal"/.test(result.stderr), "standard error must contain the call failure");
|
|
123
|
-
});
|
|
124
|
-
for (const [name, args, code] of [
|
|
125
|
-
[
|
|
126
|
-
"an unknown command has exit code 2",
|
|
127
|
-
["nothing"],
|
|
128
|
-
2
|
|
129
|
-
],
|
|
130
|
-
[
|
|
131
|
-
"an unknown word after an alias that is the default of a shared prefix has exit code 2",
|
|
132
|
-
["fixture", "nope"],
|
|
133
|
-
2
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
"the first word of two-word aliases alone, with no one-word alias, has exit code 2",
|
|
137
|
-
["shout"],
|
|
138
|
-
2
|
|
139
|
-
],
|
|
140
|
-
[
|
|
141
|
-
"an unknown second word after the first word of two-word aliases has exit code 2",
|
|
142
|
-
["shout", "nope"],
|
|
143
|
-
2
|
|
144
|
-
],
|
|
145
|
-
[
|
|
146
|
-
"an unknown second word after a one-word alias with two-word aliases has exit code 2",
|
|
147
|
-
["notes", "nope"],
|
|
148
|
-
2
|
|
149
|
-
],
|
|
150
|
-
[
|
|
151
|
-
"a capability outside the target has exit code 2",
|
|
152
|
-
["call", "fixture.hidden"],
|
|
153
|
-
2
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
"a capability outside the target with input that is not JSON has exit code 2",
|
|
157
|
-
[
|
|
158
|
-
"call",
|
|
159
|
-
"fixture.hidden",
|
|
160
|
-
"{bad"
|
|
161
|
-
],
|
|
162
|
-
2
|
|
163
|
-
],
|
|
164
|
-
[
|
|
165
|
-
"a missing required flag has exit code 3",
|
|
166
|
-
["fixture", "echo"],
|
|
167
|
-
3
|
|
168
|
-
],
|
|
169
|
-
[
|
|
170
|
-
"an unknown flag has exit code 3",
|
|
171
|
-
[
|
|
172
|
-
"fixture",
|
|
173
|
-
"echo",
|
|
174
|
-
"--text",
|
|
175
|
-
"hello",
|
|
176
|
-
"--nope",
|
|
177
|
-
"x"
|
|
178
|
-
],
|
|
179
|
-
3
|
|
180
|
-
],
|
|
181
|
-
[
|
|
182
|
-
"a flag that is not valid has exit code 3",
|
|
183
|
-
[
|
|
184
|
-
"fixture",
|
|
185
|
-
"flags",
|
|
186
|
-
"--mode",
|
|
187
|
-
"fast",
|
|
188
|
-
"--ratio",
|
|
189
|
-
"soon"
|
|
190
|
-
],
|
|
191
|
-
3
|
|
192
|
-
],
|
|
193
|
-
[
|
|
194
|
-
"an item of a repeated flag that is not valid has exit code 3",
|
|
195
|
-
[
|
|
196
|
-
"fixture",
|
|
197
|
-
"flags",
|
|
198
|
-
"--mode",
|
|
199
|
-
"fast",
|
|
200
|
-
"--steps",
|
|
201
|
-
"1",
|
|
202
|
-
"--steps",
|
|
203
|
-
"soon"
|
|
204
|
-
],
|
|
205
|
-
3
|
|
206
|
-
],
|
|
207
|
-
[
|
|
208
|
-
"an item of a repeated flag as JSON text that is not valid has exit code 3",
|
|
209
|
-
[
|
|
210
|
-
"fixture",
|
|
211
|
-
"flags",
|
|
212
|
-
"--mode",
|
|
213
|
-
"fast",
|
|
214
|
-
"--steps",
|
|
215
|
-
"[1,\"soon\"]"
|
|
216
|
-
],
|
|
217
|
-
3
|
|
218
|
-
],
|
|
219
|
-
[
|
|
220
|
-
"invalid input through call has exit code 3",
|
|
221
|
-
[
|
|
222
|
-
"call",
|
|
223
|
-
"fixture.echo",
|
|
224
|
-
"{\"text\":1}"
|
|
225
|
-
],
|
|
226
|
-
3
|
|
227
|
-
]
|
|
228
|
-
]) check(name, `${RULE}#outcomes`, async (signal) => {
|
|
229
|
-
await expectUsageError(run(signal, ...args), code);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
await checks.run("an interrupt cancels the call with exit code 130", `${RULE}#commands`, async (signal) => {
|
|
233
|
-
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
234
|
-
const marker = join(directory, "held");
|
|
235
|
-
try {
|
|
236
|
-
const { child, run } = start(command, [
|
|
237
|
-
"fixture",
|
|
238
|
-
"hold",
|
|
239
|
-
"--key",
|
|
240
|
-
"interrupt",
|
|
241
|
-
"--marker",
|
|
242
|
-
marker
|
|
243
|
-
], signal);
|
|
244
|
-
const ended = () => child.exitCode !== null || child.signalCode !== null;
|
|
245
|
-
const state = await until("the call writes its marker file", async () => existsSync(marker) ? "marked" : ended() ? "ended" : "waiting", (each) => each !== "waiting", signal);
|
|
246
|
-
if (state === "marked") child.kill("SIGINT");
|
|
247
|
-
const result = await run;
|
|
248
|
-
expect(state === "marked", `the call must hold before the interrupt, but the command line ended with ${result.code}: ${result.stderr}`);
|
|
249
|
-
expect(result.signal === null, `the process must exit, not end by the signal ${result.signal}`);
|
|
250
|
-
expectEqual(result.code, 130, "exit code");
|
|
251
|
-
expectEqual(result.stdout, "", "standard output");
|
|
252
|
-
await until("the call ends and deletes its marker file", async () => !existsSync(marker), (ended) => ended, signal);
|
|
253
|
-
} finally {
|
|
254
|
-
await rm(directory, {
|
|
255
|
-
recursive: true,
|
|
256
|
-
force: true
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
await checks.concurrently((check) => {
|
|
261
|
-
check("each flag gives the value of its property, and a repeated flag gives one item for each occurrence", `${RULE}#commands`, async (signal) => {
|
|
262
|
-
const scalars = [
|
|
263
|
-
"--mode",
|
|
264
|
-
"slow",
|
|
265
|
-
"--count",
|
|
266
|
-
"3",
|
|
267
|
-
"--ratio=0.5",
|
|
268
|
-
"--label",
|
|
269
|
-
"x",
|
|
270
|
-
"--verbose",
|
|
271
|
-
"--extra",
|
|
272
|
-
"{\"a\":1}"
|
|
273
|
-
];
|
|
274
|
-
const repeated = [
|
|
275
|
-
"--steps",
|
|
276
|
-
"2",
|
|
277
|
-
"--tags",
|
|
278
|
-
"[\"a\"]",
|
|
279
|
-
"--steps=1",
|
|
280
|
-
"--tags",
|
|
281
|
-
"b"
|
|
282
|
-
];
|
|
283
|
-
const result = await run(signal, "fixture", "flags", ...scalars, ...repeated);
|
|
284
|
-
expectEqual(result.code, 0, "exit code");
|
|
285
|
-
const expected = {
|
|
286
|
-
mode: "slow",
|
|
287
|
-
count: 3,
|
|
288
|
-
ratio: .5,
|
|
289
|
-
label: "x",
|
|
290
|
-
verbose: true,
|
|
291
|
-
extra: { a: 1 },
|
|
292
|
-
steps: [2, 1],
|
|
293
|
-
tags: ["[\"a\"]", "b"]
|
|
294
|
-
};
|
|
295
|
-
const output = parseJson(result.stdout);
|
|
296
|
-
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
297
|
-
});
|
|
298
|
-
check("a repeated flag that occurs once with JSON text of an array gives that array", `${RULE}#commands`, async (signal) => {
|
|
299
|
-
const result = await run(signal, "fixture", "flags", "--steps", "[2,1]", "--mode", "fast", "--verbose", "--tags=[\"a\",\"b\"]");
|
|
300
|
-
expectEqual(result.code, 0, "exit code");
|
|
301
|
-
const expected = {
|
|
302
|
-
mode: "fast",
|
|
303
|
-
verbose: true,
|
|
304
|
-
steps: [2, 1],
|
|
305
|
-
tags: ["a", "b"]
|
|
306
|
-
};
|
|
307
|
-
const output = parseJson(result.stdout);
|
|
308
|
-
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
309
|
-
});
|
|
310
|
-
check("a first argument -- is ignored", `${RULE}#commands`, async (signal) => {
|
|
311
|
-
const result = await run(signal, "--", "fixture", "echo", "--text", "hello");
|
|
312
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
313
|
-
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
314
|
-
});
|
|
315
|
-
check("call gives the value of a capability", `${RULE}#commands`, async (signal) => {
|
|
316
|
-
const result = await run(signal, "call", "fixture.echo", "{\"text\":\"hello\"}");
|
|
317
|
-
expectEqual(result.code, 0, "exit code");
|
|
318
|
-
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
319
|
-
});
|
|
320
|
-
check("list gives the capabilities of the target, then its events", `${RULE}#commands`, async (signal) => {
|
|
321
|
-
const entries = await listed(signal);
|
|
322
|
-
const ids = (kind) => entries.filter((entry) => entry.kind === kind).map((entry) => entry.id);
|
|
323
|
-
expectEqual(sorted(ids("capability")), idsOf("cli"), "the ids of the items with kind: capability");
|
|
324
|
-
expectEqual(sorted(ids("event")), eventIdsOf("cli"), "the ids of the items with kind: event");
|
|
325
|
-
expectEqual(entries.length, ids("capability").length + ids("event").length, "the number of items with a kind");
|
|
326
|
-
const firstEvent = entries.findIndex((entry) => entry.kind === "event");
|
|
327
|
-
expect(firstEvent === -1 || entries.slice(firstEvent).every((entry) => entry.kind === "event"), "the events must come after the capabilities");
|
|
328
|
-
});
|
|
329
|
-
check("list gives the usage of each capability and each event, with its flags", `${RULE}#commands`, async (signal) => {
|
|
330
|
-
const entries = await listed(signal);
|
|
331
|
-
for (const { id, kind, usage } of entries) {
|
|
332
|
-
expect(typeof usage === "string", `${id} must have a usage`);
|
|
333
|
-
const [program, ...rest] = usage.split(" ");
|
|
334
|
-
expect(program !== "" && rest.length > 0, `the usage of ${id} must start with the name of the program, got ${JSON.stringify(usage)}`);
|
|
335
|
-
expectEqual(rest.join(" "), kind === "event" ? EVENT_USAGES[id] : USAGES[id], `usage of ${id} after the name of the program`);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
checkHelp(check, command, listed);
|
|
339
|
-
checkAliases(check, command, listed);
|
|
340
|
-
checkWatch(check, command);
|
|
341
|
-
});
|
|
342
|
-
await checkWatchInterrupt(checks, command);
|
|
343
|
-
return checks;
|
|
344
|
-
}
|
|
345
|
-
function checkHelp(check, command, listed) {
|
|
346
|
-
const run = (signal, ...args) => start(command, args, signal).run;
|
|
347
|
-
const entry = (entries, id) => {
|
|
348
|
-
const found = entries.find((each) => each.id === id);
|
|
349
|
-
if (found === void 0 || typeof found.usage !== "string" || typeof found.description !== "string") throw new Error(`list must give ${id} with its usage and its description`);
|
|
350
|
-
return {
|
|
351
|
-
usage: found.usage,
|
|
352
|
-
description: found.description,
|
|
353
|
-
aliases: isArrayOf(found.aliases, (alias) => typeof alias === "string") ? found.aliases : []
|
|
354
|
-
};
|
|
355
|
-
};
|
|
356
|
-
const expectHelp = (result, usage, description) => {
|
|
357
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
358
|
-
expectEqual(result.stdout, `Usage: ${usage}\n\n${description}\n`, "standard output");
|
|
359
|
-
expectEqual(result.stderr, "", "standard error");
|
|
360
|
-
};
|
|
361
|
-
const commandList = (entries, prefix) => [
|
|
362
|
-
"Commands:",
|
|
363
|
-
...entries.filter((each) => each.kind === "capability" && each.id.startsWith(`${prefix}.`)).map((each) => ` ${String(each.usage)}`),
|
|
364
|
-
""
|
|
365
|
-
].join("\n");
|
|
366
|
-
check("--help after the path of a command writes the help of the capability", `${RULE}#commands`, async (signal) => {
|
|
367
|
-
const entries = await listed(signal);
|
|
368
|
-
const helps = ["fixture.raw", "fixture.switch.set"].map((id) => ({
|
|
369
|
-
id,
|
|
370
|
-
args: [...id.split("."), "--help"]
|
|
371
|
-
}));
|
|
372
|
-
helps.push({
|
|
373
|
-
id: "fixture.echo",
|
|
374
|
-
args: [
|
|
375
|
-
"fixture",
|
|
376
|
-
"echo",
|
|
377
|
-
"--text",
|
|
378
|
-
"hello",
|
|
379
|
-
"--help"
|
|
380
|
-
]
|
|
381
|
-
});
|
|
382
|
-
await Promise.all(helps.map(async ({ id, args }) => {
|
|
383
|
-
const { usage, description } = entry(entries, id);
|
|
384
|
-
expectHelp(await run(signal, ...args), usage, description);
|
|
385
|
-
}));
|
|
386
|
-
});
|
|
387
|
-
check("--help after the name of an alias writes the help of the alias", ALIASES, async (signal) => {
|
|
388
|
-
const entries = await listed(signal);
|
|
389
|
-
await Promise.all([
|
|
390
|
-
["say", "fixture.echo"],
|
|
391
|
-
["notes add", "fixture.note"],
|
|
392
|
-
["ticks", "fixture.ticks"]
|
|
393
|
-
].map(async ([name, id]) => {
|
|
394
|
-
const { aliases, description } = entry(entries, id);
|
|
395
|
-
const usage = aliases.find((each) => {
|
|
396
|
-
const rest = each.split(" ").slice(1).join(" ");
|
|
397
|
-
return rest === name || rest.startsWith(`${name} `);
|
|
398
|
-
});
|
|
399
|
-
expect(usage !== void 0, `list must give the usage of the alias ${name} of ${id}`);
|
|
400
|
-
expectHelp(await run(signal, ...name.split(" "), "--help"), usage, description);
|
|
401
|
-
}));
|
|
402
|
-
});
|
|
403
|
-
check("--help after watch and the id of an event writes the help of the event", `${RULE}#events`, async (signal) => {
|
|
404
|
-
const { usage, description } = entry(await listed(signal), "fixture.ticks");
|
|
405
|
-
expectHelp(await run(signal, "watch", "fixture.ticks", "--help"), usage, description);
|
|
406
|
-
});
|
|
407
|
-
check("--help after a shared prefix writes its command list to standard output", `${RULE}#commands`, async (signal) => {
|
|
408
|
-
const entries = await listed(signal);
|
|
409
|
-
const result = await run(signal, "fixture", "switch", "--help");
|
|
410
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
411
|
-
expectEqual(result.stdout, commandList(entries, "fixture.switch"), "standard output of fixture switch --help");
|
|
412
|
-
expectEqual(result.stderr, "", "standard error");
|
|
413
|
-
});
|
|
414
|
-
const expectUnknown = async (signal, ...args) => {
|
|
415
|
-
const entries = await listed(signal);
|
|
416
|
-
const result = await run(signal, ...args);
|
|
417
|
-
expectEqual(result.code, 2, "exit code");
|
|
418
|
-
expectEqual(result.stdout, "", "standard output");
|
|
419
|
-
expectEqual(result.stderr, commandList(entries, "fixture.switch"), "standard error");
|
|
420
|
-
};
|
|
421
|
-
check("a shared prefix alone writes its command list to standard error with exit code 2", `${RULE}#commands`, (signal) => expectUnknown(signal, "fixture", "switch"));
|
|
422
|
-
check("a shared prefix and a flag that is not --help write its command list to standard error with exit code 2", `${RULE}#commands`, (signal) => expectUnknown(signal, "fixture", "switch", "--on"));
|
|
423
|
-
}
|
|
424
|
-
function checkAliases(check, command, listed) {
|
|
425
|
-
const run = (signal, ...args) => start(command, args, signal).run;
|
|
426
|
-
const expectOutput = (result, expected) => {
|
|
427
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
428
|
-
const output = parseJson(result.stdout);
|
|
429
|
-
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
430
|
-
};
|
|
431
|
-
check("a command alias calls its capability with the flags", ALIASES, async (signal) => {
|
|
432
|
-
expectOutput(await run(signal, "say", "--text", "hi"), { text: "hi" });
|
|
433
|
-
});
|
|
434
|
-
check("a flag alias calls its capability with its fixed input", ALIASES, async (signal) => {
|
|
435
|
-
expectOutput(await run(signal, "--hello"), { text: "hello" });
|
|
436
|
-
});
|
|
437
|
-
check("the input of an alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
|
|
438
|
-
expectOutput(await run(signal, "quick", "--count", "2", "--steps", "1", "--steps", "2"), {
|
|
439
|
-
mode: "fast",
|
|
440
|
-
count: 2,
|
|
441
|
-
steps: [1, 2]
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
check("an alias of a capability whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
445
|
-
expectOutput(await run(signal, "raw", "{\"a\":[1]}"), { a: [1] });
|
|
446
|
-
expectOutput(await run(signal, "raw"), {});
|
|
447
|
-
});
|
|
448
|
-
check("the flags of an alias come from the type that the $ref of the input schema refers to, whatever other keys it has", ALIASES, async (signal) => {
|
|
449
|
-
expectOutput(await run(signal, "fixed-note"), { text: "fixed" });
|
|
450
|
-
expectOutput(await run(signal, "fixed-note", "--loud"), {
|
|
451
|
-
text: "fixed",
|
|
452
|
-
loud: true
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
check("an alias of a capability with no input takes no argument", ALIASES, async (signal) => {
|
|
456
|
-
const result = await run(signal, "held-keys");
|
|
457
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
458
|
-
expect(isArrayOf(memberOf(parseJson(result.stdout), "keys"), (key) => typeof key === "string"), `standard output must have the keys, got ${result.stdout}`);
|
|
459
|
-
});
|
|
460
|
-
check("a two-word alias calls its capability with the flags", ALIASES, async (signal) => {
|
|
461
|
-
expectOutput(await run(signal, "notes", "add", "--text", "hi"), { text: "hi" });
|
|
462
|
-
});
|
|
463
|
-
check("the input of a two-word alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
|
|
464
|
-
expectOutput(await run(signal, "notes", "loud", "--text", "hi"), {
|
|
465
|
-
text: "hi",
|
|
466
|
-
loud: true
|
|
467
|
-
});
|
|
468
|
-
expectOutput(await run(signal, "shout", "hello"), { text: "HELLO" });
|
|
469
|
-
});
|
|
470
|
-
check("a one-word alias runs when the second argument is not the second word of a two-word alias", ALIASES, async (signal) => {
|
|
471
|
-
expectOutput(await run(signal, "notes"), {});
|
|
472
|
-
expectOutput(await run(signal, "notes", "{\"a\":1}"), { a: 1 });
|
|
473
|
-
});
|
|
474
|
-
check("an alias that is the default of a shared prefix runs with the prefix alone, and with flags", ALIASES, async (signal) => {
|
|
475
|
-
expectOutput(await run(signal, "fixture"), { mode: "slow" });
|
|
476
|
-
expectOutput(await run(signal, "fixture", "--count", "2"), {
|
|
477
|
-
mode: "slow",
|
|
478
|
-
count: 2
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
check("a command under a shared prefix with a default alias keeps its path", ALIASES, async (signal) => {
|
|
482
|
-
expectOutput(await run(signal, "fixture", "echo", "--text", "hi"), { text: "hi" });
|
|
483
|
-
});
|
|
484
|
-
const ticks = async (signal, ...args) => {
|
|
485
|
-
const result = await run(signal, "ticks", ...args);
|
|
486
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
487
|
-
return occurrencesIn(result.stdout, "fixture.ticks");
|
|
488
|
-
};
|
|
489
|
-
const tickData = async (signal, ...args) => (await ticks(signal, ...args)).map((occurrence) => occurrence.data);
|
|
490
|
-
check("an alias of an event subscribes with its fixed input, and takes --cursor, --max-age-ms and a flag value in the form --name=value", ALIASES, async (signal) => {
|
|
491
|
-
expectEqual(await tickData(signal), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
492
|
-
expectEqual(await tickData(signal, "--cursor", "1", "--max-age-ms", "60000", "--key=--cursor"), [{ n: 2 }], "the data of the occurrences after the cursor 1, with the key --cursor");
|
|
493
|
-
});
|
|
494
|
-
check("an alias of an event takes the flags of the input of its event", ALIASES, async (signal) => {
|
|
495
|
-
expectEqual((await ticks(signal, "--gap", "2")).map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [[{ n: 1 }, null], [{ n: 2 }, true]], "the data and truncated of the occurrences");
|
|
496
|
-
});
|
|
497
|
-
check("an alias of an event whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
498
|
-
const echoes = async (...args) => {
|
|
499
|
-
const result = await run(signal, "echoes", ...args);
|
|
500
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
501
|
-
return occurrencesIn(result.stdout, "fixture.echoes").map((occurrence) => occurrence.data);
|
|
502
|
-
};
|
|
503
|
-
expectEqual(await echoes("{\"a\":1}"), [{ a: 1 }], "the data of the occurrences");
|
|
504
|
-
expectEqual(await echoes(), [{}], "the data of the occurrences with no input");
|
|
505
|
-
});
|
|
506
|
-
check("an alias of an event writes internal to standard error with exit code 5 after a defect", ALIASES, async (signal) => {
|
|
507
|
-
const result = await run(signal, "broken-ticks");
|
|
508
|
-
expectEqual(result.code, 5, "exit code");
|
|
509
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
510
|
-
expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
|
|
511
|
-
});
|
|
512
|
-
check("the default alias runs with no arguments", ALIASES, async (signal) => {
|
|
513
|
-
expectOutput(await run(signal), { mode: "fast" });
|
|
514
|
-
});
|
|
515
|
-
check("the default alias takes the flags when the first argument is a flag", ALIASES, async (signal) => {
|
|
516
|
-
expectOutput(await run(signal, "--count", "2", "--verbose"), {
|
|
517
|
-
mode: "fast",
|
|
518
|
-
count: 2,
|
|
519
|
-
verbose: true
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
check("--help writes the help, and does not run the default alias", ALIASES, async (signal) => {
|
|
523
|
-
const result = await run(signal, "--help");
|
|
524
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
525
|
-
expectEqual(result.stderr, "", "standard error");
|
|
526
|
-
expect(result.stdout.trim() !== "", "standard output must have the help");
|
|
527
|
-
expect(!result.stdout.trimStart().startsWith("{"), `standard output must be the help, not the output of the default alias, got ${JSON.stringify(result.stdout)}`);
|
|
528
|
-
});
|
|
529
|
-
for (const [name, args, code] of [
|
|
530
|
-
[
|
|
531
|
-
"a flag of a property of the fixed input has exit code 3",
|
|
532
|
-
[
|
|
533
|
-
"quick",
|
|
534
|
-
"--mode",
|
|
535
|
-
"slow"
|
|
536
|
-
],
|
|
537
|
-
3
|
|
538
|
-
],
|
|
539
|
-
[
|
|
540
|
-
"a flag of a property of the fixed input of an alias of an event has exit code 3",
|
|
541
|
-
[
|
|
542
|
-
"ticks",
|
|
543
|
-
"--count",
|
|
544
|
-
"3"
|
|
545
|
-
],
|
|
546
|
-
3
|
|
547
|
-
],
|
|
548
|
-
[
|
|
549
|
-
"a flag that the default alias does not have has exit code 3",
|
|
550
|
-
["--nothing"],
|
|
551
|
-
3
|
|
552
|
-
],
|
|
553
|
-
[
|
|
554
|
-
"a missing required flag of an alias has exit code 3",
|
|
555
|
-
["say"],
|
|
556
|
-
3
|
|
557
|
-
],
|
|
558
|
-
[
|
|
559
|
-
"an alias with input that is not JSON has exit code 3",
|
|
560
|
-
["raw", "{"],
|
|
561
|
-
3
|
|
562
|
-
],
|
|
563
|
-
[
|
|
564
|
-
"an alias of an event with input that is not JSON has exit code 3",
|
|
565
|
-
["echoes", "{"],
|
|
566
|
-
3
|
|
567
|
-
],
|
|
568
|
-
[
|
|
569
|
-
"JSON text to an alias of a capability whose input schema refers to a type with properties has exit code 3",
|
|
570
|
-
["fixed-note", "{\"text\":\"override\"}"],
|
|
571
|
-
3
|
|
572
|
-
],
|
|
573
|
-
[
|
|
574
|
-
"an argument to an alias of a capability with no input has exit code 3",
|
|
575
|
-
["held-keys", "{}"],
|
|
576
|
-
3
|
|
577
|
-
]
|
|
578
|
-
]) check(name, ALIASES, async (signal) => {
|
|
579
|
-
expectEqual((await run(signal, ...args)).code, code, "exit code");
|
|
580
|
-
});
|
|
581
|
-
check("list gives the usage of the aliases of each capability", ALIASES, async (signal) => {
|
|
582
|
-
const entries = await listed(signal);
|
|
583
|
-
for (const { id, kind, aliases } of entries) {
|
|
584
|
-
const expected = kind === "capability" ? ALIAS_USAGES[id] : EVENT_ALIAS_USAGES[id];
|
|
585
|
-
if (expected === void 0) {
|
|
586
|
-
expect(aliases === void 0, `${id} has no alias, so its item must not have aliases, got ${JSON.stringify(aliases)}`);
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
expect(isArrayOf(aliases, (usage) => typeof usage === "string"), `the aliases of ${id} must be a list of strings, got ${JSON.stringify(aliases)}`);
|
|
590
|
-
const rest = aliases.map((usage) => usage.split(" ").slice(1).join(" "));
|
|
591
|
-
expectEqual(rest, expected, `the usage of the aliases of ${id} after the name of the program`);
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
const EVENTS = `${RULE}#events`;
|
|
596
|
-
function checkWatch(check, command) {
|
|
597
|
-
const run = (signal, ...args) => start(command, args, signal).run;
|
|
598
|
-
check("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS, async (signal) => {
|
|
599
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "2");
|
|
600
|
-
expectEqual(result.code, 0, "exit code");
|
|
601
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
602
|
-
expectEqual(result.stderr, "", "standard error");
|
|
603
|
-
});
|
|
604
|
-
check("watch with --cursor starts after the cursor, and takes a flag value that starts with - in the form --name=value", EVENTS, async (signal) => {
|
|
605
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--cursor", "1", "--max-age-ms", "60000", "--key=--cursor");
|
|
606
|
-
expectEqual(result.code, 0, "exit code");
|
|
607
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.cursor]), [[{ n: 2 }, "2"], [{ n: 3 }, "3"]], "the data and the cursor of the occurrences");
|
|
608
|
-
});
|
|
609
|
-
check("watch writes an occurrence after a gap with truncated: true", EVENTS, async (signal) => {
|
|
610
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--gap", "2");
|
|
611
|
-
expectEqual(result.code, 0, "exit code");
|
|
612
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [
|
|
613
|
-
[{ n: 1 }, null],
|
|
614
|
-
[{ n: 2 }, true],
|
|
615
|
-
[{ n: 3 }, null]
|
|
616
|
-
], "the data and truncated of the occurrences");
|
|
617
|
-
});
|
|
618
|
-
check("watch writes internal to standard error with exit code 5 after a defect", EVENTS, async (signal) => {
|
|
619
|
-
const result = await run(signal, "watch", "fixture.broken");
|
|
620
|
-
expectEqual(result.code, 5, "exit code");
|
|
621
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
622
|
-
expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
|
|
623
|
-
});
|
|
624
|
-
for (const [name, args, code] of [
|
|
625
|
-
[
|
|
626
|
-
"watch with no event id has exit code 3",
|
|
627
|
-
["watch"],
|
|
628
|
-
3
|
|
629
|
-
],
|
|
630
|
-
[
|
|
631
|
-
"watch with invalid input has exit code 3",
|
|
632
|
-
[
|
|
633
|
-
"watch",
|
|
634
|
-
"fixture.ticks",
|
|
635
|
-
"--count",
|
|
636
|
-
"101"
|
|
637
|
-
],
|
|
638
|
-
3
|
|
639
|
-
],
|
|
640
|
-
[
|
|
641
|
-
"watch with a missing required flag has exit code 3",
|
|
642
|
-
["watch", "fixture.ticks"],
|
|
643
|
-
3
|
|
644
|
-
],
|
|
645
|
-
[
|
|
646
|
-
"watch with an unknown flag has exit code 3",
|
|
647
|
-
[
|
|
648
|
-
"watch",
|
|
649
|
-
"fixture.ticks",
|
|
650
|
-
"--count",
|
|
651
|
-
"1",
|
|
652
|
-
"--nope",
|
|
653
|
-
"x"
|
|
654
|
-
],
|
|
655
|
-
3
|
|
656
|
-
],
|
|
657
|
-
[
|
|
658
|
-
"watch of an event outside the target has exit code 2",
|
|
659
|
-
["watch", "fixture.secret"],
|
|
660
|
-
2
|
|
661
|
-
],
|
|
662
|
-
[
|
|
663
|
-
"watch with a --max-age-ms that is not an integer has exit code 3",
|
|
664
|
-
[
|
|
665
|
-
"watch",
|
|
666
|
-
"fixture.ticks",
|
|
667
|
-
"--count",
|
|
668
|
-
"1",
|
|
669
|
-
"--max-age-ms",
|
|
670
|
-
"soon"
|
|
671
|
-
],
|
|
672
|
-
3
|
|
673
|
-
],
|
|
674
|
-
[
|
|
675
|
-
"watch with a --max-age-ms that is a fraction has exit code 3",
|
|
676
|
-
[
|
|
677
|
-
"watch",
|
|
678
|
-
"fixture.ticks",
|
|
679
|
-
"--count",
|
|
680
|
-
"1",
|
|
681
|
-
"--max-age-ms",
|
|
682
|
-
"1.5"
|
|
683
|
-
],
|
|
684
|
-
3
|
|
685
|
-
]
|
|
686
|
-
]) check(name, EVENTS, async (signal) => {
|
|
687
|
-
await expectUsageError(run(signal, ...args), code);
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
async function checkWatchInterrupt(checks, command) {
|
|
691
|
-
await checks.run("an interrupt cancels watch with exit code 130", EVENTS, async (signal) => {
|
|
692
|
-
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
693
|
-
const marker = join(directory, "watching");
|
|
694
|
-
try {
|
|
695
|
-
const { child, run: watched } = start(command, [
|
|
696
|
-
"watch",
|
|
697
|
-
"fixture.watch",
|
|
698
|
-
"--key",
|
|
699
|
-
"interrupt",
|
|
700
|
-
"--marker",
|
|
701
|
-
marker
|
|
702
|
-
], signal);
|
|
703
|
-
const ended = () => child.exitCode !== null || child.signalCode !== null;
|
|
704
|
-
const state = await until("the subscription writes its marker file", async () => existsSync(marker) ? "marked" : ended() ? "ended" : "waiting", (each) => each !== "waiting", signal);
|
|
705
|
-
if (state === "marked") child.kill("SIGINT");
|
|
706
|
-
const result = await watched;
|
|
707
|
-
expect(state === "marked", `the subscription must start before the interrupt, but the command line ended with ${result.code}: ${result.stderr}`);
|
|
708
|
-
expect(result.signal === null, `the process must exit, not end by the signal ${result.signal}`);
|
|
709
|
-
expectEqual(result.code, 130, "exit code");
|
|
710
|
-
expectEqual(result.stdout, "", "standard output");
|
|
711
|
-
expectEqual(result.stderr, "", "standard error");
|
|
712
|
-
await until("the subscription ends and deletes its marker file", async () => !existsSync(marker), (ended) => ended, signal);
|
|
713
|
-
} finally {
|
|
714
|
-
await rm(directory, {
|
|
715
|
-
recursive: true,
|
|
716
|
-
force: true
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
export { checkCli };
|