@acid-cat/cli 0.11.2 → 0.12.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 CHANGED
@@ -3,10 +3,10 @@
3
3
  The AcidCat command line. npm package: `@acid-cat/cli`. It gives the `acid-cat` command. Use it at build time, in CI or by hand, to check catalogs and to test implementations. Do not use it in an application at run time.
4
4
 
5
5
  ```sh
6
- acid-cat check [--strict] <catalog.json ...> # check catalogs
6
+ acid-cat check [--strict] [--output json] <catalog.json ...> # check catalogs
7
7
  acid-cat format [--write] <catalog.json ...> # write catalogs in canonical form
8
8
  acid-cat view <catalog.json> <target> # write the view of one target
9
- acid-cat conform --mcp <url> [--mcp-handshake] --mcp-stdio "<command>" --http <url> --cli "<command>" --webmcp <url> [--deadline <ms>] [--max-bytes <n>] # test an implementation
9
+ acid-cat conform --mcp <url> [--mcp-handshake] --mcp-stdio "<command>" --http <url> --cli "<command>" --webmcp <url> [--deadline <ms>] [--max-bytes <n>] [--output json] # test an implementation
10
10
  [--poll-buffer <n>] [--poll-lease-ms <ms>] [--webhook-principal <name> --webhook-cert <file> --webhook-key <file>]
11
11
  [--webhook-other-principal <name>] [--webhook-min-ttl-ms <ms>] [--webhook-max-ttl-ms <ms>] [--webhook-max-subscriptions <n>]
12
12
  ```
@@ -19,6 +19,15 @@ pnpm add -D @acid-cat/cli
19
19
 
20
20
  It needs Node.js 24 or later. `acid-cat conform --webmcp <url>` also needs [Playwright](https://playwright.dev) and Chromium.
21
21
 
22
+ ## Output
23
+
24
+ `check` and `conform` take `--output human` (the default) or `--output json`. Human output is text for a person. JSON output is one JSON document on standard output, for a script or an agent. It writes nothing to standard error. The exit code is the same in both modes.
25
+
26
+ - `check`: `{ "conforms": boolean, "catalogs": [{ "file", "errors": [string], "warnings": [string] }] }`. `conforms` is `false` when the exit code is 1. A file that cannot be read, or that is not JSON, is a catalog with one error.
27
+ - `conform`: `{ "passed": number, "failed": number, "warnings": number, "checks": [{ "binding", "name", "rule", "passed", "warning"?, "detail"? }] }`. A check with a warning has `"passed": true` and `"warning": true`, and counts in `passed` and in `warnings`.
28
+
29
+ The JSON document comes only when the options are correct. With options that are not correct, the exit code is 1, and standard output can have the help text. `conform` with no binding, with only part of the `--webhook-*` options, or with a certificate file that cannot be read writes one line of text to standard error, and nothing to standard output.
30
+
22
31
  ## check
23
32
 
24
33
  `check` tests a catalog against [`schemas/catalog.schema.json`](../../schemas/catalog.schema.json) and against the [catalog rules](../../spec/conformance.md#catalog) that the schema cannot express.
@@ -17,7 +17,53 @@
17
17
  "cli": {
18
18
  "bindings": [
19
19
  "cli"
20
- ]
20
+ ],
21
+ "options": {
22
+ "cli": {
23
+ "aliases": {
24
+ "--hello": {
25
+ "capability": "fixture.echo",
26
+ "input": {
27
+ "text": "hello"
28
+ }
29
+ },
30
+ "broken-ticks": {
31
+ "event": "fixture.broken"
32
+ },
33
+ "echoes": {
34
+ "event": "fixture.echoes"
35
+ },
36
+ "fixed-note": {
37
+ "capability": "fixture.note",
38
+ "input": {
39
+ "text": "fixed"
40
+ }
41
+ },
42
+ "held-keys": {
43
+ "capability": "fixture.held"
44
+ },
45
+ "quick": {
46
+ "capability": "fixture.flags",
47
+ "input": {
48
+ "mode": "fast"
49
+ }
50
+ },
51
+ "raw": {
52
+ "capability": "fixture.raw"
53
+ },
54
+ "say": {
55
+ "capability": "fixture.echo"
56
+ },
57
+ "ticks": {
58
+ "event": "fixture.ticks",
59
+ "input": {
60
+ "count": 2
61
+ }
62
+ }
63
+ },
64
+ "default": "quick"
65
+ }
66
+ }
21
67
  },
22
68
  "mcp": {
23
69
  "bindings": [
@@ -25,6 +71,22 @@
25
71
  ]
26
72
  }
27
73
  },
74
+ "$defs": {
75
+ "Note": {
76
+ "properties": {
77
+ "loud": {
78
+ "type": "boolean"
79
+ },
80
+ "text": {
81
+ "type": "string"
82
+ }
83
+ },
84
+ "required": [
85
+ "text"
86
+ ],
87
+ "type": "object"
88
+ }
89
+ },
28
90
  "capabilities": {
29
91
  "fixture.crash": {
30
92
  "description": "Always fail with a defect.",
@@ -221,6 +283,31 @@
221
283
  "type": "object"
222
284
  }
223
285
  },
