@acid-cat/cli 0.11.1 → 0.11.2

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/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
@@ -4,10 +4,6 @@ import { canonicalText } from "@acid-cat/catalog";
4
4
  import { REFERENCE, bundle, 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",
@@ -39,7 +35,12 @@ const KNOWN_MEMBERS = {
39
35
  "payload"
40
36
  ]
41
37
  };
42
- /** The catalog schema (schemas/catalog.schema.json), imported as an Effect schema. */
38
+ const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
39
+ const isString = (value) => typeof value === "string";
40
+ const isTarget = (value) => isObject(value) && isStringArray(value.bindings);
41
+ 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");
42
+ const isEvent = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "payload", isObject);
43
+ 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
44
  const decodeCatalog = (() => {
44
45
  const { $defs, $schema: _schema, $id: _id, ...root } = catalog_schema_default;
45
46
  const definitions = $defs;
@@ -48,19 +49,9 @@ const decodeCatalog = (() => {
48
49
  schema: root,
49
50
  definitions
50
51
  }, { patterns: "apply" });
51
- return Schema.decodeUnknownResult(Schema.toType(schema));
52
+ const catalog = Schema.toType(schema).pipe(Schema.refine(isCatalog, { message: "the members do not have the types of a catalog" }));
53
+ return Schema.decodeUnknownResult(catalog);
52
54
  })();
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
55
  const formatIssues = SchemaIssue.makeFormatterStandardSchemaV1();
65
56
  /** Check a catalog. When `text` is given, the file must also be in canonical form. */
66
57
  function check(document, text) {
@@ -69,11 +60,7 @@ function check(document, text) {
69
60
  errors: formatIssues(decoded.failure.issue).issues.map((issue) => `${(issue.path ?? []).map((key) => `[${JSON.stringify(key)}]`).join("") || "the catalog"}: ${issue.message}`),
70
61
  warnings: []
71
62
  };
72
- if (!isCatalog(document)) return {
73
- errors: ["the catalog: the members do not have the types of a catalog"],
74
- warnings: []
75
- };
76
- const catalog = document;
63
+ const catalog = decoded.success;
77
64
  const errors = ruleErrors(catalog);
78
65
  const warnings = [...unknownMembers(catalog), ...errors.length === 0 ? schemaWarnings(catalog) : []];
79
66
  if (text !== void 0 && text !== canonicalText(catalog)) warnings.push("the file is not in canonical form: run `acid-cat format --write`");
@@ -82,7 +69,6 @@ function check(document, text) {
82
69
  warnings
83
70
  };
84
71
  }
85
- /** The catalog rules that the catalog schema cannot express. */
86
72
  function ruleErrors(catalog) {
87
73
  const errors = [];
88
74
  const types = catalog.$defs ?? {};
@@ -107,7 +93,6 @@ function ruleErrors(catalog) {
107
93
  }
108
94
  return errors;
109
95
  }
