@acid-cat/cli 0.11.1 → 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 +11 -2
- package/conformance/fixture.acidcat.json +100 -1
- package/dist/catalog.d.ts +0 -4
- package/dist/catalog.js +14 -29
- package/dist/conform/check.d.ts +0 -27
- package/dist/conform/check.js +0 -27
- package/dist/conform/cli.js +212 -16
- package/dist/conform/http.js +0 -5
- package/dist/conform/index.js +0 -4
- package/dist/conform/mcp-stdio.js +1 -23
- package/dist/conform/mcp.d.ts +0 -28
- package/dist/conform/mcp.js +0 -30
- package/dist/conform/poll.js +0 -18
- package/dist/conform/properties.d.ts +0 -3
- package/dist/conform/properties.js +0 -18
- package/dist/conform/serve.js +1 -10
- package/dist/conform/sse.d.ts +0 -6
- package/dist/conform/sse.js +10 -13
- package/dist/conform/webhook.d.ts +0 -2
- package/dist/conform/webhook.js +2 -26
- package/dist/conform/webmcp.d.ts +1 -17
- package/dist/conform/webmcp.js +8 -23
- package/dist/index.d.ts +0 -1
- package/dist/json/catalog.schema.json.js +29 -1
- package/dist/json/fixture.acidcat.json.js +58 -1
- package/dist/json/package.json.js +1 -1
- package/dist/json.d.ts +0 -11
- package/dist/json.js +0 -7
- package/dist/main.js +62 -22
- package/package.json +3 -3
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.d.ts
CHANGED
|
@@ -7,10 +7,6 @@ export interface Report {
|
|
|
7
7
|
readonly errors: readonly string[];
|
|
8
8
|
readonly warnings: readonly string[];
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* True if the value has the members and the member types of a catalog. It does not check the catalog rules: `check`
|
|
12
|
-
* does that.
|
|
13
|
-
*/
|
|
14
10
|
export declare const isCatalog: (value: unknown) => value is Catalog;
|
|
15
11
|
/** Check a catalog. When `text` is given, the file must also be in canonical form. */
|
|
16
12
|
export declare function check(document: unknown, text?: string): Report;
|
package/dist/catalog.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
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
|
-
/**
|
|
8
|
-
* The catalog operations that the specification defines: the catalog rules, views and bundling.
|
|
9
|
-
* See spec/catalog.md and spec/conformance.md.
|
|
10
|
-
*/
|
|
11
7
|
const KNOWN_MEMBERS = {
|
|
12
8
|
catalog: [
|
|
13
9
|
"acidcat",
|
|
@@ -37,9 +33,15 @@ const KNOWN_MEMBERS = {
|
|
|
37
33
|
"audience",
|
|
38
34
|
"input",
|
|
39
35
|
"payload"
|
|
40
|
-
]
|
|
36
|
+
],
|
|
37
|
+
cliOptions: ["aliases", "default"]
|
|
41
38
|
};
|
|
42
|
-
|
|
39
|
+
const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
|
|
40
|
+
const isString = (value) => typeof value === "string";
|
|
41
|
+
const isTarget = (value) => isObject(value) && isStringArray(value.bindings);
|
|
42
|
+
const isCapability = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "output", isObject) && optional(value, "state", isObject) && optional(value, "failures", (failures) => isRecordOf(failures, isObject)) && optional(value, "readOnly", (readOnly) => typeof readOnly === "boolean");
|
|
43
|
+
const isEvent = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "payload", isObject);
|
|
44
|
+
const isCatalog = (value) => isObject(value) && typeof value.acidcat === "string" && optional(value, "title", isString) && optional(value, "description", isString) && isRecordOf(value.targets, isTarget) && optional(value, "$defs", (types) => isRecordOf(types, isObject)) && isRecordOf(value.capabilities, isCapability) && optional(value, "events", (events) => isRecordOf(events, isEvent));
|
|
43
45
|
const decodeCatalog = (() => {
|
|
44
46
|
const { $defs, $schema: _schema, $id: _id, ...root } = catalog_schema_default;
|
|
45
47
|
const definitions = $defs;
|
|
@@ -48,19 +50,9 @@ const decodeCatalog = (() => {
|
|
|
48
50
|
schema: root,
|
|
49
51
|
definitions
|
|
50
52
|
}, { patterns: "apply" });
|
|
51
|
-
|
|
53
|
+
const catalog = Schema.toType(schema).pipe(Schema.refine(isCatalog, { message: "the members do not have the types of a catalog" }));
|
|
54
|
+
return Schema.decodeUnknownResult(catalog);
|
|
52
55
|
})();
|
|
53
|
-
/** True if `key` is absent from the object, or if `isMember` is true for its value. */
|
|
54
|
-
const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
|
|
55
|
-
const isString = (value) => typeof value === "string";
|
|
56
|
-
const isTarget = (value) => isObject(value) && isStringArray(value.bindings);
|
|
57
|
-
const isCapability = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "output", isObject) && optional(value, "state", isObject) && optional(value, "failures", (failures) => isRecordOf(failures, isObject)) && optional(value, "readOnly", (readOnly) => typeof readOnly === "boolean");
|
|
58
|
-
const isEvent = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "payload", isObject);
|
|
59
|
-
/**
|
|
60
|
-
* True if the value has the members and the member types of a catalog. It does not check the catalog rules: `check`
|
|
61
|
-
* does that.
|
|
62
|
-
*/
|
|
63
|
-
const isCatalog = (value) => isObject(value) && typeof value.acidcat === "string" && optional(value, "title", isString) && optional(value, "description", isString) && isRecordOf(value.targets, isTarget) && optional(value, "$defs", (types) => isRecordOf(types, isObject)) && isRecordOf(value.capabilities, isCapability) && optional(value, "events", (events) => isRecordOf(events, isEvent));
|
|
64
56
|
const formatIssues = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
65
57
|
/** Check a catalog. When `text` is given, the file must also be in canonical form. */
|
|
66
58
|
function check(document, text) {
|
|
@@ -69,11 +61,7 @@ function check(document, text) {
|
|
|
69
61
|
errors: formatIssues(decoded.failure.issue).issues.map((issue) => `${(issue.path ?? []).map((key) => `[${JSON.stringify(key)}]`).join("") || "the catalog"}: ${issue.message}`),
|
|
70
62
|
warnings: []
|
|
71
63
|
};
|
|
72
|
-
|
|
73
|
-
errors: ["the catalog: the members do not have the types of a catalog"],
|
|
74
|
-
warnings: []
|
|
75
|
-
};
|
|
76
|
-
const catalog = document;
|
|
64
|
+
const catalog = decoded.success;
|
|
77
65
|
const errors = ruleErrors(catalog);
|
|
78
66
|
const warnings = [...unknownMembers(catalog), ...errors.length === 0 ? schemaWarnings(catalog) : []];
|
|
79
67
|
if (text !== void 0 && text !== canonicalText(catalog)) warnings.push("the file is not in canonical form: run `acid-cat format --write`");
|
|
@@ -82,7 +70,6 @@ function check(document, text) {
|
|
|
82
70
|
warnings
|
|
83
71
|
};
|
|
84
72
|
}
|
|
85
|
-
/** The catalog rules that the catalog schema cannot express. */
|
|
86
73
|
function ruleErrors(catalog) {
|
|
87
74
|
const errors = [];
|
|
88
75
|
const types = catalog.$defs ?? {};
|
|
@@ -105,9 +92,9 @@ function ruleErrors(catalog) {
|
|
|
105
92
|
if ((member === "input" || member === "payload") && references.length === 0 && resolveType(schema, types).type !== "object") errors.push(`${id}: the ${member} is not an object`);
|
|
106
93
|
}
|
|
107
94
|
}
|
|
95
|
+
for (const target of Object.keys(catalog.targets)) errors.push(...cliAliases(catalog, target).errors);
|
|
108
96
|
return errors;
|
|
109
97
|
}
|
|
110
|
-
/** The schemas of each capability and each event, with the id that holds them. */
|
|
111
98
|
function catalogSchemas(catalog) {
|
|
112
99
|
return [...Object.entries(catalog.capabilities).flatMap(([id, capability]) => schemasOf(capability).map(([member, schema]) => [
|
|
113
100
|
id,
|
|
@@ -119,17 +106,15 @@ function catalogSchemas(catalog) {
|
|
|
119
106
|
schema
|
|
120
107
|
]))];
|
|
121
108
|
}
|
|
122
|
-
/** Members that the specification does not define and that have no `x-` prefix. */
|
|
123
109
|
function unknownMembers(catalog) {
|
|
124
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`);
|
|
125
111
|
return [
|
|
126
112
|
...unknown("the catalog", catalog, KNOWN_MEMBERS.catalog),
|
|
127
|
-
...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) : []]),
|
|
128
114
|
...Object.entries(catalog.capabilities).flatMap(([id, capability]) => unknown(id, capability, KNOWN_MEMBERS.capability)),
|
|
129
115
|
...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => unknown(id, event, KNOWN_MEMBERS.event))
|
|
130
116
|
];
|
|
131
117
|
}
|
|
132
|
-
/** Schemas that cannot be imported as Effect schemas. They can still be valid JSON Schema, so this is a warning. */
|
|
133
118
|
function schemaWarnings(catalog) {
|
|
134
119
|
const definitions = catalog.$defs ?? {};
|
|
135
120
|
const warnings = [];
|
package/dist/conform/check.d.ts
CHANGED
|
@@ -11,28 +11,11 @@ export interface Check {
|
|
|
11
11
|
}
|
|
12
12
|
/** The conformance fixture: the catalog that each implementation serves. */
|
|
13
13
|
export declare const fixture: CatalogDocument;
|
|
14
|
-
/**
|
|
15
|
-
* True if the value is an outcome (spec/invocation.md): `{ ok: true, value }`, `{ ok: false, error }`, or a call
|
|
16
|
-
* failure `{ kind, message }` with no `ok`.
|
|
17
|
-
*/
|
|
18
14
|
export declare const isOutcome: (value: unknown) => value is Outcome<unknown, unknown>;
|
|
19
|
-
/** The ids of the capabilities in the view of a target of the fixture. */
|
|
20
15
|
export declare const idsOf: (target: string) => string[];
|
|
21
|
-
/** The ids of the events in the view of a target of the fixture. */
|
|
22
16
|
export declare const eventIdsOf: (target: string) => string[];
|
|
23
|
-
/**
|
|
24
|
-
* The value as an occurrence of the event `id`: an occurrence in its JSON form (schemas/occurrence.schema.json), with
|
|
25
|
-
* the id as its name, and data that agrees with the payload schema. The check fails when the value is not one.
|
|
26
|
-
*/
|
|
27
17
|
export declare function expectOccurrence(value: unknown, id: string): Occurrence;
|
|
28
|
-
/** The time, in milliseconds, that each check has to settle when `conform` gets no other time. */
|
|
29
18
|
export declare const DEADLINE = 30000;
|
|
30
|
-
/**
|
|
31
|
-
* Collects checks for one binding. Each check has one deadline. The check gives its signal to each operation, and the
|
|
32
|
-
* signal aborts at the deadline. Then each operation stops, and the check fails with "did not settle". The deadline
|
|
33
|
-
* never makes a check pass. The cleanup of a check, which releases what the check holds, gets its own signal with the
|
|
34
|
-
* same time, so that `conform` always returns.
|
|
35
|
-
*/
|
|
36
19
|
export declare class Checks {
|
|
37
20
|
#private;
|
|
38
21
|
readonly results: Check[];
|
|
@@ -40,22 +23,12 @@ export declare class Checks {
|
|
|
40
23
|
readonly deadline: number;
|
|
41
24
|
constructor(binding: string, deadline: number);
|
|
42
25
|
run(name: string, rule: string, body: (signal: AbortSignal) => Promise<void> | void): Promise<void>;
|
|
43
|
-
/** Run a check of a recommendation (SHOULD). When it fails, the result is a warning, and the check passes. */
|
|
44
26
|
should(name: string, rule: string, body: (signal: AbortSignal) => Promise<void> | void): Promise<void>;
|
|
45
27
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Read a state until `done` is true for it, and give that value. The read and the pause between two reads stop when the
|
|
48
|
-
* signal of the check aborts.
|
|
49
|
-
*/
|
|
50
28
|
export declare function until<T, Done extends T>(what: string, read: () => Promise<T>, done: (value: T) => value is Done, signal: AbortSignal): Promise<Done>;
|
|
51
29
|
export declare function until<T>(what: string, read: () => Promise<T>, done: (value: T) => boolean, signal: AbortSignal): Promise<T>;
|
|
52
|
-
/** Settle as the promise does, or reject with the reason of the signal when it aborts first. */
|
|
53
30
|
export declare function abortable<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
54
|
-
/** Fail a check unless `condition` is true. */
|
|
55
31
|
export declare function expect(condition: unknown, message: string): asserts condition;
|
|
56
|
-
/** Fail a check unless the two values have the same JSON. */
|
|
57
32
|
export declare function expectEqual(actual: unknown, expected: unknown, what: string): void;
|
|
58
|
-
/** A sorted copy of a list. */
|
|
59
33
|
export declare const sorted: (values: Iterable<string>) => string[];
|
|
60
|
-
/** An origin that no deployment allows. */
|
|
61
34
|
export declare const FORBIDDEN_ORIGIN = "https://not-allowed.acid-cat.invalid";
|
package/dist/conform/check.js
CHANGED
|
@@ -4,26 +4,17 @@ import { CALL_FAILURE_KINDS, isOccurrence, viewOf } from "@acid-cat/spec-ts";
|
|
|
4
4
|
import { Schema, SchemaRepresentation } from "effect";
|
|
5
5
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
6
6
|
// src/conform/check.ts
|
|
7
|
-
/** The result of one conformance check, and helpers to write checks. */
|
|
8
7
|
/** The conformance fixture: the catalog that each implementation serves. */
|
|
9
8
|
const fixture = fixture_acidcat_default;
|
|
10
|
-
/**
|
|
11
|
-
* True if the value is an outcome (spec/invocation.md): `{ ok: true, value }`, `{ ok: false, error }`, or a call
|
|
12
|
-
* failure `{ kind, message }` with no `ok`.
|
|
13
|
-
*/
|
|
14
9
|
const isOutcome = (value) => {
|
|
15
10
|
if (!isObject(value)) return false;
|
|
16
11
|
if (value.ok === true) return "value" in value;
|
|
17
12
|
if (value.ok === false) return "error" in value;
|
|
18
13
|
return !("ok" in value) && CALL_FAILURE_KINDS.some((kind) => kind === value.kind) && typeof value.message === "string";
|
|
19
14
|
};
|
|
20
|
-
/** The ids of the capabilities in the view of a target of the fixture. */
|
|
21
15
|
const idsOf = (target) => Object.keys(viewOf(fixture, target).capabilities).sort();
|
|
22
|
-
/** The ids of the events in the view of a target of the fixture. */
|
|
23
16
|
const eventIdsOf = (target) => Object.keys(viewOf(fixture, target).events ?? {}).sort();
|
|
24
|
-
/** A check of a payload against the payload schema of an event of the fixture, made once for each event. */
|
|
25
17
|
const payloadChecks = /* @__PURE__ */ new Map();
|
|
26
|
-
/** True if the data agrees with the payload schema of the event. With no payload schema, the data is an empty object. */
|
|
27
18
|
function agreesWithPayload(id, data) {
|
|
28
19
|
let agrees = payloadChecks.get(id);
|
|
29
20
|
if (agrees === void 0) {
|
|
@@ -42,24 +33,13 @@ function agreesWithPayload(id, data) {
|
|
|
42
33
|
}
|
|
43
34
|
return agrees(data);
|
|
44
35
|
}
|
|
45
|
-
/**
|
|
46
|
-
* The value as an occurrence of the event `id`: an occurrence in its JSON form (schemas/occurrence.schema.json), with
|
|
47
|
-
* the id as its name, and data that agrees with the payload schema. The check fails when the value is not one.
|
|
48
|
-
*/
|
|
49
36
|
function expectOccurrence(value, id) {
|
|
50
37
|
expect(isOccurrence(value), `expected an occurrence, got ${JSON.stringify(value)}`);
|
|
51
38
|
expectEqual(value.name, id, "the name of the occurrence");
|
|
52
39
|
expect(agreesWithPayload(id, value.data), `the data of the occurrence must agree with the payload schema of ${id}, got ${JSON.stringify(value.data)}`);
|
|
53
40
|
return value;
|
|
54
41
|
}
|
|
55
|
-
/** The time, in milliseconds, that each check has to settle when `conform` gets no other time. */
|
|
56
42
|
const DEADLINE = 3e4;
|
|
57
|
-
/**
|
|
58
|
-
* Collects checks for one binding. Each check has one deadline. The check gives its signal to each operation, and the
|
|
59
|
-
* signal aborts at the deadline. Then each operation stops, and the check fails with "did not settle". The deadline
|
|
60
|
-
* never makes a check pass. The cleanup of a check, which releases what the check holds, gets its own signal with the
|
|
61
|
-
* same time, so that `conform` always returns.
|
|
62
|
-
*/
|
|
63
43
|
var Checks = class {
|
|
64
44
|
results = [];
|
|
65
45
|
binding;
|
|
@@ -83,7 +63,6 @@ var Checks = class {
|
|
|
83
63
|
detail: failure
|
|
84
64
|
});
|
|
85
65
|
}
|
|
86
|
-
/** Run a check of a recommendation (SHOULD). When it fails, the result is a warning, and the check passes. */
|
|
87
66
|
async should(name, rule, body) {
|
|
88
67
|
const failure = await this.#settle(body);
|
|
89
68
|
this.results.push(failure === void 0 ? {
|
|
@@ -100,7 +79,6 @@ var Checks = class {
|
|
|
100
79
|
detail: failure
|
|
101
80
|
});
|
|
102
81
|
}
|
|
103
|
-
/** Run the body of a check with its deadline. The result is the detail of the failure, or `undefined`. */
|
|
104
82
|
async #settle(body) {
|
|
105
83
|
const controller = new AbortController();
|
|
106
84
|
const timer = setTimeout(() => controller.abort(), this.deadline);
|
|
@@ -127,7 +105,6 @@ async function until(what, read, done, signal) {
|
|
|
127
105
|
throw signal.aborted ? /* @__PURE__ */ new Error(`waiting until ${what}; the last value was ${JSON.stringify(last)}`) : error;
|
|
128
106
|
}
|
|
129
107
|
}
|
|
130
|
-
/** Settle as the promise does, or reject with the reason of the signal when it aborts first. */
|
|
131
108
|
function abortable(promise, signal) {
|
|
132
109
|
const aborted = new Promise((_, reject) => {
|
|
133
110
|
signal.throwIfAborted();
|
|
@@ -135,18 +112,14 @@ function abortable(promise, signal) {
|
|
|
135
112
|
});
|
|
136
113
|
return Promise.race([promise, aborted]);
|
|
137
114
|
}
|
|
138
|
-
/** Fail a check unless `condition` is true. */
|
|
139
115
|
function expect(condition, message) {
|
|
140
116
|
if (!condition) throw new Error(message);
|
|
141
117
|
}
|
|
142
|
-
/** Fail a check unless the two values have the same JSON. */
|
|
143
118
|
function expectEqual(actual, expected, what) {
|
|
144
119
|
const a = JSON.stringify(actual);
|
|
145
120
|
const b = JSON.stringify(expected);
|
|
146
121
|
if (a !== b) throw new Error(`${what}: expected ${b}, got ${a}`);
|
|
147
122
|
}
|
|
148
|
-
/** A sorted copy of a list. */
|
|
149
123
|
const sorted = (values) => [...values].sort();
|
|
150
|
-
/** An origin that no deployment allows. */
|
|
151
124
|
const FORBIDDEN_ORIGIN = "https://not-allowed.acid-cat.invalid";
|
|
152
125
|
export { Checks, DEADLINE, FORBIDDEN_ORIGIN, abortable, eventIdsOf, expect, expectEqual, expectOccurrence, fixture, idsOf, isOutcome, sorted, until };
|