286
+ "fixture.note": {
287
+ "description": "Return the input. The input schema is a $ref with a description beside it.",
288
+ "audience": [
289
+ "cli"
290
+ ],
291
+ "input": {
292
+ "$ref": "#/$defs/Note",
293
+ "description": "The note."
294
+ },
295
+ "output": {
296
+ "$ref": "#/$defs/Note"
297
+ }
298
+ },
299
+ "fixture.raw": {
300
+ "description": "Return the input. The input schema has no top-level properties member.",
301
+ "audience": [
302
+ "cli"
303
+ ],
304
+ "input": {
305
+ "type": "object"
306
+ },
307
+ "output": {
308
+ "type": "object"
309
+ }
310
+ },
224
311
  "fixture.refuse": {
225
312
  "description": "Always return the failure Refused.",
226
313
  "audience": [
@@ -382,6 +469,18 @@
382
469
  "type": "object"
383
470
  }
384
471
  },
472
+ "fixture.echoes": {
473
+ "description": "Give one occurrence whose data is the input, then end.",
474
+ "audience": [
475
+ "cli"
476
+ ],
477
+ "input": {
478
+ "type": "object"
479
+ },
480
+ "payload": {
481
+ "type": "object"
482
+ }
483
+ },
385
484
  "fixture.secret": {
386
485
  "description": "Only the app target can follow this event. It never gives an occurrence.",
387
486
  "audience": [
package/dist/catalog.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import catalog_schema_default from "./json/catalog.schema.json.js";
2
2
  import { isObject, isRecordOf, isStringArray } from "./json.js";
3
3
  import { canonicalText } from "@acid-cat/catalog";
4
- import { REFERENCE, bundle, eventSchemasOf, resolveType, schemasOf, viewOf, visitObjects } from "@acid-cat/spec-ts";
4
+ import { REFERENCE, bundle, cliAliases, eventSchemasOf, resolveType, schemasOf, viewOf, visitObjects } from "@acid-cat/spec-ts";
5
5
  import { Result, Schema, SchemaIssue, SchemaRepresentation } from "effect";
6
6
  // src/catalog.ts
7
7
  const KNOWN_MEMBERS = {
@@ -33,7 +33,8 @@ const KNOWN_MEMBERS = {
33
33
  "audience",
34
34
  "input",
35
35
  "payload"
36
- ]
36
+ ],
37
+ cliOptions: ["aliases", "default"]
37
38
  };
38
39
  const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
39
40
  const isString = (value) => typeof value === "string";
@@ -91,6 +92,7 @@ function ruleErrors(catalog) {
91
92
  if ((member === "input" || member === "payload") && references.length === 0 && resolveType(schema, types).type !== "object") errors.push(`${id}: the ${member} is not an object`);
92
93
  }
93
94
  }
95
+ for (const target of Object.keys(catalog.targets)) errors.push(...cliAliases(catalog, target).errors);
94
96
  return errors;
95
97
  }
