mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
* test(mcp): compile advertised patterns with the regex engines clients run List the built package's tools over stdio in every input, output and catalog profile and compile each distinct advertised regular expression with V8 (plain, u, v), Go regexp (RE2), C++ RE2, Python re, and Rust regex and fancy-regex through the Rust jsonschema crate. A refusal names the engine, its error, and each tool, schema path and profile. The Python engines are pinned, hash-checked wheels; Go is the host toolchain with GOTOOLCHAIN=local. A missing engine is reported as not verified, and REA_REQUIRE_SCHEMA_ENGINES=1 makes it a failure. The pattern owner now also reports patternProperties keys, which clients compile as well. Refs #10830 * test(mcp): run schema engine helpers and listings under the process owner * test(mcp): load advertised schemas in the validators clients build (#10983) * test(mcp): load advertised schemas in the validators clients build Build a validator for every distinct advertised input and output schema with the Rust jsonschema crate's defaults, which check the declared draft's meta-schema and formats and compile every subschema. --complete adds Python jsonschema's check_schema, which jsonschema.validate runs in Python clients; it takes several seconds, so it is opt-in. Refusals are grouped by reason, so one shared pattern that breaks many schemas is reported once with its sites. Ajv strict mode and OpenAI strict mode are documented as not covered, with the reasons. Refs #10830 * ci(mcp): require the client schema engines on every code change (#10984) * ci(mcp): require the client schema engines on every code change Run scripts/verify-advertised-schemas.mjs at the end of the build job, after its artifacts upload, with REA_REQUIRE_SCHEMA_ENGINES=1 so a missing engine fails rather than passes. Go is the runner's toolchain; the Python engines install into a virtual environment cached by the requirements file's digest and interpreter version. Full qualification adds --complete. Refs #10830 * test(ci): require the client schema engine step in code builds * test(mcp): record a reviewable summary of the advertised catalog (#10985) * test(mcp): record a reviewable summary of the advertised catalog Commit scripts/verify/advertised-schemas/summary.json: each advertised pattern with the tool schemas that carry it, and a digest of every tool's schema per input or output profile. The advertised schema check compares it with the packaged listings it already makes and fails on any difference, printing lines such as '119 tool schemas gained pattern /.../', so a change that reaches many tools at once is visible in review. --update-summary regenerates it. Refs #10830 * docs(release): check the packed catalog with client engines before publishing (#10986) * docs(release): check the packed catalog with client engines before publishing Add a pre-publish step to the release guide: install the packed candidate into an empty prefix and run verify-advertised-schemas.mjs against it with --package-root, requiring the RE2 (Go regexp and C++ RE2) and Rust (regex, fancy-regex and jsonschema) engines. CI checks each commit's build; this covers the archive that will be published. Refs #10830 * docs(release): check the exact qualified archive and clean up afterwards * test(mcp): regenerate the advertised catalog summary from current main
124 lines
4.6 KiB
JavaScript
124 lines
4.6 KiB
JavaScript
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { Client } from "@modelcontextprotocol/client";
|
|
|
|
import { createOwnedMcpStdioTransport } from "./owned-mcp-stdio.mjs";
|
|
import { VerifierFixture, withVerifierFixture } from "./verifier-fixture.mjs";
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
|
|
/**
|
|
* Profile combinations whose listings advertise every distinct schema. The
|
|
* catalog profile changes the tool set (hot/cold adds `discover_tools`), so
|
|
* each catalog profile is listed with every input and every output profile,
|
|
* paired in turn rather than as their product: input and output presentations
|
|
* are selected by separate settings, and each listing starts a server process.
|
|
* advertisedDialect.test.ts lists the full product in process.
|
|
*/
|
|
const advertisedProfiles = async () => {
|
|
const [
|
|
{ mcpInputSchemaProfileSchema },
|
|
{ mcpOutputSchemaProfileSchema },
|
|
{ mcpToolCatalogProfileSchema },
|
|
] = await Promise.all([
|
|
import("../../dist/config/mcpInputSchemaProfile.js"),
|
|
import("../../dist/config/mcpOutputSchemaProfile.js"),
|
|
import("../../dist/config/mcpToolCatalogProfile.js"),
|
|
]);
|
|
const inputs = mcpInputSchemaProfileSchema.options;
|
|
const outputs = mcpOutputSchemaProfileSchema.options;
|
|
const count = Math.max(inputs.length, outputs.length);
|
|
return mcpToolCatalogProfileSchema.options.flatMap((catalog) =>
|
|
Array.from({ length: count }, (_, index) => ({
|
|
input: inputs[index % inputs.length],
|
|
output: outputs[index % outputs.length],
|
|
catalog,
|
|
})),
|
|
);
|
|
};
|
|
|
|
/** List tools from the packaged stdio entry, as an installed client does. */
|
|
const listPackagedTools = async (profile, packageRoot) => {
|
|
// The listing must not depend on the developer's account or configuration.
|
|
const fixture = await VerifierFixture.open({
|
|
prefix: "rea-advertised-catalog-",
|
|
});
|
|
const home = fixture.path;
|
|
const environment = {
|
|
PATH: process.env.PATH ?? "",
|
|
HOME: home,
|
|
USERPROFILE: home,
|
|
XDG_CONFIG_HOME: join(home, "config"),
|
|
XDG_CACHE_HOME: join(home, "cache"),
|
|
XDG_STATE_HOME: join(home, "state"),
|
|
REA_MCP_INPUT_SCHEMA_PROFILE: profile.input,
|
|
REA_MCP_OUTPUT_SCHEMA_PROFILE: profile.output,
|
|
REA_MCP_TOOL_CATALOG_PROFILE: profile.catalog,
|
|
};
|
|
if (process.env.SystemRoot !== undefined)
|
|
environment.SystemRoot = process.env.SystemRoot;
|
|
return withVerifierFixture(fixture, async () => {
|
|
// The process owner stops the server's whole process tree on close, and
|
|
// the fixture keeps its home until that cleanup confirms.
|
|
const transport = await createOwnedMcpStdioTransport({
|
|
command: process.execPath,
|
|
arguments: [join(packageRoot, "scripts/rea.mjs"), "mcp"],
|
|
cwd: home,
|
|
hostEnvironment: environment,
|
|
expectedCommand: null,
|
|
sweepTokenOwnedProcesses: true,
|
|
});
|
|
const client = new Client({ name: "rea-advertised-catalog", version: "1" });
|
|
fixture.releaseAfter(() => client.close());
|
|
try {
|
|
await client.connect(transport);
|
|
return (await client.listTools()).tools;
|
|
} catch (cause) {
|
|
throw new Error(
|
|
`packaged MCP listing failed for ${describeProfile(profile)}: ${String(cause)}\n${transport.diagnostics()?.stderr ?? ""}`,
|
|
{ cause },
|
|
);
|
|
}
|
|
});
|
|
};
|
|
|
|
/** `input/output/catalog`, as reported beside every finding. */
|
|
const describeProfile = ({ input, output, catalog }) =>
|
|
`${input}/${output}/${catalog}`;
|
|
|
|
/**
|
|
* The packaged server's tools/list for every profile combination, listed
|
|
* concurrently from separate server processes. `packageRoot` selects an
|
|
* installed package instead of this checkout's build.
|
|
*/
|
|
export const listAdvertisedCatalogs = async (packageRoot = root) => {
|
|
const profiles = await advertisedProfiles();
|
|
return Promise.all(
|
|
profiles.map(async (profile) => ({
|
|
profile,
|
|
tools: await listPackagedTools(profile, packageRoot),
|
|
})),
|
|
);
|
|
};
|
|
|
|
/** Each advertised schema with every place it is advertised. */
|
|
export const distinctAdvertisedSchemas = (catalogs) => {
|
|
const schemas = new Map();
|
|
for (const { profile, tools } of catalogs)
|
|
for (const tool of tools)
|
|
for (const kind of ["inputSchema", "outputSchema"]) {
|
|
const schema = tool[kind];
|
|
if (schema === undefined) continue;
|
|
const key = JSON.stringify(schema);
|
|
const site = {
|
|
profile: describeProfile(profile),
|
|
tool: tool.name,
|
|
kind,
|
|
};
|
|
const entry = schemas.get(key);
|
|
if (entry === undefined) schemas.set(key, { schema, sites: [site] });
|
|
else entry.sites.push(site);
|
|
}
|
|
return [...schemas.values()];
|
|
};
|