@acid-cat/cli 0.13.1 → 0.15.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 +65 -28
- package/conformance/fixture.acidcat.json +30 -2
- package/dist/catalog.js +4 -1
- package/dist/conform/check.d.ts +6 -2
- package/dist/conform/check.js +22 -3
- package/dist/conform/cli.js +356 -203
- package/dist/conform/http.js +10 -21
- package/dist/conform/index.d.ts +9 -1
- package/dist/conform/index.js +8 -2
- package/dist/conform/mcp-stdio.js +1 -19
- package/dist/conform/mcp.js +18 -21
- package/dist/conform/poll.d.ts +3 -3
- package/dist/conform/poll.js +51 -26
- package/dist/conform/properties.d.ts +0 -1
- package/dist/conform/properties.js +1 -1
- package/dist/conform/webhook.d.ts +4 -1
- package/dist/conform/webhook.js +20 -8
- package/dist/conform/webmcp.js +0 -5
- package/dist/json/catalog.schema.json.js +4 -2
- package/dist/json/fixture.acidcat.json.js +20 -2
- package/dist/json/package.json.js +1 -1
- package/dist/main.js +11 -5
- package/package.json +3 -3
package/dist/conform/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isArrayOf, isObject, memberOf, parseJson } from "../json.js";
|
|
2
|
-
import { Checks, eventIdsOf, expect, expectEqual, expectOccurrence, idsOf, sorted, until } from "./check.js";
|
|
2
|
+
import { Checks, abortable, eventIdsOf, expect, expectEqual, expectOccurrence, idsOf, sorted, until } from "./check.js";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
3
4
|
import { spawn } from "node:child_process";
|
|
4
5
|
import { existsSync } from "node:fs";
|
|
5
6
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { isDeepStrictEqual } from "node:util";
|
|
9
9
|
// src/conform/cli.ts
|
|
@@ -30,11 +30,19 @@ const EVENT_USAGES = {
|
|
|
30
30
|
"fixture.watch": "watch fixture.watch --key <string> [--marker <string>] [--cursor <string>] [--max-age-ms <integer>]"
|
|
31
31
|
};
|
|
32
32
|
const ALIAS_USAGES = {
|
|
33
|
-
"fixture.echo": [
|
|
34
|
-
|
|
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]"],
|
|
35
39
|
"fixture.held": ["held-keys"],
|
|
36
|
-
"fixture.note": [
|
|
37
|
-
|
|
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>'"]
|
|
38
46
|
};
|
|
39
47
|
const EVENT_ALIAS_USAGES = {
|
|
40
48
|
"fixture.broken": ["broken-ticks [--cursor <string>] [--max-age-ms <integer>]"],
|
|
@@ -94,103 +102,132 @@ function occurrencesIn(stdout, id) {
|
|
|
94
102
|
async function checkCli(command, options) {
|
|
95
103
|
const checks = new Checks("cli", options.deadline);
|
|
96
104
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
],
|
|
118
|
-
[
|
|
119
|
-
"a shared prefix alone has exit code 2",
|
|
120
|
-
["fixture"],
|
|
121
|
-
2
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
"a capability outside the view has exit code 2",
|
|
125
|
-
["call", "fixture.hidden"],
|
|
126
|
-
2
|
|
127
|
-
],
|
|
128
|
-
[
|
|
129
|
-
"a missing required flag has exit code 3",
|
|
130
|
-
["fixture", "echo"],
|
|
131
|
-
3
|
|
132
|
-
],
|
|
133
|
-
[
|
|
134
|
-
"an unknown flag has exit code 3",
|
|
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 [
|
|
135
125
|
[
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
"hello",
|
|
140
|
-
"--nope",
|
|
141
|
-
"x"
|
|
126
|
+
"an unknown command has exit code 2",
|
|
127
|
+
["nothing"],
|
|
128
|
+
2
|
|
142
129
|
],
|
|
143
|
-
3
|
|
144
|
-
],
|
|
145
|
-
[
|
|
146
|
-
"a flag that is not valid has exit code 3",
|
|
147
130
|
[
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
"fast",
|
|
152
|
-
"--ratio",
|
|
153
|
-
"soon"
|
|
131
|
+
"an unknown word after an alias that is the default of a shared prefix has exit code 2",
|
|
132
|
+
["fixture", "nope"],
|
|
133
|
+
2
|
|
154
134
|
],
|
|
155
|
-
3
|
|
156
|
-
],
|
|
157
|
-
[
|
|
158
|
-
"an item of a repeated flag that is not valid has exit code 3",
|
|
159
135
|
[
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
|
|
163
|
-
"fast",
|
|
164
|
-
"--steps",
|
|
165
|
-
"1",
|
|
166
|
-
"--steps",
|
|
167
|
-
"soon"
|
|
136
|
+
"the first word of two-word aliases alone, with no one-word alias, has exit code 2",
|
|
137
|
+
["shout"],
|
|
138
|
+
2
|
|
168
139
|
],
|
|
169
|
-
3
|
|
170
|
-
],
|
|
171
|
-
[
|
|
172
|
-
"an item of a repeated flag as JSON text that is not valid has exit code 3",
|
|
173
140
|
[
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
|
|
177
|
-
"fast",
|
|
178
|
-
"--steps",
|
|
179
|
-
"[1,\"soon\"]"
|
|
141
|
+
"an unknown second word after the first word of two-word aliases has exit code 2",
|
|
142
|
+
["shout", "nope"],
|
|
143
|
+
2
|
|
180
144
|
],
|
|
181
|
-
3
|
|
182
|
-
],
|
|
183
|
-
[
|
|
184
|
-
"invalid input through call has exit code 3",
|
|
185
145
|
[
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
|
|
146
|
+
"an unknown second word after a one-word alias with two-word aliases has exit code 2",
|
|
147
|
+
["notes", "nope"],
|
|
148
|
+
2
|
|
189
149
|
],
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
150
|
+
[
|
|
151
|
+
"a capability outside the view has exit code 2",
|
|
152
|
+
["call", "fixture.hidden"],
|
|
153
|
+
2
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"a capability outside the view 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
|
+
});
|
|
194
231
|
});
|
|
195
232
|
await checks.run("an interrupt cancels the call with exit code 130", `${RULE}#commands`, async (signal) => {
|
|
196
233
|
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
@@ -220,138 +257,244 @@ async function checkCli(command, options) {
|
|
|
220
257
|
});
|
|
221
258
|
}
|
|
222
259
|
});
|
|
223
|
-
await checks.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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 view: the capabilities, then the 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);
|
|
259
341
|
});
|
|
260
|
-
await checks
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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 : []
|
|
268
354
|
};
|
|
269
|
-
|
|
270
|
-
|
|
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
|
+
}));
|
|
271
386
|
});
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const entries = entriesOf((await run(signal, "list")).stdout);
|
|
288
|
-
for (const { id, kind, usage } of entries) {
|
|
289
|
-
expect(typeof usage === "string", `${id} must have a usage`);
|
|
290
|
-
const [program, ...rest] = usage.split(" ");
|
|
291
|
-
expect(program !== "" && rest.length > 0, `the usage of ${id} must start with the name of the program, got ${JSON.stringify(usage)}`);
|
|
292
|
-
expectEqual(rest.join(" "), kind === "event" ? EVENT_USAGES[id] : USAGES[id], `usage of ${id} after the name of the program`);
|
|
293
|
-
}
|
|
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
|
+
}));
|
|
294
402
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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"));
|
|
298
423
|
}
|
|
299
|
-
|
|
424
|
+
function checkAliases(check, command, listed) {
|
|
300
425
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
301
426
|
const expectOutput = (result, expected) => {
|
|
302
427
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
303
428
|
const output = parseJson(result.stdout);
|
|
304
429
|
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
305
430
|
};
|
|
306
|
-
|
|
431
|
+
check("a command alias calls its capability with the flags", ALIASES, async (signal) => {
|
|
307
432
|
expectOutput(await run(signal, "say", "--text", "hi"), { text: "hi" });
|
|
308
433
|
});
|
|
309
|
-
|
|
434
|
+
check("a flag alias calls its capability with its fixed input", ALIASES, async (signal) => {
|
|
310
435
|
expectOutput(await run(signal, "--hello"), { text: "hello" });
|
|
311
436
|
});
|
|
312
|
-
|
|
437
|
+
check("the input of an alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
|
|
313
438
|
expectOutput(await run(signal, "quick", "--count", "2", "--steps", "1", "--steps", "2"), {
|
|
314
439
|
mode: "fast",
|
|
315
440
|
count: 2,
|
|
316
441
|
steps: [1, 2]
|
|
317
442
|
});
|
|
318
443
|
});
|
|
319
|
-
|
|
444
|
+
check("an alias of a capability whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
320
445
|
expectOutput(await run(signal, "raw", "{\"a\":[1]}"), { a: [1] });
|
|
321
446
|
expectOutput(await run(signal, "raw"), {});
|
|
322
447
|
});
|
|
323
|
-
|
|
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) => {
|
|
324
449
|
expectOutput(await run(signal, "fixed-note"), { text: "fixed" });
|
|
325
450
|
expectOutput(await run(signal, "fixed-note", "--loud"), {
|
|
326
451
|
text: "fixed",
|
|
327
452
|
loud: true
|
|
328
453
|
});
|
|
329
454
|
});
|
|
330
|
-
|
|
455
|
+
check("an alias of a capability with no input takes no argument", ALIASES, async (signal) => {
|
|
331
456
|
const result = await run(signal, "held-keys");
|
|
332
457
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
333
458
|
expect(isArrayOf(memberOf(parseJson(result.stdout), "keys"), (key) => typeof key === "string"), `standard output must have the keys, got ${result.stdout}`);
|
|
334
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
|
+
});
|
|
335
484
|
const ticks = async (signal, ...args) => {
|
|
336
485
|
const result = await run(signal, "ticks", ...args);
|
|
337
486
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
338
487
|
return occurrencesIn(result.stdout, "fixture.ticks");
|
|
339
488
|
};
|
|
340
489
|
const tickData = async (signal, ...args) => (await ticks(signal, ...args)).map((occurrence) => occurrence.data);
|
|
341
|
-
|
|
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) => {
|
|
342
491
|
expectEqual(await tickData(signal), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
343
|
-
expectEqual(await tickData(signal, "--cursor", "1"), [{ n: 2 }], "the data of the occurrences after the cursor 1");
|
|
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");
|
|
344
493
|
});
|
|
345
|
-
|
|
494
|
+
check("an alias of an event takes the flags of the input of its event", ALIASES, async (signal) => {
|
|
346
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");
|
|
347
496
|
});
|
|
348
|
-
|
|
349
|
-
expectEqual(await tickData(signal, "--max-age-ms", "60000"), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
350
|
-
});
|
|
351
|
-
await checks.run("an alias of an event takes a flag value that starts with - in the form --name=value", ALIASES, async (signal) => {
|
|
352
|
-
expectEqual(await tickData(signal, "--key=--cursor"), [{ n: 1 }, { n: 2 }], "the data of the occurrences with the key --cursor");
|
|
353
|
-
});
|
|
354
|
-
await checks.run("an alias of an event whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
497
|
+
check("an alias of an event whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
355
498
|
const echoes = async (...args) => {
|
|
356
499
|
const result = await run(signal, "echoes", ...args);
|
|
357
500
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
@@ -360,27 +503,28 @@ async function checkAliases(checks, command) {
|
|
|
360
503
|
expectEqual(await echoes("{\"a\":1}"), [{ a: 1 }], "the data of the occurrences");
|
|
361
504
|
expectEqual(await echoes(), [{}], "the data of the occurrences with no input");
|
|
362
505
|
});
|
|
363
|
-
|
|
506
|
+
check("an alias of an event writes internal to standard error with exit code 5 after a defect", ALIASES, async (signal) => {
|
|
364
507
|
const result = await run(signal, "broken-ticks");
|
|
365
508
|
expectEqual(result.code, 5, "exit code");
|
|
366
509
|
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
367
510
|
expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
|
|
368
511
|
});
|
|
369
|
-
|
|
512
|
+
check("the default alias runs with no arguments", ALIASES, async (signal) => {
|
|
370
513
|
expectOutput(await run(signal), { mode: "fast" });
|
|
371
514
|
});
|
|
372
|
-
|
|
515
|
+
check("the default alias takes the flags when the first argument is a flag", ALIASES, async (signal) => {
|
|
373
516
|
expectOutput(await run(signal, "--count", "2", "--verbose"), {
|
|
374
517
|
mode: "fast",
|
|
375
518
|
count: 2,
|
|
376
519
|
verbose: true
|
|
377
520
|
});
|
|
378
|
-
expectOutput(await run(signal, "--hello"), { text: "hello" });
|
|
379
521
|
});
|
|
380
|
-
|
|
522
|
+
check("--help writes the help, and does not run the default alias", ALIASES, async (signal) => {
|
|
381
523
|
const result = await run(signal, "--help");
|
|
382
|
-
expectEqual(result.code, 0,
|
|
383
|
-
|
|
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)}`);
|
|
384
528
|
});
|
|
385
529
|
for (const [name, args, code] of [
|
|
386
530
|
[
|
|
@@ -431,11 +575,11 @@ async function checkAliases(checks, command) {
|
|
|
431
575
|
["held-keys", "{}"],
|
|
432
576
|
3
|
|
433
577
|
]
|
|
434
|
-
])
|
|
578
|
+
]) check(name, ALIASES, async (signal) => {
|
|
435
579
|
expectEqual((await run(signal, ...args)).code, code, "exit code");
|
|
436
580
|
});
|
|
437
|
-
|
|
438
|
-
const entries =
|
|
581
|
+
check("list gives the usage of the aliases of each capability", ALIASES, async (signal) => {
|
|
582
|
+
const entries = await listed(signal);
|
|
439
583
|
for (const { id, kind, aliases } of entries) {
|
|
440
584
|
const expected = kind === "capability" ? ALIAS_USAGES[id] : EVENT_ALIAS_USAGES[id];
|
|
441
585
|
if (expected === void 0) {
|
|
@@ -449,25 +593,20 @@ async function checkAliases(checks, command) {
|
|
|
449
593
|
});
|
|
450
594
|
}
|
|
451
595
|
const EVENTS = `${RULE}#events`;
|
|
452
|
-
|
|
596
|
+
function checkWatch(check, command) {
|
|
453
597
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
454
|
-
|
|
598
|
+
check("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS, async (signal) => {
|
|
455
599
|
const result = await run(signal, "watch", "fixture.ticks", "--count", "2");
|
|
456
600
|
expectEqual(result.code, 0, "exit code");
|
|
457
601
|
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
458
602
|
expectEqual(result.stderr, "", "standard error");
|
|
459
603
|
});
|
|
460
|
-
|
|
461
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--cursor", "1", "--max-age-ms", "60000");
|
|
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");
|
|
462
606
|
expectEqual(result.code, 0, "exit code");
|
|
463
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");
|
|
464
608
|
});
|
|
465
|
-
|
|
466
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "1", "--key=--cursor");
|
|
467
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
468
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
469
|
-
});
|
|
470
|
-
await checks.run("watch writes an occurrence after a gap with truncated: true", EVENTS, async (signal) => {
|
|
609
|
+
check("watch writes an occurrence after a gap with truncated: true", EVENTS, async (signal) => {
|
|
471
610
|
const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--gap", "2");
|
|
472
611
|
expectEqual(result.code, 0, "exit code");
|
|
473
612
|
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [
|
|
@@ -476,7 +615,7 @@ async function checkWatch(checks, command) {
|
|
|
476
615
|
[{ n: 3 }, null]
|
|
477
616
|
], "the data and truncated of the occurrences");
|
|
478
617
|
});
|
|
479
|
-
|
|
618
|
+
check("watch writes internal to standard error with exit code 5 after a defect", EVENTS, async (signal) => {
|
|
480
619
|
const result = await run(signal, "watch", "fixture.broken");
|
|
481
620
|
expectEqual(result.code, 5, "exit code");
|
|
482
621
|
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
@@ -503,6 +642,18 @@ async function checkWatch(checks, command) {
|
|
|
503
642
|
["watch", "fixture.ticks"],
|
|
504
643
|
3
|
|
505
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
|
+
],
|
|
506
657
|
[
|
|
507
658
|
"watch of an event outside the view has exit code 2",
|
|
508
659
|
["watch", "fixture.secret"],
|
|
@@ -532,9 +683,11 @@ async function checkWatch(checks, command) {
|
|
|
532
683
|
],
|
|
533
684
|
3
|
|
534
685
|
]
|
|
535
|
-
])
|
|
686
|
+
]) check(name, EVENTS, async (signal) => {
|
|
536
687
|
await expectUsageError(run(signal, ...args), code);
|
|
537
688
|
});
|
|
689
|
+
}
|
|
690
|
+
async function checkWatchInterrupt(checks, command) {
|
|
538
691
|
await checks.run("an interrupt cancels watch with exit code 130", EVENTS, async (signal) => {
|
|
539
692
|
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
540
693
|
const marker = join(directory, "watching");
|