96
98
  function catalogSchemas(catalog) {
@@ -108,7 +110,7 @@ function unknownMembers(catalog) {
108
110
  const unknown = (where, value, known) => Object.keys(value).filter((key) => !known.includes(key) && !key.startsWith("x-")).map((key) => `${where}: unknown member ${key}; give extensions an x- prefix`);
109
111
  return [
110
112
  ...unknown("the catalog", catalog, KNOWN_MEMBERS.catalog),
111
- ...Object.entries(catalog.targets).flatMap(([name, target]) => unknown(`target ${name}`, target, KNOWN_MEMBERS.target)),
113
+ ...Object.entries(catalog.targets).flatMap(([name, target]) => [...unknown(`target ${name}`, target, KNOWN_MEMBERS.target), ...isObject(target.options) && isObject(target.options.cli) ? unknown(`target ${name} options.cli`, target.options.cli, KNOWN_MEMBERS.cliOptions) : []]),
112
114
  ...Object.entries(catalog.capabilities).flatMap(([id, capability]) => unknown(id, capability, KNOWN_MEMBERS.capability)),
113
115
  ...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => unknown(id, event, KNOWN_MEMBERS.event))
114
116
  ];
@@ -14,6 +14,8 @@ const USAGES = {
14
14
  "fixture.flags": "fixture flags --mode <fast|slow> [--count <integer>] [--extra <json>] [--label <string>] [--ratio <number>] [--steps <integer>...] [--tags <string>...] [--verbose]",
15
15
  "fixture.held": "fixture held",
16
16
  "fixture.hold": "fixture hold --key <string> [--marker <string>]",
17
+ "fixture.note": "fixture note --text <string> [--loud]",
18
+ "fixture.raw": "call fixture.raw '<json>'",
17
19
  "fixture.refuse": "fixture refuse",
18
20
  "fixture.release": "fixture release --key <string>",
19
21
  "fixture.switch.set": "fixture switch set --on",
@@ -23,9 +25,23 @@ const USAGES = {
23
25
  };
24
26
  const EVENT_USAGES = {
25
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>]",
26
29
  "fixture.ticks": "watch fixture.ticks --count <integer> [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]",
27
30
  "fixture.watch": "watch fixture.watch --key <string> [--marker <string>] [--cursor <string>] [--max-age-ms <integer>]"
28
31
  };
32
+ const ALIAS_USAGES = {
33
+ "fixture.echo": ["--hello", "say --text <string>"],
34
+ "fixture.flags": ["quick [--count <integer>] [--extra <json>] [--label <string>] [--ratio <number>] [--steps <integer>...] [--tags <string>...] [--verbose]"],
35
+ "fixture.held": ["held-keys"],
36
+ "fixture.note": ["fixed-note [--loud]"],
37
+ "fixture.raw": ["raw '<json>'"]
38
+ };
39
+ const EVENT_ALIAS_USAGES = {
40
+ "fixture.broken": ["broken-ticks [--cursor <string>] [--max-age-ms <integer>]"],
41
+ "fixture.echoes": ["echoes '<json>' [--cursor <string>] [--max-age-ms <integer>]"],
42
+ "fixture.ticks": ["ticks [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]"]
43
+ };
44
+ const ALIASES = `${RULE}#aliases`;
29
45
  const isEntry = (value) => isObject(value) && typeof value.id === "string";
30
46
  function entriesOf(stdout) {
31
47
  const list = parseJson(stdout);
@@ -67,6 +83,14 @@ function start(command, args, signal) {
67
83
  run
68
84
  };
69
85
  }
86
+ async function expectUsageError(result, code) {
87
+ const { code: actual, stdout } = await result;
88
+ expectEqual(actual, code, "exit code");
89
+ expectEqual(stdout, "", "standard output");
90
+ }
91
+ function occurrencesIn(stdout, id) {
92
+ return stdout.split("\n").filter((line) => line !== "").map((line) => expectOccurrence(parseJson(line), id));
93
+ }
70
94
  async function checkCli(command, options) {
71
95
  const checks = new Checks("cli", options.deadline);
72
96
  const run = (signal, ...args) => start(command, args, signal).run;
@@ -91,6 +115,11 @@ async function checkCli(command, options) {
91
115
  ["fixture", "nothing"],
92
116
  2
93
117
  ],
118
+ [
119
+ "a shared prefix alone has exit code 2",
120
+ ["fixture"],
121
+ 2
122
+ ],
94
123
  [
95
124
  "a capability outside the view has exit code 2",
96
125
  ["call", "fixture.hidden"],
@@ -101,6 +130,18 @@ async function checkCli(command, options) {
101
130
  ["fixture", "echo"],
102
131
  3
103
132
  ],
133
+ [
134
+ "an unknown flag has exit code 3",
135
+ [
136
+ "fixture",
137
+ "echo",
138
+ "--text",
139
+ "hello",
140
+ "--nope",
141
+ "x"
142
+ ],
143
+ 3
144
+ ],
104
145
  [
105
146
  "a flag that is not valid has exit code 3",
106
147
  [
@@ -149,7 +190,7 @@ async function checkCli(command, options) {
149
190
  3
150
191
  ]
151
192
  ]) await checks.run(name, `${RULE}#outcomes`, async (signal) => {
152
- expectEqual((await run(signal, ...args)).code, code, "exit code");
193
+ await expectUsageError(run(signal, ...args), code);
153
194
  });
154
195
  await checks.run("an interrupt cancels the call with exit code 130", `${RULE}#commands`, async (signal) => {
155
196
  const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
@@ -250,28 +291,185 @@ async function checkCli(command, options) {
250
291
  expectEqual(rest.join(" "), kind === "event" ? EVENT_USAGES[id] : USAGES[id], `usage of ${id} after the name of the program`);
251
292
  }
252
293
  });
294
+ await checkAliases(checks, command);
253
295
  await checkWatch(checks, command);
254
296
  return checks;
255
297
  }
298
+ async function checkAliases(checks, command) {
299
+ const run = (signal, ...args) => start(command, args, signal).run;
300
+ const expectOutput = (result, expected) => {
301
+ expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
302
+ const output = parseJson(result.stdout);
303
+ expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
304
+ };
305
+ await checks.run("a command alias calls its capability with the flags", ALIASES, async (signal) => {
306
+ expectOutput(await run(signal, "say", "--text", "hi"), { text: "hi" });
307
+ });
308
+ await checks.run("a flag alias calls its capability with its fixed input", ALIASES, async (signal) => {
309
+ expectOutput(await run(signal, "--hello"), { text: "hello" });
310
+ });
311
+ await checks.run("the input of an alias is its fixed input with the properties of the flags", ALIASES, async (signal) => {
312
+ expectOutput(await run(signal, "quick", "--count", "2", "--steps", "1", "--steps", "2"), {
313
+ mode: "fast",
314
+ count: 2,
315
+ steps: [1, 2]
316
+ });
317
+ });
318
+ await checks.run("an alias of a capability whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
319
+ expectOutput(await run(signal, "raw", "{\"a\":[1]}"), { a: [1] });
320
+ expectOutput(await run(signal, "raw"), {});
321
+ });
322
+ await checks.run("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) => {
323
+ expectOutput(await run(signal, "fixed-note"), { text: "fixed" });
324
+ expectOutput(await run(signal, "fixed-note", "--loud"), {
325
+ text: "fixed",
326
+ loud: true
327
+ });
328
+ });
329
+ await checks.run("an alias of a capability with no input takes no argument", ALIASES, async (signal) => {
330
+ const result = await run(signal, "held-keys");
331
+ expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
332
+ expect(isArrayOf(memberOf(parseJson(result.stdout), "keys"), (key) => typeof key === "string"), `standard output must have the keys, got ${result.stdout}`);
333
+ });
334
+ const ticks = async (signal, ...args) => {
335
+ const result = await run(signal, "ticks", ...args);
336
+ expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
337
+ return occurrencesIn(result.stdout, "fixture.ticks");
338
+ };
339
+ const tickData = async (signal, ...args) => (await ticks(signal, ...args)).map((occurrence) => occurrence.data);
340
+ await checks.run("an alias of an event subscribes with its fixed input and the cursor", ALIASES, async (signal) => {
341
+ expectEqual(await tickData(signal), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
342
+ expectEqual(await tickData(signal, "--cursor", "1"), [{ n: 2 }], "the data of the occurrences after the cursor 1");
343
+ });
344
+ await checks.run("an alias of an event takes the flags of the input of its event", ALIASES, async (signal) => {
345
+ 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");
346
+ });
347
+ await checks.run("an alias of an event takes --max-age-ms", ALIASES, async (signal) => {
348
+ expectEqual(await tickData(signal, "--max-age-ms", "60000"), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
349
+ });
350
+ await checks.run("an alias of an event takes a flag value that starts with - in the form --name=value", ALIASES, async (signal) => {
351
+ expectEqual(await tickData(signal, "--key=--cursor"), [{ n: 1 }, { n: 2 }], "the data of the occurrences with the key --cursor");
352
+ });
353
+ await checks.run("an alias of an event whose input schema has no properties takes the input as JSON text", ALIASES, async (signal) => {
354
+ const echoes = async (...args) => {
355
+ const result = await run(signal, "echoes", ...args);
356
+ expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
357
+ return occurrencesIn(result.stdout, "fixture.echoes").map((occurrence) => occurrence.data);
358
+ };
359
+ expectEqual(await echoes("{\"a\":1}"), [{ a: 1 }], "the data of the occurrences");
360
+ expectEqual(await echoes(), [{}], "the data of the occurrences with no input");
361
+ });
362
+ await checks.run("an alias of an event writes internal to standard error with exit code 5 after a defect", ALIASES, async (signal) => {
363
+ const result = await run(signal, "broken-ticks");
364
+ expectEqual(result.code, 5, "exit code");
365
+ expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
366
+ expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
367
+ });
368
+ await checks.run("the default alias runs with no arguments", ALIASES, async (signal) => {
369
+ expectOutput(await run(signal), { mode: "fast" });
370
+ });
371
+ await checks.run("the default alias takes the flags when the first argument is a flag", ALIASES, async (signal) => {
372
+ expectOutput(await run(signal, "--count", "2", "--verbose"), {
373
+ mode: "fast",
374
+ count: 2,
375
+ verbose: true
376
+ });
377
+ expectOutput(await run(signal, "--hello"), { text: "hello" });
378
+ });
379
+ await checks.run("--help writes the help when there is a default alias", ALIASES, async (signal) => {
380
+ const result = await run(signal, "--help");
381
+ expectEqual(result.code, 0, "exit code");
382
+ expect(result.stdout.length > 0, "standard output must have the help");
383
+ });
384
+ for (const [name, args, code] of [
385
+ [
386
+ "a flag of a property of the fixed input has exit code 3",
387
+ [
388
+ "quick",
389
+ "--mode",
390
+ "slow"
391
+ ],
392
+ 3
393
+ ],
394
+ [
395
+ "a flag of a property of the fixed input of an alias of an event has exit code 3",
396
+ [
397
+ "ticks",
398
+ "--count",
399
+ "3"
400
+ ],
401
+ 3
402
+ ],
403
+ [
404
+ "a flag that the default alias does not have has exit code 3",
405
+ ["--nothing"],
406
+ 3
407
+ ],
408
+ [
409
+ "a missing required flag of an alias has exit code 3",
410
+ ["say"],
411
+ 3
412
+ ],
413
+ [
414
+ "an alias with input that is not JSON has exit code 3",
415
+ ["raw", "{"],
416
+ 3
417
+ ],
418
+ [
419
+ "an alias of an event with input that is not JSON has exit code 3",
420
+ ["echoes", "{"],
421
+ 3
422
+ ],
423
+ [
424
+ "JSON text to an alias of a capability whose input schema refers to a type with properties has exit code 3",
425
+ ["fixed-note", "{\"text\":\"override\"}"],
426
+ 3
427
+ ],
428
+ [
429
+ "an argument to an alias of a capability with no input has exit code 3",
430
+ ["held-keys", "{}"],
431
+ 3
432
+ ]
433
+ ]) await checks.run(name, ALIASES, async (signal) => {
434
+ expectEqual((await run(signal, ...args)).code, code, "exit code");
435
+ });
436
+ await checks.run("list gives the usage of the aliases of each capability", ALIASES, async (signal) => {
437
+ const entries = entriesOf((await run(signal, "list")).stdout);
438
+ for (const { id, kind, aliases } of entries) {
439
+ const expected = kind === "capability" ? ALIAS_USAGES[id] : EVENT_ALIAS_USAGES[id];
440
+ if (expected === void 0) {
441
+ expect(aliases === void 0, `${id} has no alias, so its item must not have aliases, got ${JSON.stringify(aliases)}`);
442
+ continue;
443
+ }
444
+ expect(isArrayOf(aliases, (usage) => typeof usage === "string"), `the aliases of ${id} must be a list of strings, got ${JSON.stringify(aliases)}`);
445
+ const rest = aliases.map((usage) => usage.split(" ").slice(1).join(" "));
446
+ expectEqual(rest, expected, `the usage of the aliases of ${id} after the name of the program`);
447
+ }
448
+ });
449
+ }
256
450
  const EVENTS = `${RULE}#events`;
257
451
  async function checkWatch(checks, command) {
258
452
  const run = (signal, ...args) => start(command, args, signal).run;
259
- const occurrences = (stdout, id) => stdout.split("\n").filter((line) => line !== "").map((line) => expectOccurrence(parseJson(line), id));
260
453
  await checks.run("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS, async (signal) => {
261
454
  const result = await run(signal, "watch", "fixture.ticks", "--count", "2");
262
455
  expectEqual(result.code, 0, "exit code");
263
- expectEqual(occurrences(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
456
+ expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }, { n: 2 }], "the data of the occurrences");
264
457
  expectEqual(result.stderr, "", "standard error");
265
458
  });
266
459
  await checks.run("watch with --cursor starts after the cursor", EVENTS, async (signal) => {
267
460
  const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--cursor", "1", "--max-age-ms", "60000");
268
461
  expectEqual(result.code, 0, "exit code");
269
- expectEqual(occurrences(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.cursor]), [[{ n: 2 }, "2"], [{ n: 3 }, "3"]], "the data and the cursor of the occurrences");
462
+ 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");
463
+ });
464
+ await checks.run("watch takes a flag value that starts with - in the form --name=value", EVENTS, async (signal) => {
465
+ const result = await run(signal, "watch", "fixture.ticks", "--count", "1", "--key=--cursor");
466
+ expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
467
+ expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
270
468
  });
