@acid-cat/cli 0.19.0 → 0.21.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.
Files changed (42) hide show
  1. package/README.md +32 -2
  2. package/conformance/fixture.acidcat.json +96 -0
  3. package/dist/conform-LH9KgQ9-.js +5045 -0
  4. package/dist/index.d.ts +164 -4
  5. package/dist/index.js +96 -4
  6. package/dist/main.d.ts +1 -2
  7. package/dist/main.js +1090 -7
  8. package/package.json +4 -3
  9. package/dist/catalog.d.ts +0 -12
  10. package/dist/catalog.js +0 -149
  11. package/dist/conform/check.d.ts +0 -47
  12. package/dist/conform/check.js +0 -178
  13. package/dist/conform/cli.d.ts +0 -5
  14. package/dist/conform/cli.js +0 -721
  15. package/dist/conform/http.d.ts +0 -6
  16. package/dist/conform/http.js +0 -297
  17. package/dist/conform/index.d.ts +0 -69
  18. package/dist/conform/index.js +0 -80
  19. package/dist/conform/mcp-stdio.d.ts +0 -7
  20. package/dist/conform/mcp-stdio.js +0 -291
  21. package/dist/conform/mcp.d.ts +0 -47
  22. package/dist/conform/mcp.js +0 -754
  23. package/dist/conform/poll.d.ts +0 -13
  24. package/dist/conform/poll.js +0 -295
  25. package/dist/conform/properties.d.ts +0 -12
  26. package/dist/conform/properties.js +0 -151
  27. package/dist/conform/serve.d.ts +0 -12
  28. package/dist/conform/serve.js +0 -96
  29. package/dist/conform/server-card.d.ts +0 -5
  30. package/dist/conform/server-card.js +0 -142
  31. package/dist/conform/sse.d.ts +0 -9
  32. package/dist/conform/sse.js +0 -53
  33. package/dist/conform/webhook.d.ts +0 -30
  34. package/dist/conform/webhook.js +0 -481
  35. package/dist/conform/webmcp.d.ts +0 -53
  36. package/dist/conform/webmcp.js +0 -232
  37. package/dist/json/catalog.schema.json.js +0 -170
  38. package/dist/json/fixture.acidcat.json.js +0 -396
  39. package/dist/json/package.json.js +0 -3
  40. package/dist/json/server-card.schema.json.js +0 -281
  41. package/dist/json.d.ts +0 -11
  42. package/dist/json.js +0 -13
