mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* test(mcp): check advertised schemas against a portable dialect in every profile * fix(mcp): re-emit advertised patterns in a portable regex grammar * fix(mcp): validate advertised dialect by selected profile * fix(mcp): preserve schema widening through references * fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns * fix(mcp): keep references valid when presentation widens their targets * fix(mcp): relax references into negations and conditionals presentation may remove * fix(mcp): keep astral literals and dynamic references widening in every mode * fix(mcp): omit astral literals and relax untracked references when presentation widens * fix(mcp): read reference pointers by schema position, not segment spelling * fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse * fix(mcp): omit patterns whose classes name astral characters * fix(mcp): decide union collapse and pointer protection from canonical branches * docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes * test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe * fix(mcp): protect references into unevaluated keywords lost evaluation removes * fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings * fix(mcp): protect references into literal siblings of relaxed draft-07 references
114 lines
4.1 KiB
TypeScript
114 lines
4.1 KiB
TypeScript
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { AjvJsonSchemaValidator } from "@modelcontextprotocol/client/validators/ajv";
|
|
import { expect, it, onTestFinished } from "vitest";
|
|
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { advertisedSchemaPatterns } from "../../../src/contracts/advertisedDialect.js";
|
|
import { projectPortablePattern } from "../../../src/contracts/portablePattern.js";
|
|
import {
|
|
BASE64_QUARTET_LENGTH_PATTERN,
|
|
INVALID_BASE64_CHARACTER_PATTERN,
|
|
INVALID_BASE64_PADDING_PATTERN,
|
|
INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN,
|
|
} from "../../../src/domain/stringPatterns.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
|
|
// Pattern portability across every profile is owned by
|
|
// advertisedDialect.test.ts. This file keeps the composed canonical base64
|
|
// constraint's safe advertisement after portable re-emission.
|
|
|
|
const advertised = (pattern: RegExp): string => {
|
|
const projection = projectPortablePattern(pattern.source);
|
|
if (projection.kind === "unexpressible")
|
|
throw new Error(`No portable form for ${pattern.source}`);
|
|
return projection.pattern;
|
|
};
|
|
|
|
const collectCanonicalBase64Leaves = (
|
|
value: unknown,
|
|
leaves: Record<string, unknown>[],
|
|
): void => {
|
|
if (value === null || typeof value !== "object") return;
|
|
if (Array.isArray(value)) {
|
|
value.forEach((entry) => collectCanonicalBase64Leaves(entry, leaves));
|
|
return;
|
|
}
|
|
const record = value as Record<string, unknown>;
|
|
const allOf = record.allOf;
|
|
if (
|
|
Array.isArray(allOf) &&
|
|
allOf.some(
|
|
(entry) =>
|
|
entry !== null &&
|
|
typeof entry === "object" &&
|
|
"pattern" in entry &&
|
|
entry.pattern === advertised(BASE64_QUARTET_LENGTH_PATTERN),
|
|
)
|
|
)
|
|
leaves.push(record);
|
|
Object.values(record).forEach((entry) =>
|
|
collectCanonicalBase64Leaves(entry, leaves),
|
|
);
|
|
};
|
|
|
|
const listAdvertisedTools = async () => {
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("No deep provider may start for a schema projection");
|
|
});
|
|
const server = createServer({ kind: "session", session }, {});
|
|
const client = new Client({ name: "advertised-patterns", version: "1" });
|
|
onTestFinished(async () => {
|
|
await client.close();
|
|
await server.close();
|
|
await session.close();
|
|
});
|
|
const [clientTransport, serverTransport] =
|
|
InMemoryTransport.createLinkedPair();
|
|
await server.connect(serverTransport);
|
|
await client.connect(clientTransport);
|
|
return (await client.listTools()).tools;
|
|
};
|
|
|
|
it("advertises base64 without rejecting valid inputs or overflowing V8", async () => {
|
|
const tools = await listAdvertisedTools();
|
|
const patterns: string[] = [];
|
|
const canonicalBase64Leaves: Record<string, unknown>[] = [];
|
|
for (const tool of tools)
|
|
for (const schema of [tool.inputSchema, tool.outputSchema]) {
|
|
if (schema === undefined) continue;
|
|
patterns.push(
|
|
...advertisedSchemaPatterns(schema).map(({ pattern }) => pattern),
|
|
);
|
|
collectCanonicalBase64Leaves(schema, canonicalBase64Leaves);
|
|
}
|
|
|
|
expect(patterns).toContain(advertised(BASE64_QUARTET_LENGTH_PATTERN));
|
|
for (const pattern of [
|
|
INVALID_BASE64_CHARACTER_PATTERN,
|
|
INVALID_BASE64_PADDING_PATTERN,
|
|
INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN,
|
|
])
|
|
expect(projectPortablePattern(pattern.source)).toEqual({
|
|
kind: "unexpressible",
|
|
});
|
|
|
|
expect(canonicalBase64Leaves.length).toBeGreaterThan(0);
|
|
const sdkValidator = new AjvJsonSchemaValidator();
|
|
const validators = canonicalBase64Leaves.map((schema) =>
|
|
sdkValidator.getValidator(schema),
|
|
);
|
|
for (const value of ["", "AA==", "AQID"])
|
|
expect(
|
|
validators.map((validate) => validate(value).valid),
|
|
JSON.stringify(value),
|
|
).toEqual(canonicalBase64Leaves.map(() => true));
|
|
const large = "A".repeat(8 * 1024 * 1024);
|
|
const base64Patterns = new Set(
|
|
canonicalBase64Leaves.flatMap((schema) =>
|
|
advertisedSchemaPatterns(schema).map(({ pattern }) => pattern),
|
|
),
|
|
);
|
|
for (const pattern of base64Patterns)
|
|
expect(new RegExp(pattern, "v").test(large)).toBe(true);
|
|
});
|