110
- /** The schemas of each capability and each event, with the id that holds them. */
111
96
  function catalogSchemas(catalog) {
112
97
  return [...Object.entries(catalog.capabilities).flatMap(([id, capability]) => schemasOf(capability).map(([member, schema]) => [
113
98
  id,
@@ -119,7 +104,6 @@ function catalogSchemas(catalog) {
119
104
  schema
120
105
  ]))];
121
106
  }
122
- /** Members that the specification does not define and that have no `x-` prefix. */
123
107
  function unknownMembers(catalog) {
124
108
  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
109
  return [
@@ -129,7 +113,6 @@ function unknownMembers(catalog) {
129
113
  ...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => unknown(id, event, KNOWN_MEMBERS.event))
130
114
  ];
131
115
  }
132
- /** Schemas that cannot be imported as Effect schemas. They can still be valid JSON Schema, so this is a warning. */
133
116
  function schemaWarnings(catalog) {
134
117
  const definitions = catalog.$defs ?? {};
135
118
  const warnings = [];
@@ -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";
@@ -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 };
@@ -7,9 +7,7 @@ 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
10
- /** Conformance checks for the CLI binding (spec/bindings/cli.md). Each check runs the command line as a process. */
11
10
  const RULE = "spec/bindings/cli.md";
12
- /** The `usage` of each capability in the view of the fixture, after the name of the program. */
13
11
  const USAGES = {
14
12
  "fixture.crash": "fixture crash",
15
13
  "fixture.echo": "fixture echo --text <string>",
@@ -23,23 +21,20 @@ const USAGES = {
23
21
  "fixture.signal": "fixture signal --key <string> --value <string>",
24
22
  "fixture.watching": "fixture watching"
25
23
  };
26
- /** The `usage` of each event in the view of the fixture, after the name of the program. */
27
24
  const EVENT_USAGES = {
28
25
  "fixture.broken": "watch fixture.broken [--cursor <string>] [--max-age-ms <integer>]",
29
26
  "fixture.ticks": "watch fixture.ticks --count <integer> [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]",
30
27
  "fixture.watch": "watch fixture.watch --key <string> [--marker <string>] [--cursor <string>] [--max-age-ms <integer>]"
31
28
  };
32
29
  const isEntry = (value) => isObject(value) && typeof value.id === "string";
33
- /** The list that the `list` command writes to standard output. The check fails when it is not a list of entries. */
34
30
  function entriesOf(stdout) {
35
31
  const list = parseJson(stdout);
36
32
  if (!isArrayOf(list, isEntry)) throw new Error(`list must give a list of objects with an id, got ${JSON.stringify(list)}`);
37
33
  return list;
38
34
  }
39
35
  /**
40
- * Start the command line. When the signal aborts, the process is killed, and its run rejects. The rejection is observed
41
- * here too, so that a check that stops waiting first, for example at the deadline, records a failure and does not end
42
- * the process with an unhandled rejection.
36
+ * The rejection is observed here too, so that a check that stops waiting first, for example at the deadline, records a
37
+ * failure and does not end the process with an unhandled rejection.
43
38
  */
44
39
  function start(command, args, signal) {
45
40
  const [program, ...programArgs] = command;
@@ -259,10 +254,8 @@ async function checkCli(command, options) {
259
254
  return checks;
260
255
  }
261
256
  const EVENTS = `${RULE}#events`;
262
- /** The checks of `watch` (spec/bindings/cli.md#events). */
263
257
  async function checkWatch(checks, command) {
264
258
  const run = (signal, ...args) => start(command, args, signal).run;
265
- /** The lines of standard output, each one an occurrence of the event. */
266
259
  const occurrences = (stdout, id) => stdout.split("\n").filter((line) => line !== "").map((line) => expectOccurrence(parseJson(line), id));
267
260
  await checks.run("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS, async (signal) => {
268
261
  const result = await run(signal, "watch", "fixture.ticks", "--count", "2");
@@ -3,10 +3,8 @@ import { Checks, FORBIDDEN_ORIGIN, eventIdsOf, expect, expectEqual, expectOccurr
3
3
  import { sseReader } from "./sse.js";
4
4
  import { randomUUID } from "node:crypto";
5
5
  // src/conform/http.ts
6
- /** Conformance checks for the HTTP binding (spec/bindings/http.md). */
7
6
  const RULE = "spec/bindings/http.md";
8
7
  const isEntry = (value) => isObject(value) && typeof value.id === "string";
9
- /** The list that `GET /capabilities` gives. The check fails when it is not a list of entries. */
10
8
  async function entriesOf(response) {
11
9
  const list = await readJson(response);
12
10
  if (!isArrayOf(list, isEntry)) throw new Error(`GET /capabilities must give a list of objects with an id, got ${JSON.stringify(list)}`);
@@ -109,7 +107,6 @@ async function checkHttp(base, options) {
109
107
  return checks;
110
108
  }
111
109
  const EVENTS = `${RULE}#events`;
112
- /** The checks of the events (spec/bindings/http.md#events). */
113
110
  async function checkEvents(checks, base) {
114
111
  const subscribe = (signal, id, input, headers = {}) => fetch(`${base}/events/${id}`, {
115
112
  method: "POST",
@@ -120,7 +117,6 @@ async function checkEvents(checks, base) {
120
117
  body: JSON.stringify(input),
121
118
  signal
122
119
  });
123
- /** Subscribe, and check that the stream starts. `signal` and `close` both close the stream. */
124
120
  const open = async (signal, id, input, headers = {}) => {
125
121
  const controller = new AbortController();
126
122
  const response = await subscribe(AbortSignal.any([signal, controller.signal]), id, input, headers);
@@ -136,7 +132,6 @@ async function checkEvents(checks, base) {
136
132
  close: () => controller.abort()
137
133
  };
138
134
  };
139
- /** The next message of a stream, which must be an occurrence of the event with the cursor as its SSE id. */
140
135
  const nextOccurrence = async (stream, id) => {
141
136
  const message = await stream.reader.next();
142
137
  expect(message?.event === "next", `expected event: next, got ${JSON.stringify(message)}`);
@@ -7,10 +7,6 @@ import { checkProperties, httpInvoke, mcpInvoke } from "./properties.js";
7
7
  import { browserDriver, checkWebMcp, processDriver } from "./webmcp.js";
8
8
  import { serve } from "./serve.js";
9
9
  // src/conform/index.ts
10
- /**
11
- * `acid-cat conform`: test a running implementation through its bindings (spec/conformance.md). The implementation
12
- * serves the conformance fixture (conformance/fixture.acidcat.json), with its switch on.
13
- */
14
10
  /** Run all checks for the bindings that the options give. */
15
11
  async function conform(options) {
16
12
  const maximumBytes = options.maximumBytes ?? 1048576;
@@ -7,14 +7,7 @@ import { randomUUID } from "node:crypto";
7
7
  import { Client } from "@modelcontextprotocol/client";
8
8
  import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
9
9
  // src/conform/mcp-stdio.ts
10
- /**
11
- * Conformance checks for the MCP binding through standard input and standard output (spec/bindings/mcp.md#stdio). Each
12
- * check starts the server as a process. The protocol checks use the official MCP client, once with revision 2026-07-28
13
- * and once with the `initialize` handshake of revision 2025-11-25. The other checks write lines that a client never
14
- * writes, or end standard input during a call.
15
- */
16
10
  const RULE = "spec/bindings/mcp.md#stdio";
17
- /** The two ways that a client opens the session: revision 2026-07-28, or the handshake of revision 2025-11-25. */
18
11
  const ERAS = [{
19
12
  revision: "2026-07-28",
20
13
  connects: "an MCP client connects with revision 2026-07-28",
@@ -24,11 +17,9 @@ const ERAS = [{
24
17
  connects: "an MCP client connects with the initialize handshake of revision 2025-11-25",
25
18
  options: {}
26
19
  }];
27
- /** The environment of the process: the environment of `conform`, without the variables that have no value. */
28
20
  function environment() {
29
21
  return Object.fromEntries(Object.entries(process.env).flatMap(([name, value]) => value === void 0 ? [] : [[name, value]]));
30
22
  }
31
- /** Start the server and connect an MCP client. `changes` counts each `notifications/tools/list_changed`. */
32
23
  async function connect(command, options, changes, signal) {
33
24
  const [program, ...args] = command;
34
25
  if (program === void 0) throw new Error("the command that starts the MCP server is empty");
@@ -78,10 +69,6 @@ async function checkMcpStdio(command, options) {
78
69
  all.push(await checkStdioEvents(command, options));
79
70
  return all;
80
71
  }
81
- /**
82
- * The checks of the events extension through one server process. The requests have revision 2026-07-28 in `_meta`, with
83
- * no handshake. `cancel` sends `notifications/cancelled` with the id of the `events/stream` request.
84
- */
85
72
  async function checkStdioEvents(command, options) {
86
73
  const checks = new Checks("mcp-stdio events", options.deadline);
87
74
  const controller = new AbortController();
@@ -97,7 +84,6 @@ async function checkStdioEvents(command, options) {
97
84
  }
98
85
  return checks;
99
86
  }
100
- /** A channel to a server process. Each wait stops when the signal of the check aborts. */
101
87
  function stdioChannel(server) {
102
88
  let next = 0;
103
89
  const send = (id, method, params) => server.write(JSON.stringify({
@@ -143,7 +129,6 @@ function stdioChannel(server) {
143
129
  }
144
130
  };
145
131
  }
146
- /** The server tells the client each change of the set of available tools. */
147
132
  async function checkChanges(checks, mcp, changes) {
148
133
  const set = (on, signal) => mcp.callTool({
149
134
  name: "fixture.switch.set",
@@ -165,7 +150,7 @@ async function checkChanges(checks, mcp, changes) {
165
150
  }
166
151
  });
167
152
  }
168
- /** `notifications/cancelled` cancels a call. The official client sends it when the signal of a call aborts. */
153
+ /** The official client sends `notifications/cancelled` when the signal of a call aborts. */
169
154
  async function checkCancellation(checks, mcp) {
170
155
  const invoke = clientInvoke(mcp);
171
156
  await checks.run("notifications/cancelled cancels the call", RULE, async (signal) => {
@@ -182,10 +167,6 @@ async function checkCancellation(checks, mcp) {
182
167
  }
183
168
  });
184
169
  }
185
- /**
186
- * A server process with its standard input and output, one JSON-RPC message on each line. `lines` holds each line of
187
- * standard output. When the signal aborts, the process is killed.
188
- */
189
170
  function startRaw(command, signal) {
190
171
  const [program, ...args] = command;
191
172
  if (program === void 0) throw new Error("the command that starts the MCP server is empty");
@@ -224,7 +205,6 @@ function startRaw(command, signal) {
224
205
  exited.catch(() => void 0);
225
206
  let next = 0;
226
207
  const write = (line) => child.stdin.write(`${line}\n`);
227
- /** Send a request and wait for its response. */
228
208
  const request = async (method, params = {}) => {
229
209
  const id = `conform-${next += 1}`;
230
210
  write(JSON.stringify({
@@ -244,7 +224,6 @@ function startRaw(command, signal) {
244
224
  exited
245
225
  };
246
226
  }
247
- /** The `initialize` handshake of revision 2025-11-25, through a raw process. */
248
227
  async function handshake(server, revision = "2025-11-25") {
249
228
  const response = await server.request("initialize", {
250
229
  protocolVersion: revision,
@@ -262,7 +241,6 @@ async function handshake(server, revision = "2025-11-25") {
262
241
  }
263
242
  async function checkLines(command, options) {
264
243
  const checks = new Checks("mcp-stdio", options.deadline);
265
- /** Run a body with a new server process, and kill the process at the end. */
266
244
  const withServer = (body) => async (signal) => {
267
245
  const controller = new AbortController();
268
246
  const server = startRaw(command, AbortSignal.any([controller.signal, signal]));
@@ -3,60 +3,37 @@ import type { JsonObject } from "../json.js";
3
3
  import { Checks } from "./check.js";
4
4
  import type { PollSettings } from "./poll.js";
5
5
  import type { WebhookSettings } from "./webhook.js";
6
- /** A connected MCP client. With `handshake`, the client opens the session with `initialize`. */
7
6
  export declare function mcpClient(url: string, signal?: AbortSignal, handshake?: boolean): Promise<Client>;
8
7
  export interface McpCheckOptions {
9
8
  readonly maximumBytes: number;
10
9
  readonly deadline: number;
11
10
  readonly handshake: boolean;
12
- /** The poll settings of the deployment, for the checks of the buffer and of the lease time. */
13
11
  readonly poll: PollSettings;
14
- /** The settings of the checks of webhook delivery. With none, conform does not test webhook delivery. */
15
12
  readonly webhook: WebhookSettings | undefined;
16
13
  }
17
14
  export declare function checkMcp(url: string, options: McpCheckOptions): Promise<Checks>;
18
- /**
19
- * The checks of the tools and their outcomes, through a connected client (spec/bindings/mcp.md#tools). Each transport
20
- * runs them.
21
- */
22
15
  export declare function checkTools(checks: Checks, mcp: Client): Promise<void>;
23
- /** The revision of the protocol that serves the events extension. */
24
16
  export declare const EVENTS_REVISION = "2026-07-28";
25
- /** The `_meta` of each request of revision 2026-07-28: the revision, and the capabilities of the client, which has none. */
26
17
  export declare const META: {
27
18
  "io.modelcontextprotocol/protocolVersion": string;
28
19
  "io.modelcontextprotocol/clientCapabilities": {};
29
20
  };
30
- /** A JSON-RPC message from the server. */
31
21
  export type Message = JsonObject;
32
- /**
33
- * The messages of one `events/stream` request: the notifications of the subscription and its response. `next` gives
34
- * the next message, or `undefined` at the end. `cancel` cancels the subscription, as the transport does.
35
- */
36
22
  export interface EventStream {
37
23
  next(): Promise<Message | undefined>;
38
24
  cancel(): Promise<void>;
39
25
  }
40
- /** A way to send requests of revision 2026-07-28 to a server: through HTTP, or through standard input and output. */
41
26
  export interface Channel {
42
27
  request(method: string, params: JsonObject, signal: AbortSignal): Promise<Message>;
43
- /** Start `events/stream` with this request id. */
44
28
  stream(id: string, params: JsonObject, signal: AbortSignal): Promise<EventStream>;
45
29
  }
46
- /** A channel to a server through HTTP. Each request has the `headers` too, for example the credentials of a principal. */
47
30
  export declare function httpChannel(url: string, headers?: Readonly<Record<string, string>>): Channel;
48
- /** The subscription id in the `_meta` of the params of a notification, or of a result. */
49
31
  export declare const subscriptionOf: (message: Message) => unknown;
50
- /** How a server serves the events extension, as `checkEvents` tests it. */
51
32
  export interface EventsOptions {
52
- /** The transport of the channel. Through stdio, the server never serves webhook delivery. */
53
33
  readonly transport: "http" | "stdio";
54
- /** The poll settings of the deployment. */
55
34
  readonly poll: PollSettings;
56
- /** `true` if conform tests webhook delivery through this server, so the server must serve it. */
57
35
  readonly webhook: boolean;
58
36
  }
59
- /** The requests that the checks of events send through a channel, and the capabilities of the fixture that they call. */
60
37
  export declare function eventRequests(channel: Channel): {
61
38
  resultOf: (method: string, params: JsonObject, signal: AbortSignal) => Promise<JsonObject>;
62
39
  errorOf: (message: Message | undefined) => JsonObject;
@@ -64,10 +41,5 @@ export declare function eventRequests(channel: Channel): {
64
41
  watching: (signal: AbortSignal) => Promise<readonly string[]>;
65
42
  signalKey: (key: string, value: string, signal: AbortSignal) => Promise<unknown>;
66
43
  };
67
- /** The number of times that a key is in a list of keys. */
68
44
  export declare const count: (keys: readonly string[], key: string) => number;
69
- /**
70
- * The checks of the events extension (spec/bindings/mcp.md#events), through a channel. Each transport runs them. Through
71
- * stdio, `cancel` sends `notifications/cancelled`; through HTTP, it closes the request.
72
- */
73
45
  export declare function checkEvents(checks: Checks, channel: Channel, options: EventsOptions): Promise<void>;
@@ -7,13 +7,7 @@ import { MCP_EVENTS_EXTENSION, MCP_SUBSCRIPTION_ID } from "@acid-cat/spec-ts";
7
7
  import { randomUUID } from "node:crypto";
8
8
  import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
9
9
  // src/conform/mcp.ts
10
- /**
11
- * Conformance checks for the MCP binding through HTTP (spec/bindings/mcp.md). The protocol checks use the official MCP
12
- * client with revision 2026-07-28. With `handshake`, they run again with the `initialize` handshake of revision
13
- * 2025-11-25. The other checks send requests that a client never sends.
14
- */
15
10
  const RULE = "spec/bindings/mcp.md";
16
- /** A connected MCP client. With `handshake`, the client opens the session with `initialize`. */
17
11
  async function mcpClient(url, signal, handshake = false) {
18
12
  const client = new Client({
19
13
  name: "acid-cat-conform",
@@ -22,7 +16,6 @@ async function mcpClient(url, signal, handshake = false) {
22
16
  await client.connect(new StreamableHTTPClientTransport(new URL(url)), signal ? { signal } : void 0);
23
17
  return client;
24
18
  }
25
- /** The JSON value in the first text content of a tool result, or `null` when there is no text content. */
26
19
  const textOf = (result) => {
27
20
  const first = result.content[0];
28
21
  return parseJson(first?.type === "text" ? first.text : "null");
@@ -91,7 +84,6 @@ async function checkMcp(url, options) {
91
84
  return checks;
92
85
  }
93
86
  const ANCHOR = `${RULE}#earlier-revisions-through-http`;
94
- /** The checks of the `initialize` handshake of revision 2025-11-25 (spec/bindings/mcp.md#earlier-revisions-through-http). */
95
87
  async function checkHandshake(checks, url, deadline) {
96
88
  const handshakeChecks = new Checks("mcp 2025-11-25", deadline);
97
89
  let client;
@@ -140,10 +132,6 @@ async function checkHandshake(checks, url, deadline) {
140
132
  });
141
133
  checks.results.push(...handshakeChecks.results);
142
134
  }
143
- /**
144
- * The checks of the tools and their outcomes, through a connected client (spec/bindings/mcp.md#tools). Each transport
145
- * runs them.
146
- */
147
135
  async function checkTools(checks, mcp) {
148
136
  const call = (signal, name, args) => mcp.callTool({
149
137
  name,
@@ -204,14 +192,11 @@ async function checkTools(checks, mcp) {
204
192
  }
205
193
  });
206
194
  }
207
- /** The revision of the protocol that serves the events extension. */
208
195
  const EVENTS_REVISION = "2026-07-28";
209
- /** The `_meta` of each request of revision 2026-07-28: the revision, and the capabilities of the client, which has none. */
210
196
  const META = {
211
197
  "io.modelcontextprotocol/protocolVersion": EVENTS_REVISION,
212
198
  "io.modelcontextprotocol/clientCapabilities": {}
213
199
  };
214
- /** A channel to a server through HTTP. Each request has the `headers` too, for example the credentials of a principal. */
215
200
  function httpChannel(url, headers = {}) {
216
201
  const post = (id, method, params, signal) => fetch(url, {
217
202
  method: "POST",
@@ -234,7 +219,6 @@ function httpChannel(url, headers = {}) {
234
219
  }),
235
220
  signal
236
221
  });
237
- /** The messages of a response: one JSON message, or a stream of server-sent events with one message in each. */
238
222
  const messagesOf = (response, close) => {
239
223
  if (response.headers.get("Content-Type")?.startsWith("text/event-stream") !== true) {
240
224
  let read = false;
@@ -276,22 +260,18 @@ function httpChannel(url, headers = {}) {
276
260
  }
277
261
  };
278
262
  }
279
- /** The subscription id in the `_meta` of the params of a notification, or of a result. */
280
263
  const subscriptionOf = (message) => memberOf(memberOf(memberOf(message, "params") ?? memberOf(message, "result"), "_meta"), MCP_SUBSCRIPTION_ID);
281
- /** The params of a notification of a subscription, without `_meta`. */
282
264
  const paramsOf = (message) => {
283
265
  const params = memberOf(message, "params");
284
266
  expect(isObject(params), `expected a notification with params, got ${JSON.stringify(message)}`);
285
267
  const { _meta: _, ...rest } = params;
286
268
  return rest;
287
269
  };
288
- /** The order of the delivery modes in `events/list` (spec/bindings/mcp.md#events). */
289
270
  const DELIVERY_ORDER = [
290
271
  "push",
291
272
  "poll",
292
273
  "webhook"
293
274
  ];
294
- /** The requests that the checks of events send through a channel, and the capabilities of the fixture that they call. */
295
275
  function eventRequests(channel) {
296
276
  const resultOf = async (method, params, signal) => {
297
277
  const message = await channel.request(method, params, signal);
@@ -308,13 +288,11 @@ function eventRequests(channel) {
308
288
  name,
309
289
  arguments: args
310
290
  }, signal), "structuredContent");
311
- /** The keys of the subscriptions to `fixture.watch` that are active now. */
312
291
  const watching = async (signal) => {
313
292
  const keys = memberOf(await tool("fixture.watching", {}, signal), "keys");
314
293
  expect(isStringArray(keys), `fixture.watching must give a list of keys, got ${JSON.stringify(keys)}`);
315
294
  return keys;
316
295
  };
317
- /** Give a value to the subscriptions to `fixture.watch` that watch the key. The result is the number of these subscriptions. */
318
296
  const signalKey = async (key, value, signal) => memberOf(await tool("fixture.signal", {
319
297
  key,
320
298
  value
@@ -327,16 +305,10 @@ function eventRequests(channel) {
327
305
  signalKey
328
306
  };
329
307
  }
330
- /** The number of times that a key is in a list of keys. */
331
308
  const count = (keys, key) => keys.filter((each) => each === key).length;
332
- /**
333
- * The checks of the events extension (spec/bindings/mcp.md#events), through a channel. Each transport runs them. Through
334
- * stdio, `cancel` sends `notifications/cancelled`; through HTTP, it closes the request.
335
- */
336
309
  async function checkEvents(checks, channel, options) {
337
310
  const RULE_EVENTS = `${RULE}#events`;
338
311
  const { resultOf, errorOf, watching, signalKey } = eventRequests(channel);
339
- /** The next message of a stream, which must be a notification of the method for this subscription. */
340
312
  const notification = async (stream, id, method) => {
341
313
  const message = await stream.next();
342
314
  expect(message !== void 0 && message.method === method, `expected ${method}, got ${JSON.stringify(message)}`);
@@ -348,7 +320,6 @@ async function checkEvents(checks, channel, options) {
348
320
  const message = await notification(stream, id, "notifications/events/active");
349
321
  expectEqual(paramsOf(message), { truncated: false }, "the params of notifications/events/active");
350
322
  };
351
- /** The response of the stream, which must be the result `complete` for this subscription, then the end. */
352
323
  const complete = async (stream, id) => {
353
324
  const message = await stream.next();
354
325
  expect(message !== void 0 && message.id === id, `expected the result of events/stream, got ${JSON.stringify(message)}`);
@@ -362,7 +333,6 @@ async function checkEvents(checks, channel, options) {
362
333
  const extensions = memberOf(memberOf(result, "capabilities"), "extensions");
363
334
  expect(isObject(memberOf(extensions, MCP_EVENTS_EXTENSION)), `the capabilities must have the extension ${MCP_EVENTS_EXTENSION}, got ${JSON.stringify(result)}`);
364
335
  });
365
- /** The delivery modes that the server serves, from `events/list`. */
366
336
  let delivery = [];
367
337
  await checks.run("events/list gives each event of the view, with the delivery modes of the server and its schemas", RULE_EVENTS, async (signal) => {
368
338
  const result = await resultOf("events/list", {}, signal);
@@ -3,22 +3,11 @@ import { expect, expectEqual, expectOccurrence, until } from "./check.js";
3
3
  import { eventRequests } from "./mcp.js";
4
4
  import { randomUUID } from "node:crypto";
5
5
  // src/conform/poll.ts
6
- /**
7
- * Conformance checks for poll delivery of the MCP events extension (spec/bindings/mcp.md#poll), through a channel. Each
8
- * transport runs them. The checks read the state of a lease only through `events/poll` and `fixture.watching`, and wait
9
- * for states that they can observe, not for times.
10
- *
11
- * A lease continues after the check that started it, until the lease time of the deployment ends. So each check uses a
12
- * new key in its input: the leases of one check, or of an earlier run of conform, never have the key of another check.
13
- */
14
6
  const RULE = "spec/bindings/mcp.md#poll";
15
- /** The largest count of `fixture.ticks`. */
16
7
  const MAXIMUM_TICKS = 100;
17
- /** The most occurrences that a check asks for in one poll. */
18
8
  const MAXIMUM_EVENTS = 100;
19
9
  async function checkPoll(checks, channel, settings) {
20
10
  const { errorOf, watching, signalKey } = eventRequests(channel);
21
- /** The form of a result of `events/poll` (spec/bindings/mcp.md#poll). */
22
11
  const polledOf = (message, name) => {
23
12
  const result = memberOf(message, "result");
24
13
  expect(isObject(result), `events/poll must give a result, got ${JSON.stringify(message)}`);
@@ -37,15 +26,12 @@ async function checkPoll(checks, channel, settings) {
37
26
  hasMore
38
27
  };
39
28
  };
40
- /** Poll once. The result must have the form of a result. */
41
29
  const poll = async (name, input, extra, signal) => polledOf(await channel.request("events/poll", {
42
30
  name,
43
31
  arguments: input,
44
32
  ...extra
45
33
  }, signal), name);
46
- /** Poll with the same params until `done` is true for the result. Each poll renews the lease. */
47
34
  const pollUntil = (what, name, input, extra, done, signal) => until(what, () => poll(name, input, extra, signal), done, signal);
48
- /** The JSON-RPC error of a poll. */
49
35
  const pollError = async (name, input, extra, signal) => errorOf(await channel.request("events/poll", {
50
36
  name,
51
37
  arguments: input,
@@ -64,14 +50,12 @@ async function checkPoll(checks, channel, settings) {
64
50
  expectEqual(polled.truncated, truncated, "truncated");
65
51
  expectEqual(polled.hasMore, false, "hasMore");
66
52
  };
67
- /** Start a lease of `fixture.watch` for the key, and wait until its subscription is active. The result is the cursor of the start. */
68
53
  const startWatch = async (key, signal) => {
69
54
  const started = await poll("fixture.watch", { key }, {}, signal);
70
55
  expectStart(started, false);
71
56
  await until("fixture.watching gives the key of the lease", () => watching(signal), hasKey(key), signal);
72
57
  return started.cursor;
73
58
  };
74
- /** Give values to the subscriptions of the key, one at a time. Each must reach one subscription. */
75
59
  const signalAll = async (key, values, signal) => {
76
60
  for (const value of values) expectEqual(await signalKey(key, value, signal), 1, "the subscriptions that fixture.signal reached");
77
61
  };
@@ -242,7 +226,6 @@ async function checkPoll(checks, channel, settings) {
242
226
  }
243
227
  });
244
228
  await checks.run("after a defect, the next poll is the error -32603 and ends the lease, and a later poll starts a new lease", RULE, async (signal) => {
245
- /** Start a lease of `fixture.broken`. A lease of an earlier run can still have the failure: its poll ends it first. */
246
229
  const start = async () => {
247
230
  const message = await channel.request("events/poll", {
248
231
  name: "fixture.broken",
@@ -252,7 +235,6 @@ async function checkPoll(checks, channel, settings) {
252
235
  expectStart(polled, false);
253
236
  return polled.cursor;
254
237
  };
255
- /** Poll until the error. A result before the error can only have the occurrence n = 1. */
256
238
  const failure = async (cursor) => {
257
239
  const message = await until("a poll gets the error", async () => {
258
240
  const each = await channel.request("events/poll", {
@@ -2,15 +2,12 @@ import type { Outcome } from "@acid-cat/spec-ts";
2
2
  import type { Client } from "@modelcontextprotocol/client";
3
3
  import type { JsonObject } from "../json.js";
4
4
  import { Checks } from "./check.js";
5
- /** A call through one binding. When the signal aborts, the client stops the call and rejects with the reason of the signal. */
6
5
  export type Invoke = (id: string, input: JsonObject, signal?: AbortSignal) => Promise<Outcome<unknown, unknown>>;
7
6
  export declare function httpInvoke(base: string): Invoke;
8
7
  export declare function mcpInvoke(url: string, signal: AbortSignal): Promise<{
9
8
  readonly invoke: Invoke;
10
9
  close(): Promise<void>;
11
10
  }>;
12
- /** Calls through a connected MCP client, with any transport. */
13
11
  export declare function clientInvoke(client: Client): Invoke;
14
- /** The keys of the calls that hold now, as fixture.held gives them through the binding. */
15
12
  export declare function heldKeys(invoke: Invoke, signal: AbortSignal): Promise<readonly string[]>;
16
13
  export declare function checkProperties(binding: string, invoke: Invoke, deadline: number): Promise<Checks>;
@@ -5,10 +5,6 @@ import { randomUUID } from "node:crypto";
5
5
  import { SdkError } from "@modelcontextprotocol/client";
6
6
  import fc from "fast-check";
7
7
  // src/conform/properties.ts
8
- /**
9
- * Property-based checks for the guarantees of spec/invocation.md#cancellation-and-concurrency, through each remote
10
- * binding. fast-check makes random sets of concurrent calls and cancellations.
11
- */
12
8
  const RULE = "spec/invocation.md#cancellation-and-concurrency";
13
9
  function httpInvoke(base) {
14
10
  return async (id, input, signal) => {
@@ -30,7 +26,6 @@ async function mcpInvoke(url, signal) {
30
26
  close: () => client.close()
31
27
  };
32
28
  }
33
- /** Calls through a connected MCP client, with any transport. */
34
29
  function clientInvoke(client) {
35
30
  return async (id, input, signal) => {
36
31
  try {
@@ -60,7 +55,6 @@ const operation = fc.oneof(fc.string({ maxLength: 40 }).map((text) => ({
60
55
  kind: "echo",
61
56
  text
62
57
  })), fc.constant({ kind: "refuse" }), fc.constant({ kind: "crash" }), fc.constant({ kind: "invalid" }));
63
- /** The outcome that an operation must have. */
64
58
  function agrees(operation, outcome) {
65
59
  switch (operation.kind) {
66
60
  case "echo": return "ok" in outcome && outcome.ok && JSON.stringify(outcome.value) === JSON.stringify({ text: operation.text });
@@ -79,12 +73,7 @@ const callFor = (invoke, operation, signal) => {
79
73
  };
80
74
  const settle = (call) => call.then((outcome) => ({ outcome }), (rejected) => ({ rejected }));
81
75
  const describe = (settled) => "outcome" in settled ? JSON.stringify(settled.outcome) : `the rejection ${String(settled.rejected)}`;
82
- /**
83
- * True if a call ended as a cancellation: with the call failure `cancelled`, or with the rejection that the client gives
84
- * when it aborts the call, which is the reason of its signal. Any other rejection is not a cancellation.
85
- */
86
76
  const isCancellation = (settled, reason) => "outcome" in settled ? "kind" in settled.outcome && settled.outcome.kind === "cancelled" : settled.rejected === reason;
87
- /** The keys of the calls that hold now, as fixture.held gives them through the binding. */
88
77
  async function heldKeys(invoke, signal) {
89
78
  const outcome = await invoke("fixture.held", {}, signal);
90
79
  expect("ok" in outcome && outcome.ok, `fixture.held gave ${JSON.stringify(outcome)}`);
@@ -92,12 +81,6 @@ async function heldKeys(invoke, signal) {
92
81
  expect(isStringArray(keys), `fixture.held gave ${JSON.stringify(outcome)}, with no list of keys`);
93
82
  return keys;
94
83
  }
95
- /**
96
- * Start one call to fixture.hold for each flag, and wait until each call holds. Then cancel each call whose flag is
97
- * true, and release the others. Each cancelled call must end as a cancellation and stop holding. Each other call must
98
- * hold until it is released, and then give its own key. At the end, the cleanup releases every key, with a signal that
99
- * aborts `deadline` milliseconds later.
100
- */
101
84
  async function cancelSome(invoke, flags, signal, deadline) {
102
85
  const calls = flags.map((cancelled) => {
103
86
  const key = randomUUID();
@@ -137,7 +120,6 @@ async function cancelSome(invoke, flags, signal, deadline) {
137
120
  await Promise.all(calls.map((call) => invoke("fixture.release", { key: call.key }, cleanup).catch(() => void 0)));
138
121
  }
139
122
  }
140
- /** Two calls or more, at least one of them cancelled and at least one not. */
141
123
  const cancellations = fc.array(fc.boolean(), {
142
124
  minLength: 2,
143
125
  maxLength: 5
@@ -1,9 +1,5 @@
1
1
  import { createServer } from "node:http";
2
2
  // src/conform/serve.ts
3
- /**
4
- * Serve a web request handler, `(request: Request) => Promise<Response>`, on a local port. Implementations use it
5
- * to run `acid-cat conform` against their bindings in a test.
6
- */
7
3
  /** Serve one handler for all paths, or handlers by path prefix, on `127.0.0.1` and a free port. */
8
4
  function serve(handler) {
9
5
  const routes = typeof handler === "function" ? { "/": handler } : handler;
@@ -65,12 +61,7 @@ async function answer(incoming, outgoing, prefixes, routes) {
65
61
  outgoing.end();
66
62
  }
67
63
  }
68
- /**
69
- * The body of an incoming request, as a web stream. The stream reads the request only when the handler reads the body,
70
- * and the request pauses after each chunk until the handler reads again. A request that the handler does not read stays
71
- * unread, so that Node.js discards it after the response. When the handler cancels the stream, the request discards the
72
- * rest of its body.
73
- */
64
+ /** A request that the handler does not read stays unread, so that Node.js discards it after the response. */
74
65
  function bodyOf(incoming) {
75
66
  let open = true;
76
67
  let reading = false;
@@ -1,14 +1,8 @@
1
- /** A reader of a stream of server-sent events, for the checks of the HTTP binding and of MCP through HTTP. */
2
- /** One message of a stream of server-sent events. A comment line is a message with the event `comment`. */
3
1
  export interface SseMessage {
4
2
  readonly event?: string;
5
3
  readonly id?: string;
6
4
  readonly data: string;
7
5
  }
8
- /**
9
- * Read the messages of a response one at a time. `next` skips comment lines, and resolves with `undefined` at the end of
10
- * the stream. When the signal of the request aborts, `next` rejects.
11
- */
12
6
  export declare function sseReader(response: Response): {
13
7
  next(): Promise<SseMessage | undefined>;
14
8
  cancel: () => Promise<void | undefined>;
@@ -1,8 +1,4 @@
1
1
  // src/conform/sse.ts
2
- /**
3
- * Read the messages of a response one at a time. `next` skips comment lines, and resolves with `undefined` at the end of
4
- * the stream. When the signal of the request aborts, `next` rejects.
5
- */
6
2
  function sseReader(response) {
7
3
  if (response.body === null) throw new Error("the response has no body");
8
4
  const reader = response.body.getReader();
@@ -24,8 +20,9 @@ function sseReader(response) {
24
20
  return {
25
21
  async next() {
26
22
  for (;;) {
27
- const message = await read();
28
- if (message?.event !== "comment") return message;
23
+ const frame = await read();
24
+ if (frame === void 0) return void 0;
25
+ if (frame.type === "message") return frame.message;
29
26
  }
30
27
  },
31
28
  cancel: () => reader.cancel().catch(() => void 0)
@@ -34,10 +31,7 @@ function sseReader(response) {
34
31
  function parse(raw) {
35
32
  const fields = { data: [] };
36
33
  const lines = raw.split(/\r?\n/);
37
- if (lines.every((line) => line.startsWith(":"))) return {
38
- event: "comment",
39
- data: ""
40
- };
34
+ if (lines.every((line) => line.startsWith(":"))) return { type: "comment" };
41
35
  for (const line of lines) {
42
36
  if (line.startsWith(":")) continue;
43
37
  const colon = line.indexOf(":");
@@ -48,9 +42,12 @@ function parse(raw) {
48
42
  else if (name === "data") fields.data.push(value);
49
43
  }
50
44
  return {
51
- ...fields.event === void 0 ? {} : { event: fields.event },
52
- ...fields.id === void 0 ? {} : { id: fields.id },
53
- data: fields.data.join("\n")
45
+ type: "message",
46
+ message: {
47
+ ...fields.event === void 0 ? {} : { event: fields.event },
48
+ ...fields.id === void 0 ? {} : { id: fields.id },
49
+ data: fields.data.join("\n")
50
+ }
54
51
  };
55
52
  }
56
53
  export { sseReader };
@@ -1,5 +1,4 @@
1
1
  import { Checks } from "./check.js";
2
- /** The settings of the checks of webhook delivery. */
3
2
  export interface WebhookSettings {
4
3
  /** The principal that the deployment gives to a request with the header `Authorization: Bearer <principal>`. */
5
4
  readonly principal: string;
@@ -24,5 +23,4 @@ export interface WebhookSettings {
24
23
  /** The maximum number of subscriptions of one principal in the deployment. With it, conform tests the limit. */
25
24
  readonly maxSubscriptions?: number | undefined;
26
25
  }
27
- /** The checks of webhook delivery through the MCP server at `url`. */
28
26
  export declare function checkWebhook(checks: Checks, url: string, settings: WebhookSettings): Promise<void>;
@@ -5,22 +5,9 @@ import { MCP_WEBHOOK_DEFAULTS, isOccurrence, webhookSignature, webhookSubscripti
5
5
  import { randomBytes, randomUUID } from "node:crypto";
6
6
  import { createServer } from "node:https";
7
7
  // src/conform/webhook.ts
8
- /**
9
- * Conformance checks for webhook delivery of the MCP events extension (spec/bindings/mcp.md#webhook), through HTTP.
10
- * conform runs an HTTPS receiver on 127.0.0.1 with the certificate that it gets. The deployment under test must trust
11
- * that certificate, allow deliveries to 127.0.0.1, and give the principal of `WebhookSettings` to each request with the
12
- * header `Authorization: Bearer <principal>`.
13
- *
14
- * Each check uses its own path on the receiver, so its URL is new: the server verifies it again, and the subscriptions
15
- * of one check, or of an earlier run of conform, never have the key of another check.
16
- */
17
8
  const RULE = "spec/bindings/mcp.md#webhook";
18
- /** True if the body of a request is the control message `verification`. */
9
+ const REFRESH_BEFORE_PRECISION_MS = 1;
19
10
  const isVerification = (request) => memberOf(request.body, "type") === "verification";
20
- /**
21
- * Start the receiver. By default, it answers a verification with its challenge, and each other request with 200. A
22
- * check can choose other answers for its path.
23
- */
24
11
  async function startReceiver(settings) {
25
12
  const received = /* @__PURE__ */ new Map();
26
13
  const answerers = /* @__PURE__ */ new Map();
@@ -60,7 +47,6 @@ async function startReceiver(settings) {
60
47
  const address = server.address();
61
48
  const port = typeof address === "object" && address !== null ? address.port : 0;
62
49
  return {
63
- /** A new URL on the receiver, for one check. */
64
50
  url: (answer) => {
65
51
  const path = `/hook/${randomUUID()}`;
66
52
  if (answer !== void 0) answerers.set(path, answer);
@@ -75,18 +61,12 @@ async function startReceiver(settings) {
75
61
  })
76
62
  };
77
63
  }
78
- /** A new Standard Webhooks secret. */
79
64
  const newSecret = () => `whsec_${randomBytes(32).toString("base64")}`;
80
- /** One header of a request, as text. */
81
65
  function header(request, name) {
82
66
  const value = request.headers[name];
83
67
  expect(typeof value === "string", `the request must have the header ${name}, got ${JSON.stringify(request.headers)}`);
84
68
  return value;
85
69
  }
86
- /**
87
- * Check the headers of a request of the server: the media type, the id, the timestamp, the subscription id, and a
88
- * signature with each secret. `type` is the type of a control message; with none, the request is an occurrence.
89
- */
90
70
  async function expectSigned(request, subscription, secrets, type) {
91
71
  expect(header(request, "content-type").startsWith("application/json"), `Content-Type must be application/json, got ${header(request, "content-type")}`);
92
72
  const id = header(request, "webhook-id");
@@ -103,12 +83,10 @@ async function expectSigned(request, subscription, secrets, type) {
103
83
  }
104
84
  return id;
105
85
  }
106
- /** The body of a delivery of an occurrence: the occurrence without `truncated`. */
107
86
  function expectDelivered(request, name) {
108
87
  expect(isObject(request.body) && !("truncated" in request.body), `the body must be an occurrence without truncated, got ${request.text}`);
109
88
  return expectOccurrence(request.body, name);
110
89
  }
111
- /** The checks of webhook delivery through the MCP server at `url`. */
112
90
  async function checkWebhook(checks, url, settings) {
113
91
  let receiver;
114
92
  try {
@@ -174,9 +152,7 @@ async function checkWithReceiver(checks, url, settings, receiver) {
174
152
  };
175
153
  };
176
154
  const unsubscribe = (name, input, hook, signal, client = main) => client.channel.request("events/unsubscribe", unsubscribeParams(name, input, hook), signal);
177
- /** End a subscription at the end of a check. It can be gone already. */
178
155
  const cleanup = (name, input, hook, client = main) => unsubscribe(name, input, hook, AbortSignal.timeout(checks.deadline), client).catch(() => void 0);
179
- /** The requests of a URL that are not verifications. */
180
156
  const deliveries = (hook) => hook.received().filter((each) => !isVerification(each));
181
157
  const atLeast = (hook, number, signal) => until(`the receiver gets ${number} deliveries`, async () => deliveries(hook), (list) => list.length >= number, signal);
182
158
  const watchedKey = (key) => (keys) => keys.includes(key);
@@ -407,7 +383,7 @@ async function checkWithReceiver(checks, url, settings, receiver) {
407
383
  const before = Date.now();
408
384
  const { refreshBefore } = await subscribe("fixture.watch", input, hook.url, newSecret(), signal, extra);
409
385
  const after = Date.now();
410
- expect(refreshBefore >= before + granted - 1 && refreshBefore <= after + granted + 1, `for ${what}, refreshBefore must be ${granted} ms after the request, got ${refreshBefore - before} ms after its start`);
386
+ expect(refreshBefore >= before + granted - REFRESH_BEFORE_PRECISION_MS && refreshBefore <= after + granted + REFRESH_BEFORE_PRECISION_MS, `for ${what}, refreshBefore must be ${granted} ms after the request, got ${refreshBefore - before} ms after its start`);
411
387
  } finally {
412
388
  await cleanup("fixture.watch", input, hook.url);
413
389
  }
@@ -1,17 +1,14 @@
1
1
  import { Checks } from "./check.js";
2
- /** A tool as the host records it. */
3
2
  export interface RecordedTool {
4
3
  readonly name: string;
5
4
  readonly description: string;
6
5
  readonly inputSchema: unknown;
7
6
  }
8
- /** A tool, as a page gives it to `registerTool`. */
9
7
  export interface HostTool extends RecordedTool {
10
8
  execute(input: unknown, options: {
11
9
  readonly signal: AbortSignal;
12
10
  }): Promise<unknown>;
13
11
  }
14
- /** What a call to a tool gives: the value that `execute` resolves with, or the error that it rejects with. */
15
12
  export type ToolCall = {
16
13
  readonly resolved: unknown;
17
14
  } | {
@@ -23,7 +20,6 @@ export type ToolCall = {
23
20
  } | {
24
21
  readonly missing: true;
25
22
  };
26
- /** The host that the checks give to the page. */
27
23
  export interface TestHost {
28
24
  readonly modelContext: {
29
25
  registerTool(tool: HostTool, options: {
@@ -31,23 +27,13 @@ export interface TestHost {
31
27
  }): void;
32
28
  };
33
29
  tools(): RecordedTool[];
34
- /** Call a tool. With an `id`, `cancel` can abort the signal of the call. */
35
30
  call(name: string, input: unknown, id?: string): Promise<ToolCall>;
36
- /** Abort the signal of the call that has this `id`, if it runs. */
37
31
  cancel(id: string): void;
38
32
  }
39
- /**
40
- * Make a test host. The function uses no imports and no outer variables, because the browser driver sends its
41
- * source text to the page.
42
- */
33
+ /** The function uses no imports and no outer variables, because the browser driver sends its source text to the page. */
43
34
  export declare function createTestHost(): TestHost;
44
- /** The view from the checks: the tools of the page, and calls to them. */
45
35
  export interface WebMcpDriver {
46
36
  tools(signal: AbortSignal): Promise<RecordedTool[]>;
47
- /**
48
- * Call a tool. When `cancel` aborts, the host aborts the signal of the call, and the driver waits for what the tool
49
- * gives. When `signal` aborts, the host aborts the signal of the call, and the driver stops waiting.
50
- */
51
37
  call(name: string, input: unknown, options?: {
52
38
  readonly signal?: AbortSignal;
53
39
  readonly cancel?: AbortSignal;
@@ -59,9 +45,7 @@ export interface WebMcpDriver {
59
45
  * implementation serves the `app` target of the fixture, with its switch on.
60
46
  */
61
47
  export type WebMcpInstall = (modelContext: TestHost["modelContext"]) => void | (() => void | Promise<void>) | Promise<void | (() => void | Promise<void>)>;
62
- /** A driver for an implementation in the same process. Values pass through JSON, as they do from a page. */
63
48
  export declare function processDriver(install: WebMcpInstall): Promise<WebMcpDriver>;
64
- /** A driver for a page in Chromium, through Playwright. The page loads with the test host as its `modelContext`. */
65
49
  export declare function browserDriver(url: string): Promise<WebMcpDriver>;
66
50
  export declare function checkWebMcp(driver: WebMcpDriver, options: {
67
51
  readonly deadline: number;
@@ -2,20 +2,9 @@ import { isArrayOf, isObject, isStringArray, memberOf, parseJson } from "../json
2
2
  import { Checks, abortable, expect, expectEqual, fixture, idsOf, sorted, until } from "./check.js";
3
3
  import { REFERENCE, visitObjects } from "@acid-cat/spec-ts";
4
4
  // src/conform/webmcp.ts
5
- /**
6
- * Conformance checks for the WebMCP binding (spec/bindings/webmcp.md).
7
- *
8
- * The checks act as the WebMCP host: they give the page a `modelContext`, record the tools that the binding registers,
9
- * and call them. The page can run in a browser, or the implementation can install itself on the host in the same
10
- * process.
11
- */
12
5
  const RULE = "spec/bindings/webmcp.md";
13
- /** The target of the fixture that has the WebMCP binding. */
14
6
  const TARGET = "app";
15
- /**
16
- * Make a test host. The function uses no imports and no outer variables, because the browser driver sends its
17
- * source text to the page.
18
- */
7
+ /** The function uses no imports and no outer variables, because the browser driver sends its source text to the page. */
19
8
  function createTestHost() {
20
9
  const registered = /* @__PURE__ */ new Map();
21
10
  const calls = /* @__PURE__ */ new Map();
@@ -57,7 +46,6 @@ function createTestHost() {
57
46
  }
58
47
  };
59
48
  }
60
- /** The tools that a host gives, after they pass through JSON. The check fails when the value is not a list of tools. */
61
49
  function toolsOf(value) {
62
50
  const isTool = (tool) => isObject(tool) && typeof tool.name === "string" && typeof tool.description === "string";
63
51
  if (!isArrayOf(value, isTool)) throw new Error(`the host must give a list of tools, got ${JSON.stringify(value)}`);
@@ -67,7 +55,6 @@ function toolsOf(value) {
67
55
  inputSchema: tool.inputSchema
68
56
  }));
69
57
  }
70
- /** A tool call that a host gives, after it passes through JSON. The check fails when the value is not a tool call. */
71
58
  function toolCallOf(value) {
72
59
  if (isObject(value)) {
73
60
  if (value.missing === true) return { missing: true };
@@ -99,7 +86,6 @@ function driverOf(host) {
99
86
  close: () => host.close()
100
87
  };
101
88
  }
102
- /** A driver for an implementation in the same process. Values pass through JSON, as they do from a page. */
103
89
  async function processDriver(install) {
104
90
  const host = createTestHost();
105
91
  const remove = await install(host.modelContext);
@@ -113,7 +99,6 @@ async function processDriver(install) {
113
99
  }
114
100
  });
115
101
  }
116
- /** A driver for a page in Chromium, through Playwright. The page loads with the test host as its `modelContext`. */
117
102
  async function browserDriver(url) {
118
103
  let playwright;
119
104
  try {
@@ -145,7 +130,6 @@ async function browserDriver(url) {
145
130
  close: () => browser.close()
146
131
  });
147
132
  }
148
- /** True if each `$ref` of a schema refers to a type in its own `$defs` (spec/catalog.md#bundling). */
149
133
  function isBundled(schema) {
150
134
  const types = isObject(schema.$defs) ? schema.$defs : {};
151
135
  let bundled = true;
@@ -156,8 +140,13 @@ function isBundled(schema) {
156
140
  });
157
141
  return bundled;
158
142
  }
143
+ const requiredOf = (schema) => isStringArray(schema.required) ? schema.required : [];
144
+ function expectSameInputShape(tool, schema, input) {
145
+ expectEqual(schema.type, "object", `type of the input schema of ${tool}`);
146
+ expectEqual(sorted(Object.keys(schema.properties ?? {})), sorted(Object.keys(input.properties ?? {})), `properties of ${tool}`);
147
+ expectEqual(sorted(requiredOf(schema)), sorted(requiredOf(input)), `required properties of ${tool}`);
148
+ }
159
149
  const names = async (driver, signal) => sorted((await driver.tools(signal)).map((tool) => tool.name));
160
- /** The keys of the calls that hold now, as fixture.held gives them through the host. */
161
150
  async function heldKeys(driver, signal) {
162
151
  const call = await driver.call("fixture.held", {}, { signal });
163
152
  expect("resolved" in call, `fixture.held gave ${JSON.stringify(call)}`);
@@ -182,11 +171,7 @@ async function checkWebMcp(driver, options) {
182
171
  expectEqual(tool.description, view[tool.name]?.description, `description of ${tool.name}`);
183
172
  const schema = tool.inputSchema;
184
173
  expect(isObject(schema), `the input schema of ${tool.name} must be an object`);
185
- const input = view[tool.name]?.input ?? {};
186
- const required = (object) => isStringArray(object.required) ? object.required : [];
187
- expectEqual(schema.type, "object", `type of the input schema of ${tool.name}`);
188
- expectEqual(sorted(Object.keys(schema.properties ?? {})), sorted(Object.keys(input.properties ?? {})), `properties of ${tool.name}`);
189
- expectEqual(sorted(required(schema)), sorted(required(input)), `required properties of ${tool.name}`);
174
+ expectSameInputShape(tool.name, schema, view[tool.name]?.input ?? {});
190
175
  expect(isBundled(schema), `the input schema of ${tool.name} must be bundled`);
191
176
  }
192
177
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /** The library of `@acid-cat/cli`: catalog checks, and the conformance tests. */
2
1
  export { bundle, check, viewOf } from "./catalog.js";
3
2
  export type { Catalog, Report } from "./catalog.js";
4
3
  export { conform, fixture, serve } from "./conform/index.js";
@@ -1,3 +1,3 @@
1
1
  // package.json
2
- var version = "0.11.1";
2
+ var version = "0.11.2";
3
3
  export { version };
package/dist/json.d.ts CHANGED
@@ -1,22 +1,11 @@
1
- /**
2
- * Checks of JSON values at run time. A value from a file, a process or a network is not trusted. These checks give it a
3
- * type only after they examine it.
4
- */
5
1
  import type { JsonObject } from "@acid-cat/spec-ts";
6
2
  export type { JsonObject };
7
- /** True if the value is a JSON object: not `null`, and not an array. */
8
3
  export declare const isObject: (value: unknown) => value is JsonObject;
9
- /** True if the value is an array of strings. */
10
4
  export declare const isStringArray: (value: unknown) => value is readonly string[];
11
- /** True if the value is a JSON object, and `isMember` is true for each of its member values. */
12
5
  export declare const isRecordOf: <T>(value: unknown, isMember: (member: unknown) => member is T) => value is {
13
6
  readonly [key: string]: T;
14
7
  };
15
- /** The member `key` of a value, or `undefined` when the value is not an object. */
16
8
  export declare const memberOf: (value: unknown, key: string) => unknown;
17
- /** Parse JSON text. The value is not trusted, so its type is `unknown`. */
18
9
  export declare function parseJson(text: string): unknown;
19
- /** Read the body of a response as JSON. The value is not trusted, so its type is `unknown`. */
20
10
  export declare function readJson(response: Response): Promise<unknown>;
21
- /** True if the value is an array, and `isItem` is true for each of its items. */
22
11
  export declare const isArrayOf: <T>(value: unknown, isItem: (item: unknown) => item is T) => value is readonly T[];
package/dist/json.js CHANGED
@@ -1,20 +1,13 @@
1
1
  // src/json.ts
2
- /** True if the value is a JSON object: not `null`, and not an array. */
3
2
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
- /** True if the value is an array of strings. */
5
3
  const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
6
- /** True if the value is a JSON object, and `isMember` is true for each of its member values. */
7
4
  const isRecordOf = (value, isMember) => isObject(value) && Object.values(value).every(isMember);
8
- /** The member `key` of a value, or `undefined` when the value is not an object. */
9
5
  const memberOf = (value, key) => isObject(value) ? value[key] : void 0;
10
- /** Parse JSON text. The value is not trusted, so its type is `unknown`. */
11
6
  function parseJson(text) {
12
7
  return JSON.parse(text);
13
8
  }
14
- /** Read the body of a response as JSON. The value is not trusted, so its type is `unknown`. */
15
9
  async function readJson(response) {
16
10
  return await response.json();
17
11
  }
18
- /** True if the value is an array, and `isItem` is true for each of its items. */
19
12
  const isArrayOf = (value, isItem) => Array.isArray(value) && value.every(isItem);
20
13
  export { isArrayOf, isObject, isRecordOf, isStringArray, memberOf, parseJson, readJson };
package/dist/main.js CHANGED
@@ -9,11 +9,6 @@ import { Console, 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
- /**
13
- * `acid-cat`: check, format and view AcidCat catalogs.
14
- *
15
- * Exit codes: 0 when the command succeeds, 1 when a catalog does not conform or a file is not found.
16
- */
17
12
  const readCatalog = Effect.fn("readCatalog")(function* (file) {
18
13
  const text = yield* (yield* FileSystem.FileSystem).readFileString(file);
19
14
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acid-cat/cli",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
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.1",
41
- "@acid-cat/spec-ts": "0.11.1",
40
+ "@acid-cat/catalog": "0.11.2",
41
+ "@acid-cat/spec-ts": "0.11.2",
42
42
  "@effect/platform-node": "^4.1.3",
43
43
  "@effect/platform-node-shared": "^4.1.3",
44
44
  "@modelcontextprotocol/client": "2.4.0",