@acid-cat/cli 0.14.0 → 0.16.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 +64 -32
- package/dist/conform/check.d.ts +6 -2
- package/dist/conform/check.js +22 -3
- package/dist/conform/cli.js +283 -253
- 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 +10 -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/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
|
|
@@ -102,123 +102,132 @@ function occurrencesIn(stdout, id) {
|
|
|
102
102
|
async function checkCli(command, options) {
|
|
103
103
|
const checks = new Checks("cli", options.deadline);
|
|
104
104
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
[
|
|
127
|
-
"a shared prefix alone has exit code 2",
|
|
128
|
-
["fixture", "switch"],
|
|
129
|
-
2
|
|
130
|
-
],
|
|
131
|
-
[
|
|
132
|
-
"an unknown word after an alias that is the default of a shared prefix has exit code 2",
|
|
133
|
-
["fixture", "nope"],
|
|
134
|
-
2
|
|
135
|
-
],
|
|
136
|
-
[
|
|
137
|
-
"the first word of two-word aliases alone, with no one-word alias, has exit code 2",
|
|
138
|
-
["shout"],
|
|
139
|
-
2
|
|
140
|
-
],
|
|
141
|
-
[
|
|
142
|
-
"an unknown second word after the first word of two-word aliases has exit code 2",
|
|
143
|
-
["shout", "nope"],
|
|
144
|
-
2
|
|
145
|
-
],
|
|
146
|
-
[
|
|
147
|
-
"an unknown second word after a one-word alias with two-word aliases has exit code 2",
|
|
148
|
-
["notes", "nope"],
|
|
149
|
-
2
|
|
150
|
-
],
|
|
151
|
-
[
|
|
152
|
-
"a capability outside the view has exit code 2",
|
|
153
|
-
["call", "fixture.hidden"],
|
|
154
|
-
2
|
|
155
|
-
],
|
|
156
|
-
[
|
|
157
|
-
"a missing required flag has exit code 3",
|
|
158
|
-
["fixture", "echo"],
|
|
159
|
-
3
|
|
160
|
-
],
|
|
161
|
-
[
|
|
162
|
-
"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 [
|
|
163
125
|
[
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
|
|
167
|
-
"hello",
|
|
168
|
-
"--nope",
|
|
169
|
-
"x"
|
|
126
|
+
"an unknown command has exit code 2",
|
|
127
|
+
["nothing"],
|
|
128
|
+
2
|
|
170
129
|
],
|
|
171
|
-
3
|
|
172
|
-
],
|
|
173
|
-
[
|
|
174
|
-
"a flag that is not valid has exit code 3",
|
|
175
130
|
[
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
|
|
179
|
-
"fast",
|
|
180
|
-
"--ratio",
|
|
181
|
-
"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
|
|
182
134
|
],
|
|
183
|
-
3
|
|
184
|
-
],
|
|
185
|
-
[
|
|
186
|
-
"an item of a repeated flag that is not valid has exit code 3",
|
|
187
135
|
[
|
|
188
|
-
"
|
|
189
|
-
"
|
|
190
|
-
|
|
191
|
-
"fast",
|
|
192
|
-
"--steps",
|
|
193
|
-
"1",
|
|
194
|
-
"--steps",
|
|
195
|
-
"soon"
|
|
136
|
+
"the first word of two-word aliases alone, with no one-word alias, has exit code 2",
|
|
137
|
+
["shout"],
|
|
138
|
+
2
|
|
196
139
|
],
|
|
197
|
-
3
|
|
198
|
-
],
|
|
199
|
-
[
|
|
200
|
-
"an item of a repeated flag as JSON text that is not valid has exit code 3",
|
|
201
140
|
[
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
|
|
205
|
-
"fast",
|
|
206
|
-
"--steps",
|
|
207
|
-
"[1,\"soon\"]"
|
|
141
|
+
"an unknown second word after the first word of two-word aliases has exit code 2",
|
|
142
|
+
["shout", "nope"],
|
|
143
|
+
2
|
|
208
144
|
],
|
|
209
|
-
3
|
|
210
|
-
],
|
|
211
|
-
[
|
|
212
|
-
"invalid input through call has exit code 3",
|
|
213
145
|
[
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
|
|
146
|
+
"an unknown second word after a one-word alias with two-word aliases has exit code 2",
|
|
147
|
+
["notes", "nope"],
|
|
148
|
+
2
|
|
217
149
|
],
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
});
|
|
222
231
|
});
|
|
223
232
|
await checks.run("an interrupt cancels the call with exit code 130", `${RULE}#commands`, async (signal) => {
|
|
224
233
|
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
@@ -248,86 +257,93 @@ async function checkCli(command, options) {
|
|
|
248
257
|
});
|
|
249
258
|
}
|
|
250
259
|
});
|
|
251
|
-
await checks.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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);
|
|
322
341
|
});
|
|
323
|
-
await
|
|
324
|
-
await checkAliases(checks, command);
|
|
325
|
-
await checkWatch(checks, command);
|
|
342
|
+
await checkWatchInterrupt(checks, command);
|
|
326
343
|
return checks;
|
|
327
344
|
}
|
|
328
|
-
|
|
345
|
+
function checkHelp(check, command, listed) {
|
|
329
346
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
330
|
-
const listed = async (signal) => entriesOf((await run(signal, "list")).stdout);
|
|
331
347
|
const entry = (entries, id) => {
|
|
332
348
|
const found = entries.find((each) => each.id === id);
|
|
333
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`);
|
|
@@ -347,33 +363,48 @@ async function checkHelp(checks, command) {
|
|
|
347
363
|
...entries.filter((each) => each.kind === "capability" && each.id.startsWith(`${prefix}.`)).map((each) => ` ${String(each.usage)}`),
|
|
348
364
|
""
|
|
349
365
|
].join("\n");
|
|
350
|
-
|
|
366
|
+
check("--help after the path of a command writes the help of the capability", `${RULE}#commands`, async (signal) => {
|
|
351
367
|
const entries = await listed(signal);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
"
|
|
355
|
-
|
|
356
|
-
|
|
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 }) => {
|
|
357
383
|
const { usage, description } = entry(entries, id);
|
|
358
|
-
expectHelp(await run(signal, ...
|
|
359
|
-
}
|
|
360
|
-
const { usage, description } = entry(entries, "fixture.echo");
|
|
361
|
-
expectHelp(await run(signal, "fixture", "echo", "--text", "hello", "--help"), usage, description);
|
|
384
|
+
expectHelp(await run(signal, ...args), usage, description);
|
|
385
|
+
}));
|
|
362
386
|
});
|
|
363
|
-
|
|
387
|
+
check("--help after the name of an alias writes the help of the alias", ALIASES, async (signal) => {
|
|
364
388
|
const entries = await listed(signal);
|
|
365
|
-
|
|
389
|
+
await Promise.all([
|
|
390
|
+
["say", "fixture.echo"],
|
|
391
|
+
["notes add", "fixture.note"],
|
|
392
|
+
["ticks", "fixture.ticks"]
|
|
393
|
+
].map(async ([name, id]) => {
|
|
366
394
|
const { aliases, description } = entry(entries, id);
|
|
367
|
-
const usage = aliases.find((each) =>
|
|
395
|
+
const usage = aliases.find((each) => {
|
|
396
|
+
const rest = each.split(" ").slice(1).join(" ");
|
|
397
|
+
return rest === name || rest.startsWith(`${name} `);
|
|
398
|
+
});
|
|
368
399
|
expect(usage !== void 0, `list must give the usage of the alias ${name} of ${id}`);
|
|
369
|
-
expectHelp(await run(signal, name, "--help"), usage
|
|
370
|
-
}
|
|
400
|
+
expectHelp(await run(signal, ...name.split(" "), "--help"), usage, description);
|
|
401
|
+
}));
|
|
371
402
|
});
|
|
372
|
-
|
|
403
|
+
check("--help after watch and the id of an event writes the help of the event", `${RULE}#events`, async (signal) => {
|
|
373
404
|
const { usage, description } = entry(await listed(signal), "fixture.ticks");
|
|
374
405
|
expectHelp(await run(signal, "watch", "fixture.ticks", "--help"), usage, description);
|
|
375
406
|
});
|
|
376
|
-
|
|
407
|
+
check("--help after a shared prefix writes its command list to standard output", `${RULE}#commands`, async (signal) => {
|
|
377
408
|
const entries = await listed(signal);
|
|
378
409
|
const result = await run(signal, "fixture", "switch", "--help");
|
|
379
410
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
@@ -387,94 +418,83 @@ async function checkHelp(checks, command) {
|
|
|
387
418
|
expectEqual(result.stdout, "", "standard output");
|
|
388
419
|
expectEqual(result.stderr, commandList(entries, "fixture.switch"), "standard error");
|
|
389
420
|
};
|
|
390
|
-
|
|
391
|
-
|
|
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"));
|
|
392
423
|
}
|
|
393
|
-
|
|
424
|
+
function checkAliases(check, command, listed) {
|
|
394
425
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
395
426
|
const expectOutput = (result, expected) => {
|
|
396
427
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
397
428
|
const output = parseJson(result.stdout);
|
|
398
429
|
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
399
430
|
};
|
|
400
|
-
|
|
431
|
+
check("a command alias calls its capability with the flags", ALIASES, async (signal) => {
|
|
401
432
|
expectOutput(await run(signal, "say", "--text", "hi"), { text: "hi" });
|
|
402
433
|
});
|
|
403
|
-
|
|
434
|
+
check("a flag alias calls its capability with its fixed input", ALIASES, async (signal) => {
|
|
404
435
|
expectOutput(await run(signal, "--hello"), { text: "hello" });
|
|
405
436
|
});
|
|
406
|
-
|
|
437
|
+
check("the input of an alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
|
|
407
438
|
expectOutput(await run(signal, "quick", "--count", "2", "--steps", "1", "--steps", "2"), {
|
|
408
439
|
mode: "fast",
|
|
409
440
|
count: 2,
|
|
410
441
|
steps: [1, 2]
|
|
411
442
|
});
|
|
412
443
|
});
|
|
413
|
-
|
|
444
|
+
check("an alias of a capability whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
|
|
414
445
|
expectOutput(await run(signal, "raw", "{\"a\":[1]}"), { a: [1] });
|
|
415
446
|
expectOutput(await run(signal, "raw"), {});
|
|
416
447
|
});
|
|
417
|
-
|
|
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) => {
|
|
418
449
|
expectOutput(await run(signal, "fixed-note"), { text: "fixed" });
|
|
419
450
|
expectOutput(await run(signal, "fixed-note", "--loud"), {
|
|
420
451
|
text: "fixed",
|
|
421
452
|
loud: true
|
|
422
453
|
});
|
|
423
454
|
});
|
|
424
|
-
|
|
455
|
+
check("an alias of a capability with no input takes no argument", ALIASES, async (signal) => {
|
|
425
456
|
const result = await run(signal, "held-keys");
|
|
426
457
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
427
458
|
expect(isArrayOf(memberOf(parseJson(result.stdout), "keys"), (key) => typeof key === "string"), `standard output must have the keys, got ${result.stdout}`);
|
|
428
459
|
});
|
|
429
|
-
|
|
460
|
+
check("a two-word alias calls its capability with the flags", ALIASES, async (signal) => {
|
|
430
461
|
expectOutput(await run(signal, "notes", "add", "--text", "hi"), { text: "hi" });
|
|
431
462
|
});
|
|
432
|
-
|
|
463
|
+
check("the input of a two-word alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
|
|
433
464
|
expectOutput(await run(signal, "notes", "loud", "--text", "hi"), {
|
|
434
465
|
text: "hi",
|
|
435
466
|
loud: true
|
|
436
467
|
});
|
|
437
468
|
expectOutput(await run(signal, "shout", "hello"), { text: "HELLO" });
|
|
438
469
|
});
|
|
439
|
-
|
|
470
|
+
check("a one-word alias runs when the second argument is not the second word of a two-word alias", ALIASES, async (signal) => {
|
|
440
471
|
expectOutput(await run(signal, "notes"), {});
|
|
441
472
|
expectOutput(await run(signal, "notes", "{\"a\":1}"), { a: 1 });
|
|
442
473
|
});
|
|
443
|
-
|
|
474
|
+
check("an alias that is the default of a shared prefix runs with the prefix alone, and with flags", ALIASES, async (signal) => {
|
|
444
475
|
expectOutput(await run(signal, "fixture"), { mode: "slow" });
|
|
445
476
|
expectOutput(await run(signal, "fixture", "--count", "2"), {
|
|
446
477
|
mode: "slow",
|
|
447
478
|
count: 2
|
|
448
479
|
});
|
|
449
480
|
});
|
|
450
|
-
|
|
481
|
+
check("a command under a shared prefix with a default alias keeps its path", ALIASES, async (signal) => {
|
|
451
482
|
expectOutput(await run(signal, "fixture", "echo", "--text", "hi"), { text: "hi" });
|
|
452
483
|
});
|
|
453
|
-
await checks.run("a two-word alias with --help writes its usage", ALIASES, async (signal) => {
|
|
454
|
-
const result = await run(signal, "notes", "add", "--help");
|
|
455
|
-
expectEqual(result.code, 0, "exit code");
|
|
456
|
-
expect(result.stdout.includes("notes add --text <string> [--loud]"), `standard output must have the usage of the alias, got ${JSON.stringify(result.stdout)}`);
|
|
457
|
-
});
|
|
458
484
|
const ticks = async (signal, ...args) => {
|
|
459
485
|
const result = await run(signal, "ticks", ...args);
|
|
460
486
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
461
487
|
return occurrencesIn(result.stdout, "fixture.ticks");
|
|
462
488
|
};
|
|
463
489
|
const tickData = async (signal, ...args) => (await ticks(signal, ...args)).map((occurrence) => occurrence.data);
|
|
464
|
-
|
|
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) => {
|
|
465
491
|
expectEqual(await tickData(signal), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
466
|
-
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");
|
|
467
493
|
});
|
|
468
|
-
|
|
494
|
+
check("an alias of an event takes the flags of the input of its event", ALIASES, async (signal) => {
|
|
469
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");
|
|
470
496
|
});
|
|
471
|
-
|
|
472
|
-
expectEqual(await tickData(signal, "--max-age-ms", "60000"), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
473
|
-
});
|
|
474
|
-
await checks.run("an alias of an event takes a flag value that starts with - in the form --name=value", ALIASES, async (signal) => {
|
|
475
|
-
expectEqual(await tickData(signal, "--key=--cursor"), [{ n: 1 }, { n: 2 }], "the data of the occurrences with the key --cursor");
|
|
476
|
-
});
|
|
477
|
-
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) => {
|
|
478
498
|
const echoes = async (...args) => {
|
|
479
499
|
const result = await run(signal, "echoes", ...args);
|
|
480
500
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
@@ -483,27 +503,28 @@ async function checkAliases(checks, command) {
|
|
|
483
503
|
expectEqual(await echoes("{\"a\":1}"), [{ a: 1 }], "the data of the occurrences");
|
|
484
504
|
expectEqual(await echoes(), [{}], "the data of the occurrences with no input");
|
|
485
505
|
});
|
|
486
|
-
|
|
506
|
+
check("an alias of an event writes internal to standard error with exit code 5 after a defect", ALIASES, async (signal) => {
|
|
487
507
|
const result = await run(signal, "broken-ticks");
|
|
488
508
|
expectEqual(result.code, 5, "exit code");
|
|
489
509
|
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
490
510
|
expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
|
|
491
511
|
});
|
|
492
|
-
|
|
512
|
+
check("the default alias runs with no arguments", ALIASES, async (signal) => {
|
|
493
513
|
expectOutput(await run(signal), { mode: "fast" });
|
|
494
514
|
});
|
|
495
|
-
|
|
515
|
+
check("the default alias takes the flags when the first argument is a flag", ALIASES, async (signal) => {
|
|
496
516
|
expectOutput(await run(signal, "--count", "2", "--verbose"), {
|
|
497
517
|
mode: "fast",
|
|
498
518
|
count: 2,
|
|
499
519
|
verbose: true
|
|
500
520
|
});
|
|
501
|
-
expectOutput(await run(signal, "--hello"), { text: "hello" });
|
|
502
521
|
});
|
|
503
|
-
|
|
522
|
+
check("--help writes the help, and does not run the default alias", ALIASES, async (signal) => {
|
|
504
523
|
const result = await run(signal, "--help");
|
|
505
|
-
expectEqual(result.code, 0,
|
|
506
|
-
|
|
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)}`);
|
|
507
528
|
});
|
|
508
529
|
for (const [name, args, code] of [
|
|
509
530
|
[
|
|
@@ -554,11 +575,11 @@ async function checkAliases(checks, command) {
|
|
|
554
575
|
["held-keys", "{}"],
|
|
555
576
|
3
|
|
556
577
|
]
|
|
557
|
-
])
|
|
578
|
+
]) check(name, ALIASES, async (signal) => {
|
|
558
579
|
expectEqual((await run(signal, ...args)).code, code, "exit code");
|
|
559
580
|
});
|
|
560
|
-
|
|
561
|
-
const entries =
|
|
581
|
+
check("list gives the usage of the aliases of each capability", ALIASES, async (signal) => {
|
|
582
|
+
const entries = await listed(signal);
|
|
562
583
|
for (const { id, kind, aliases } of entries) {
|
|
563
584
|
const expected = kind === "capability" ? ALIAS_USAGES[id] : EVENT_ALIAS_USAGES[id];
|
|
564
585
|
if (expected === void 0) {
|
|
@@ -572,25 +593,20 @@ async function checkAliases(checks, command) {
|
|
|
572
593
|
});
|
|
573
594
|
}
|
|
574
595
|
const EVENTS = `${RULE}#events`;
|
|
575
|
-
|
|
596
|
+
function checkWatch(check, command) {
|
|
576
597
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
577
|
-
|
|
598
|
+
check("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS, async (signal) => {
|
|
578
599
|
const result = await run(signal, "watch", "fixture.ticks", "--count", "2");
|
|
579
600
|
expectEqual(result.code, 0, "exit code");
|
|
580
601
|
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
|
|
581
602
|
expectEqual(result.stderr, "", "standard error");
|
|
582
603
|
});
|
|
583
|
-
|
|
584
|
-
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");
|
|
585
606
|
expectEqual(result.code, 0, "exit code");
|
|
586
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");
|
|
587
608
|
});
|
|
588
|
-
|
|
589
|
-
const result = await run(signal, "watch", "fixture.ticks", "--count", "1", "--key=--cursor");
|
|
590
|
-
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
591
|
-
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
592
|
-
});
|
|
593
|
-
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) => {
|
|
594
610
|
const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--gap", "2");
|
|
595
611
|
expectEqual(result.code, 0, "exit code");
|
|
596
612
|
expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [
|
|
@@ -599,7 +615,7 @@ async function checkWatch(checks, command) {
|
|
|
599
615
|
[{ n: 3 }, null]
|
|
600
616
|
], "the data and truncated of the occurrences");
|
|
601
617
|
});
|
|
602
|
-
|
|
618
|
+
check("watch writes internal to standard error with exit code 5 after a defect", EVENTS, async (signal) => {
|
|
603
619
|
const result = await run(signal, "watch", "fixture.broken");
|
|
604
620
|
expectEqual(result.code, 5, "exit code");
|
|
605
621
|
expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
|
|
@@ -626,6 +642,18 @@ async function checkWatch(checks, command) {
|
|
|
626
642
|
["watch", "fixture.ticks"],
|
|
627
643
|
3
|
|
628
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
|
+
],
|
|
629
657
|
[
|
|
630
658
|
"watch of an event outside the view has exit code 2",
|
|
631
659
|
["watch", "fixture.secret"],
|
|
@@ -655,9 +683,11 @@ async function checkWatch(checks, command) {
|
|
|
655
683
|
],
|
|
656
684
|
3
|
|
657
685
|
]
|
|
658
|
-
])
|
|
686
|
+
]) check(name, EVENTS, async (signal) => {
|
|
659
687
|
await expectUsageError(run(signal, ...args), code);
|
|
660
688
|
});
|
|
689
|
+
}
|
|
690
|
+
async function checkWatchInterrupt(checks, command) {
|
|
661
691
|
await checks.run("an interrupt cancels watch with exit code 130", EVENTS, async (signal) => {
|
|
662
692
|
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
663
693
|
const marker = join(directory, "watching");
|