package/dist/index.d.ts CHANGED
@@ -1,4 +1,164 @@
1
- export { bundle, check, targetCatalog } from "./catalog.js";
2
- export type { Catalog, Report } from "./catalog.js";
3
- export { conform, fixture, serve } from "./conform/index.js";
4
- export type { Check, ConformOptions, PollSettings, Routes, Served, WebHandler, WebhookSettings } from "./conform/index.js";
1
+ import { CatalogDocument, CatalogDocument as Catalog, bundle, targetCatalog } from "@acid-cat/spec-ts";
2
+ import "effect";
3
+ import "@modelcontextprotocol/client";
4
+ /** The result of a check. An error breaks a rule. A warning breaks a recommendation. */
5
+ interface Report {
6
+ readonly errors: readonly string[];
7
+ readonly warnings: readonly string[];
8
+ }
9
+ /** Check a catalog. When `text` is given, the file must also be in canonical form. */
10
+ export declare function check(document: unknown, text?: string): Report;
11
+ interface Check {
12
+ readonly surface: string;
13
+ readonly name: string;
14
+ /** The part of the specification that the check tests, for example `spec/surfaces/mcp.md#tools`. */
15
+ readonly rule: string;
16
+ readonly passed: boolean;
17
+ /** `true` when the check tests a recommendation (SHOULD) that the implementation does not follow. The check still passes. */
18
+ readonly warning?: boolean | undefined;
19
+ readonly detail?: string | undefined;
20
+ }
21
+ /** The conformance fixture: the catalog that each implementation serves. */
22
+ export declare const fixture: CatalogDocument;
23
+ interface RecordedTool {
24
+ readonly name: string;
25
+ readonly description: string;
26
+ readonly inputSchema: unknown;
27
+ }
28
+ interface HostTool extends RecordedTool {
29
+ execute(input: unknown, options: {
30
+ readonly signal: AbortSignal;
31
+ }): Promise<unknown>;
32
+ }
33
+ type ToolCall = {
34
+ readonly resolved: unknown;
35
+ } | {
36
+ readonly rejected: {
37
+ readonly name: string;
38
+ readonly kind: unknown;
39
+ readonly message: string;
40
+ };
41
+ } | {
42
+ readonly missing: true;
43
+ };
44
+ interface TestHost {
45
+ readonly modelContext: {
46
+ registerTool(tool: HostTool, options: {
47
+ readonly signal: AbortSignal;
48
+ }): void;
49
+ };
50
+ tools(): RecordedTool[];
51
+ call(name: string, input: unknown, id?: string): Promise<ToolCall>;
52
+ cancel(id: string): void;
53
+ }
54
+ /**
55
+ * Install the implementation on a host in the same process. Return a function that removes it, or nothing. The
56
+ * implementation serves the `app` target of the fixture, with its switch on.
57
+ */
58
+ type WebMcpInstall = (modelContext: TestHost["modelContext"]) => void | (() => void | Promise<void>) | Promise<void | (() => void | Promise<void>)>;
59
+ interface WebhookSettings {
60
+ /** The principal that the deployment gives to a request with the header `Authorization: Bearer <principal>`. */
61
+ readonly principal: string;
62
+ /** The certificate of the receiver, in PEM. It must be valid for the IP address 127.0.0.1. */
63
+ readonly cert: string;
64
+ /** The private key of the certificate, in PEM. */
65
+ readonly key: string;
66
+ /**
67
+ * A second principal, given to a request with the header `Authorization: Bearer <otherPrincipal>`. With it, the check
68
+ * of the limit fills the subscriptions of this principal, which no other check uses, and checks that the first
69
+ * principal can still subscribe.
70
+ */
71
+ readonly otherPrincipal?: string | undefined;
72
+ /**
73
+ * The maximum lifetime of a subscription in the deployment, in milliseconds. The default is the default of the
74
+ * specification, 3 600 000. It must be longer than the deadline: a subscription must last for a whole check.
75
+ */
76
+ readonly maxTtlMs?: number | undefined;
77
+ /**
78
+ * The minimum lifetime of a subscription in the deployment, in milliseconds. The default is the default of the
79
+ * specification, 60 000. With it, conform also tests that a subscription with no renewal ends: it must be shorter
80
+ * than the deadline.
81
+ */
82
+ readonly minTtlMs?: number | undefined;
83
+ /** The maximum number of subscriptions of one principal in the deployment. With it, conform tests the limit. */
84
+ readonly maxSubscriptions?: number | undefined;
85
+ }
86
+ /**
87
+ * The poll settings of the deployment that conform tests. Each one is optional. With a setting, conform also tests the
88
+ * rule that depends on it. The lease time of the deployment must be longer than the deadline: a lease must last for a
89
+ * whole check.
90
+ */
91
+ interface PollSettings {
92
+ /** The number of occurrences that a lease keeps. With it, conform tests the occurrences of a cursor older than the buffer. It must be 97 or less. */
93
+ readonly bufferLimit?: number | undefined;
94
+ }
95
+ interface Served {
96
+ /** The base URL, for example `http://127.0.0.1:40123`. */
97
+ readonly url: string;
98
+ close(): Promise<void>;
99
+ }
100
+ type WebHandler = (request: Request) => Promise<Response> | Response;
101
+ /** Handlers by path prefix, for example `{ "/mcp": mcp, "/api": http }`. The longest prefix that matches gets the request. */
102
+ interface Routes {
103
+ readonly [prefix: string]: WebHandler;
104
+ }
105
+ /** Serve one handler for all paths, or handlers by path prefix, on `127.0.0.1` and a free port. */
106
+ export declare function serve(handler: WebHandler | Routes): Promise<Served>;
107
+ interface ConformOptions {
108
+ /** The URL of the MCP server, for example `http://localhost:8787/mcp`. */
109
+ readonly mcp?: string | undefined;
110
+ /**
111
+ * Check the `initialize` handshake of revision 2025-11-25 through the MCP server too
112
+ * (spec/surfaces/mcp.md#earlier-revisions-through-http). The default is `false`.
113
+ */
114
+ readonly mcpHandshake?: boolean | undefined;
115
+ /**
116
+ * The command that starts the MCP server through standard input and standard output, for example
117
+ * `["node", "fixture-mcp-stdio.ts"]`. Each check starts its own process.
118
+ */
119
+ readonly mcpStdio?: readonly string[] | undefined;
120
+ /** The base URL of the HTTP API, before `/capabilities`. */
121
+ readonly http?: string | undefined;
122
+ /** The command that starts the command line, for example `["node", "fixture-cli.ts"]`. */
123
+ readonly cli?: readonly string[] | undefined;
124
+ /**
125
+ * The WebMCP surface: the URL of a page that serves the `app` target, or a function that installs the implementation
126
+ * on a host in the same process. A page runs in Chromium, through Playwright.
127
+ */
128
+ readonly webmcp?: string | WebMcpInstall | undefined;
129
+ /**
130
+ * The poll settings of the deployment, for MCP through HTTP and through stdio. With `bufferLimit`, conform tests a
131
+ * cursor older than the buffer. The lease time of the deployment must be longer than the deadline.
132
+ */
133
+ readonly poll?: PollSettings | undefined;
134
+ /**
135
+ * An MCP server through HTTP whose lease time is `leaseMs`, shorter than the deadline. conform tests there that a lease
136
+ * with no poll ends.
137
+ */
138
+ readonly pollLease?: {
139
+ readonly mcp: string;
140
+ readonly leaseMs: number;
141
+ } | undefined;
142
+ /**
143
+ * Test webhook delivery through `mcp`. conform runs an HTTPS receiver on 127.0.0.1 with this certificate and key. The
144
+ * deployment trusts the certificate, allows deliveries to 127.0.0.1, and gives the principal to each request with the
145
+ * header `Authorization: Bearer <principal>`.
146
+ */
147
+ readonly webhook?: WebhookSettings | undefined;
148
+ /** The body limit of the remote surfaces, in bytes. The default is 1 MiB. */
149
+ readonly maximumBytes?: number | undefined;
150
+ /**
151
+ * The time, in milliseconds, that each check has to settle. A check that does not settle in this time fails. The
152
+ * default is `DEADLINE`, 30 seconds.
153
+ */
154
+ readonly deadline?: number | undefined;
155
+ /**
156
+ * When it aborts, conform stops: each check that runs stops as at its deadline and cleans up, no other check and no
157
+ * other surface starts, and the promise rejects with the reason of the signal. A test gives its own signal, so that
158
+ * conform ends with the test.
159
+ */
160
+ readonly signal?: AbortSignal | undefined;
161
+ }
162
+ /** Run all checks for the surfaces that the options give. */
163
+ export declare function conform(options: ConformOptions): Promise<readonly Check[]>;
164
+ export { type Catalog, type Check, type ConformOptions, type PollSettings, type Report, type Routes, type Served, type WebHandler, type WebhookSettings, bundle, targetCatalog };
package/dist/index.js CHANGED
@@ -1,5 +1,97 @@
1
- import { bundle, check, targetCatalog } from "./catalog.js";
2
- import { fixture } from "./conform/check.js";
3
- import { serve } from "./conform/serve.js";
4
- import { conform } from "./conform/index.js";
1
+ import { i as bundle, l as targetCatalog, o as check, r as fixture, t as conform } from "./conform-LH9KgQ9-.js";
2
+ import { createServer } from "node:http";
3
+ // src/conform/serve.ts
4
+ /** Serve one handler for all paths, or handlers by path prefix, on `127.0.0.1` and a free port. */
5
+ function serve(handler) {
6
+ const routes = typeof handler === "function" ? { "/": handler } : handler;
7
+ const prefixes = Object.keys(routes).sort((a, b) => b.length - a.length);
8
+ const server = createServer({ keepAliveTimeout: 0 }, (incoming, outgoing) => {
9
+ const closeIfIdle = () => server.listening || server.closeIdleConnections();
10
+ incoming.on("end", closeIfIdle);
11
+ outgoing.on("finish", closeIfIdle);
12
+ answer(incoming, outgoing, prefixes, routes);
13
+ });
14
+ return new Promise((resolve) => {
15
+ server.listen(0, "127.0.0.1", () => {
16
+ const address = server.address();
17
+ resolve({
18
+ url: `http://127.0.0.1:${typeof address === "object" && address !== null ? address.port : 0}`,
19
+ close: () => new Promise((done) => server.close(() => done()))
20
+ });
21
+ });
22
+ });
23
+ }
24
+ async function answer(incoming, outgoing, prefixes, routes) {
25
+ const url = new URL(incoming.url ?? "/", `http://${incoming.headers.host ?? "127.0.0.1"}`);
26
+ const prefix = prefixes.find((candidate) => candidate === "/" || url.pathname === candidate || url.pathname.startsWith(`${candidate}/`));
27
+ const handler = prefix === void 0 ? void 0 : routes[prefix];
28
+ if (handler === void 0) {
29
+ outgoing.writeHead(404).end();
30
+ return;
31
+ }
32
+ const abort = new AbortController();
33
+ outgoing.on("close", () => {
34
+ if (!outgoing.writableFinished) abort.abort();
35
+ });
36
+ const headers = new Headers();
37
+ for (const [name, value] of Object.entries(incoming.headers)) if (Array.isArray(value)) value.forEach((item) => headers.append(name, item));
38
+ else if (value !== void 0) headers.set(name, value);
39
+ const hasBody = incoming.method !== "GET" && incoming.method !== "HEAD";
40
+ const init = {
41
+ method: incoming.method ?? "GET",
42
+ headers,
43
+ signal: abort.signal
44
+ };
45
+ const withBody = () => ({
46
+ ...init,
47
+ body: bodyOf(incoming),
48
+ duplex: "half"
49
+ });
50
+ const request = new Request(url, hasBody ? withBody() : init);
51
+ try {
52
+ const response = await handler(request);
53
+ outgoing.writeHead(response.status, Object.fromEntries(response.headers));
54
+ if (response.body === null) {
55
+ outgoing.end();
56
+ return;
57
+ }
58
+ outgoing.flushHeaders();
59
+ const reader = response.body.getReader();
60
+ abort.signal.addEventListener("abort", () => void reader.cancel().catch(() => void 0), { once: true });
61
+ for (let chunk = await reader.read(); !chunk.done; chunk = await reader.read()) outgoing.write(chunk.value);
62
+ outgoing.end();
63
+ } catch {
64
+ if (!outgoing.headersSent) outgoing.writeHead(500);
65
+ outgoing.end();
66
+ }
67
+ }
68
+ /** A request that the handler does not read stays unread, so that Node.js discards it after the response. */
69
+ function bodyOf(incoming) {
70
+ let open = true;
71
+ let reading = false;
72
+ const close = (end) => {
73
+ if (open) end();
74
+ open = false;
75
+ };
76
+ return new ReadableStream({
77
+ pull(controller) {
78
+ if (!reading) {
79
+ reading = true;
80
+ incoming.on("data", (chunk) => {
81
+ if (!open) return;
82
+ if (!(chunk instanceof Uint8Array)) return close(() => controller.error(/* @__PURE__ */ new TypeError("a chunk of the request body is not bytes")));
83
+ controller.enqueue(chunk);
84
+ incoming.pause();
85
+ });
86
+ incoming.on("end", () => close(() => controller.close()));
87
+ incoming.on("error", (error) => close(() => controller.error(error)));
88
+ }
89
+ incoming.resume();
90
+ },
91
+ cancel() {
92
+ open = false;
93
+ incoming.resume();
94
+ }
95
+ }, { highWaterMark: 0 });
96
+ }
5
97
  export { bundle, check, conform, fixture, serve, targetCatalog };
package/dist/main.d.ts CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ export {}