271
469
  await checks.run("watch writes an occurrence after a gap with truncated: true", EVENTS, async (signal) => {
272
470
  const result = await run(signal, "watch", "fixture.ticks", "--count", "3", "--gap", "2");
273
471
  expectEqual(result.code, 0, "exit code");
274
- expectEqual(occurrences(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [
472
+ expectEqual(occurrencesIn(result.stdout, "fixture.ticks").map((occurrence) => [occurrence.data, occurrence.truncated ?? null]), [
275
473
  [{ n: 1 }, null],
276
474
  [{ n: 2 }, true],
277
475
  [{ n: 3 }, null]
@@ -280,10 +478,15 @@ async function checkWatch(checks, command) {
280
478
  await checks.run("watch writes internal to standard error with exit code 5 after a defect", EVENTS, async (signal) => {
281
479
  const result = await run(signal, "watch", "fixture.broken");
282
480
  expectEqual(result.code, 5, "exit code");
283
- expectEqual(occurrences(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
481
+ expectEqual(occurrencesIn(result.stdout, "fixture.broken").map((occurrence) => occurrence.data), [{ n: 1 }], "the data of the occurrences");
284
482
  expect(/"kind":"internal"/.test(result.stderr), `standard error must contain the call failure internal, got ${JSON.stringify(result.stderr)}`);
285
483
  });
286
484
  for (const [name, args, code] of [
485
+ [
486
+ "watch with no event id has exit code 3",
487
+ ["watch"],
488
+ 3
489
+ ],
287
490
  [
288
491
  "watch with invalid input has exit code 3",
289
492
  [
@@ -329,7 +532,7 @@ async function checkWatch(checks, command) {
329
532
  3
330
533
  ]
331
534
  ]) await checks.run(name, EVENTS, async (signal) => {
332
- expectEqual((await run(signal, ...args)).code, code, "exit code");
535
+ await expectUsageError(run(signal, ...args), code);
333
536
  });
334
537
  await checks.run("an interrupt cancels watch with exit code 130", EVENTS, async (signal) => {
335
538
  const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
@@ -71,7 +71,35 @@ var catalog_schema_default = {
71
71
  "uniqueItems": true
72
72
  },
73
73
  "description": { "type": "string" },
74
- "options": { "type": "object" }
74
+ "options": {
75
+ "type": "object",
76
+ "properties": { "cli": { "$ref": "#/$defs/cliOptions" } }
77
+ }
78
+ }
79
+ },
80
+ "cliOptions": {
81
+ "description": "The settings of the CLI binding. See spec/bindings/cli.md#aliases.",
82
+ "type": "object",
83
+ "properties": {
84
+ "aliases": {
85
+ "type": "object",
86
+ "propertyNames": { "pattern": "^(--)?[a-z][a-z0-9]*(-[a-z0-9]+)*$" },
87
+ "additionalProperties": { "$ref": "#/$defs/cliAlias" }
88
+ },
89
+ "default": {
90
+ "description": "The name of the default alias: a command alias that runs when the command line gets no command.",
91
+ "type": "string",
92
+ "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
93
+ }
94
+ }
95
+ },
96
+ "cliAlias": {
97
+ "description": "A short name for a capability or an event: its id in capability or event, and an optional fixed input. Other members start with x-; acid-cat check rejects other members, and an alias with both or neither of capability and event.",
98
+ "type": "object",
99
+ "properties": {
100
+ "capability": { "$ref": "#/$defs/id" },
101
+ "event": { "$ref": "#/$defs/id" },
102
+ "input": { "type": "object" }
75
103
  }
76
104
  },
77
105
  "schema": {
@@ -6,9 +6,45 @@ var fixture_acidcat_default = {
6
6
  targets: {
7
7
  "api": { "bindings": ["http"] },
8
8
  "app": { "bindings": ["typescript", "webmcp"] },
9
- "cli": { "bindings": ["cli"] },
9
+ "cli": {
10
+ "bindings": ["cli"],
11
+ "options": { "cli": {
12
+ "aliases": {
13
+ "--hello": {
14
+ "capability": "fixture.echo",
15
+ "input": { "text": "hello" }
16
+ },
17
+ "broken-ticks": { "event": "fixture.broken" },
18
+ "echoes": { "event": "fixture.echoes" },
19
+ "fixed-note": {
20
+ "capability": "fixture.note",
21
+ "input": { "text": "fixed" }
22
+ },
23
+ "held-keys": { "capability": "fixture.held" },
24
+ "quick": {
25
+ "capability": "fixture.flags",
26
+ "input": { "mode": "fast" }
27
+ },
28
+ "raw": { "capability": "fixture.raw" },
29
+ "say": { "capability": "fixture.echo" },
30
+ "ticks": {
31
+ "event": "fixture.ticks",
32
+ "input": { "count": 2 }
33
+ }
34
+ },
35
+ "default": "quick"
36
+ } }
37
+ },
10
38
  "mcp": { "bindings": ["mcp"] }
11
39
  },
40
+ $defs: { "Note": {
41
+ "properties": {
42
+ "loud": { "type": "boolean" },
43
+ "text": { "type": "string" }
44
+ },
45
+ "required": ["text"],
46
+ "type": "object"
47
+ } },
12
48
  capabilities: {
13
49
  "fixture.crash": {
14
50
  "description": "Always fail with a defect.",
@@ -133,6 +169,21 @@ var fixture_acidcat_default = {
133
169
  "type": "object"
134
170
  }
135
171
  },
172
+ "fixture.note": {
173
+ "description": "Return the input. The input schema is a $ref with a description beside it.",
174
+ "audience": ["cli"],
175
+ "input": {
176
+ "$ref": "#/$defs/Note",
177
+ "description": "The note."
178
+ },
179
+ "output": { "$ref": "#/$defs/Note" }
180
+ },
181
+ "fixture.raw": {
182
+ "description": "Return the input. The input schema has no top-level properties member.",
183
+ "audience": ["cli"],
184
+ "input": { "type": "object" },
185
+ "output": { "type": "object" }
186
+ },
136
187
  "fixture.refuse": {
137
188
  "description": "Always return the failure Refused.",
138
189
  "audience": [
@@ -250,6 +301,12 @@ var fixture_acidcat_default = {
250
301
  "type": "object"
251
302
  }
252
303
  },
304
+ "fixture.echoes": {
305
+ "description": "Give one occurrence whose data is the input, then end.",
306
+ "audience": ["cli"],
307
+ "input": { "type": "object" },
308
+ "payload": { "type": "object" }
309
+ },
253
310
  "fixture.secret": {
254
311
  "description": "Only the app target can follow this event. It never gives an occurrence.",
255
312
  "audience": ["app"]
@@ -1,3 +1,3 @@
1
1
  // package.json
2
- var version = "0.11.2";
2
+ var version = "0.12.0";
3
3
  export { version };
package/dist/main.js CHANGED
@@ -5,33 +5,68 @@ import { DEADLINE } from "./conform/check.js";
5
5
  import { conform } from "./conform/index.js";
6
6
  import { parseJson } from "./json.js";
7
7
  import { canonicalText } from "@acid-cat/catalog";
8
- import { Console, Effect, FileSystem, Option } from "effect";
8
+ import { Console, Data, Effect, FileSystem, Option } from "effect";
9
9
  import { NodeRuntime, NodeServices } from "@effect/platform-node";
10
10
  import { Argument, Command, Flag } from "effect/cli";
11
11
  // src/main.ts
12
+ var UnreadableFile = class extends Data.TaggedError("UnreadableFile") {};
13
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
14
+ const readText = Effect.fn("readText")(function* (file) {
15
+ return yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.mapError((error) => new UnreadableFile({
16
+ file,
17
+ reason: `the file cannot be read: ${error.message}`
18
+ })));
19
+ });
12
20
  const readCatalog = Effect.fn("readCatalog")(function* (file) {
13
- const text = yield* (yield* FileSystem.FileSystem).readFileString(file);
21
+ const text = yield* readText(file);
14
22
  return {
15
23
  text,
16
- document: parseJson(text)
24
+ document: yield* Effect.try({
25
+ try: () => parseJson(text),
26
+ catch: (error) => new UnreadableFile({
27
+ file,
28
+ reason: `the file is not JSON: ${messageOf(error)}`
29
+ })
30
+ })
17
31
  };
18
32
  });
33
+ const reportUnreadable = (error) => Effect.andThen(Console.error(`${error.file}: error: ${error.reason}`), fail);
19
34
  const fail = Effect.sync(() => {
20
35
  process.exitCode = 1;
21
36
  });
22
37
  const files = Argument.String("catalog").pipe(Argument.withDescription("A catalog file, such as acidcat.catalog.json"), Argument.variadic({ min: 1 }));
38
+ const output = Flag.Literals("output", ["human", "json"]).pipe(Flag.withDescription("human: text for a person. json: one JSON document on standard output, for a script or an agent"), Flag.withDefault("human"));
39
+ const printJson = (value) => Effect.sync(() => process.stdout.write(`${JSON.stringify(value)}\n`));
23
40
  const checkCommand = Command.make("check", {
24
41
  files,
25
- strict: Flag.Boolean("strict").pipe(Flag.withDescription("Fail on warnings too"), Flag.withDefault(false))
26
- }, Effect.fn(function* ({ files, strict }) {
42
+ strict: Flag.Boolean("strict").pipe(Flag.withDescription("Fail on warnings too"), Flag.withDefault(false)),
43
+ output
44
+ }, Effect.fn(function* ({ files, strict, output }) {
27
45
  let failed = false;
46
+ const reports = [];
28
47
  for (const file of files) {
29
- const { text, document } = yield* readCatalog(file);
30
- const report = check(document, text);
31
- for (const error of report.errors) yield* Console.error(`${file}: error: ${error}`);
32
- for (const warning of report.warnings) yield* Console.error(`${file}: warning: ${warning}`);
48
+ const report = yield* readCatalog(file).pipe(Effect.map(({ text, document }) => check(document, text)), Effect.catchTag("UnreadableFile", (error) => Effect.succeed({
49
+ errors: [error.reason],
50
+ warnings: []
51
+ })));
52
+ reports.push({
53
+ file,
54
+ ...report
55
+ });
33
56
  failed ||= report.errors.length > 0 || strict && report.warnings.length > 0;
34
57
  }
58
+ if (output === "json") {
59
+ yield* printJson({
60
+ conforms: !failed,
61
+ catalogs: reports
62
+ });
63
+ if (failed) return yield* fail;
64
+ return;
65
+ }
66
+ for (const { file, errors, warnings } of reports) {
67
+ for (const error of errors) yield* Console.error(`${file}: error: ${error}`);
68
+ for (const warning of warnings) yield* Console.error(`${file}: warning: ${warning}`);
69
+ }
35
70
  if (failed) return yield* fail;
36
71
  yield* Console.log(files.length === 1 ? "The catalog conforms." : "Every catalog conforms.");
37
72
  })).pipe(Command.withDescription("Check that catalogs conform to the specification."));
@@ -46,7 +81,7 @@ const formatCommand = Command.make("format", {
46
81
  if (write) yield* fs.writeFileString(file, text);
47
82
  else yield* Effect.sync(() => process.stdout.write(text));
48
83
  }
49
- })).pipe(Command.withDescription("Write catalogs in canonical form."));
84
+ }, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Write catalogs in canonical form."));
50
85
  const viewCommand = Command.make("view", {
51
86
  file: Argument.String("catalog").pipe(Argument.withDescription("A catalog file")),
52
87
  target: Argument.String("target").pipe(Argument.withDescription("The name of a target in the catalog"))
@@ -61,7 +96,7 @@ const viewCommand = Command.make("view", {
61
96
  return yield* fail;
62
97
  }
63
98
  yield* Effect.sync(() => process.stdout.write(canonicalText(viewOf(catalog, target))));
64
- })).pipe(Command.withDescription("Print the view of one target."));
99
+ }, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Print the view of one target."));
65
100
  const url = (name, description) => Flag.String(name).pipe(Flag.withDescription(description), Flag.optional);
66
101
  const conformCommand = Command.make("conform", {
67
102
  mcp: url("mcp", "The URL of the MCP server"),
@@ -80,12 +115,12 @@ const conformCommand = Command.make("conform", {
80
115
  webhookMinTtlMs: Flag.Int("webhook-min-ttl-ms").pipe(Flag.withDescription("The minimum lifetime of a webhook subscription in the deployment, shorter than the deadline. With it, conform tests that a subscription with no renewal ends"), Flag.optional),
81
116
  webhookMaxSubscriptions: Flag.Int("webhook-max-subscriptions").pipe(Flag.withDescription("The maximum number of webhook subscriptions of one principal in the deployment. With it, conform tests the limit"), Flag.optional),
82
117
  maximumBytes: Flag.Int("max-bytes").pipe(Flag.withDescription("The body limit of the remote bindings"), Flag.withDefault(1048576)),
83
- deadline: Flag.Int("deadline").pipe(Flag.withDescription("The time, in milliseconds, that each check has to settle. A check that does not settle in this time fails"), Flag.withDefault(DEADLINE))
118
+ deadline: Flag.Int("deadline").pipe(Flag.withDescription("The time, in milliseconds, that each check has to settle. A check that does not settle in this time fails"), Flag.withDefault(DEADLINE)),
119
+ output
84
120
  }, Effect.fn(function* (options) {
85
121
  const value = (option) => Option.isSome(option) ? option.value : void 0;
86
122
  const words = (option) => value(option)?.split(/\s+/).filter((word) => word !== "");
87
123
  const optionalInt = (option) => Option.isSome(option) ? option.value : void 0;
88
- const fs = yield* FileSystem.FileSystem;
89
124
  const given = [
90
125
  options.webhookPrincipal,
91
126
  options.webhookCert,
@@ -107,8 +142,8 @@ const conformCommand = Command.make("conform", {
107
142
  }
108
143
  const webhook = Option.isSome(options.webhookPrincipal) && Option.isSome(options.webhookCert) && Option.isSome(options.webhookKey) ? {
109
144
  principal: options.webhookPrincipal.value,
110
- cert: yield* fs.readFileString(options.webhookCert.value),
111
- key: yield* fs.readFileString(options.webhookKey.value),
145
+ cert: yield* readText(options.webhookCert.value),
146
+ key: yield* readText(options.webhookKey.value),
112
147
  otherPrincipal: value(options.webhookOtherPrincipal),
113
148
  maxTtlMs: optionalInt(options.webhookMaxTtlMs),
114
149
  minTtlMs: optionalInt(options.webhookMinTtlMs),
@@ -133,12 +168,22 @@ const conformCommand = Command.make("conform", {
133
168
  yield* Console.error("Give at least one binding: --mcp, --mcp-stdio, --http, --cli or --webmcp.");
134
169
  return yield* fail;
135
170
  }
136
- for (const result of results) yield* Console.log(`${result.warning === true ? "!" : result.passed ? "✓" : "✗"} ${result.binding}: ${result.name} (${result.rule})${result.detail ? `\n ${result.detail}` : ""}`);
137
171
  const failed = results.filter((result) => !result.passed).length;
138
172
  const warnings = results.filter((result) => result.warning === true).length;
173
+ if (options.output === "json") {
174
+ yield* printJson({
175
+ passed: results.length - failed,
176
+ failed,
177
+ warnings,
178
+ checks: results
179
+ });
180
+ if (failed > 0) return yield* fail;
181
+ return;
182
+ }
183
+ for (const result of results) yield* Console.log(`${result.warning === true ? "!" : result.passed ? "✓" : "✗"} ${result.binding}: ${result.name} (${result.rule})${result.detail ? `\n ${result.detail}` : ""}`);
139
184
  yield* Console.log(`\n${results.length - failed} passed, ${failed} failed${warnings === 0 ? "" : `, ${warnings} with a warning`}.`);
140
185
  if (failed > 0) return yield* fail;
141
- })).pipe(Command.withDescription("Test a running implementation of the conformance fixture through its bindings."));
186
+ }, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Test a running implementation of the conformance fixture through its bindings."));
142
187
  Command.make("acid-cat").pipe(Command.withDescription("Check, format and view AcidCat catalogs, and test implementations."), Command.withSubcommands([
143
188
  checkCommand,
144
189
  formatCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acid-cat/cli",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "The AcidCat command line: check, format and view catalogs, and test implementations.",
5
5
  "keywords": [
6
6
  "acidcat",
@@ -37,8 +37,8 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@acid-cat/catalog": "0.11.2",
41
- "@acid-cat/spec-ts": "0.11.2",
40
+ "@acid-cat/catalog": "0.12.0",
41
+ "@acid-cat/spec-ts": "0.12.0",
42
42
  "@effect/platform-node": "^4.1.3",
43
43
  "@effect/platform-node-shared": "^4.1.3",
44
44
  "@modelcontextprotocol/client": "2.4.0",